Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
The new Text::Hatena
Search
Yasuhiro Onishi
August 18, 2012
Programming
2
240
The new Text::Hatena
https://github.com/onishi/Text-Hatena
Yasuhiro Onishi
August 18, 2012
Tweet
Share
More Decks by Yasuhiro Onishi
See All by Yasuhiro Onishi
アニメから得た学びを発表会 in 関西 はてな スポンサーLT
onishi
1
14
大吉祥寺.pm 基調講演
onishi
3
7.1k
YAPC::Kyoto 2023 Keynote
onishi
3
9.9k
2016 Devsumi Kansai
onishi
3
1.4k
Hatena-Camp
onishi
2
4.3k
Hatena Blog for Engineer
onishi
2
3k
Hatena Blog Development Flow
onishi
34
38k
hatena-diary-blog-xss
onishi
5
1.1k
wget.pl
onishi
3
1.4k
Other Decks in Programming
See All in Programming
今年一番支援させていただいたのは認証系サービスでした
satoshi256kbyte
1
260
KubeCon + CloudNativeCon NA 2024 Overviewat Kubernetes Meetup Tokyo #68 / amsy810_k8sjp68
masayaaoyama
0
250
42 best practices for Symfony, a decade later
tucksaun
1
180
「Chatwork」Android版アプリを 支える単体テストの現在
okuzawats
0
180
CSC305 Lecture 26
javiergs
PRO
0
140
Mermaid x AST x 生成AI = コードとドキュメントの完全同期への道
shibuyamizuho
0
160
複雑な仕様に立ち向かうアーキテクチャ
myohei
0
170
KMP와 kotlinx.rpc로 서버와 클라이언트 동기화
kwakeuijin
0
140
採用事例の少ないSvelteを選んだ理由と それを正解にするためにやっていること
oekazuma
2
1k
20年もののレガシープロダクトに 0からPHPStanを入れるまで / phpcon2024
hirobe1999
0
480
Fibonacci Function Gallery - Part 1
philipschwarz
PRO
0
220
命名をリントする
chiroruxx
1
410
Featured
See All Featured
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
5
450
Dealing with People You Can't Stand - Big Design 2015
cassininazir
365
25k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
191
16k
Bootstrapping a Software Product
garrettdimon
PRO
305
110k
Fantastic passwords and where to find them - at NoRuKo
philnash
50
2.9k
Product Roadmaps are Hard
iamctodd
PRO
49
11k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
159
15k
The Pragmatic Product Professional
lauravandoore
32
6.3k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
111
49k
The Language of Interfaces
destraynor
154
24k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
356
29k
Gamification - CAS2011
davidbonilla
80
5.1k
Transcript
͜ ͷ Ն ͷ ࠷ ৽ 5FYU)BUFOB Λ͓ಧ͚͠·͢ େ߁༟
JEPOJTIJ ͯͳ
ࣗݾհ w JEPOJTIJେ߁༟ w גࣜձࣾͯͳ ʙ w νʔϑΤϯδχΞ w ͯͳϒϩάσΟϨΫλʔ
w !ZBTVIJSP@POJTIJ w 1"64&0/*4)*%FWFM,:51SPG
5FYU)BUFOBͱ ͯ ͳ ه ๏ Λ )5.-ʹม ͢ΔϞδϡʔϧ
ͯͳه๏ͱ w ͯͳϒϩάͯͳμΠΞϦʔͯͳά ϧʔϓͰ͑Δॻࣜ w ͔ΜͨΜͳهड़Ͱ)5.-จॻߏࣗಈϦϯ Ϋ͕ॻ͚Δ w IBUFOBEJBSZHIBUFOBOFKQLFZXPSE ͯͳه๏Ұཡ
ೖྗࢧԉʢϒϩοΫه๏ʣ
ࣗಈϦϯΫʢΠϯϥΠϯه๏ʣ
ͨ͘͞Μͷ5FYU)BUFOB w 5FYU)BUFOBʙ KLPOEP w IUUQTNFUBDQBOPSHSFMFBTF+,0/%05FYU)BUFOB w 5FYU)BUFOB KLPOEP w
IUUQTNFUBDQBOPSHNPEVMF5FYU)BUFOB w 5FYU9BUFOB DIP w IUUQTNFUBDQBOPSHNPEVMF5FYU9BUFOB w 5FYU)BUFOB-JUF XBLBCBUBO w IUUQTHJUIVCDPNXBLBCBQFSMUFYUIBUFOBMJUF
5FYU)BUFOBʙ use Text::Hatena; # 0.16 my $parser = Text::Hatena-‐>new;
$parser-‐>parse($text); my $html = $parser-‐>html;
5FYU)BUFOB use Text::Hatena; # 0.20 my $html = Text::Hatena-‐>parse($text);
5FYU9BUFOB use Text::Xatena; my $thx = Text::Xatena-‐>new; $thx-‐>format($string);
5FYU)BUFOB-JUF use Text::HatenaLite::Parser; my $html = Text::HatenaLite::Parser -‐>parse_string($string);
ͬͱͨ͘͞Μͷʜ •Hatena::Diary::HTMLParserBody •Hatena2::Group::HTMLParserBody •Hatena::Bookmark::TextFormat •Hatena::Haiku::Body
)BUFOB%JBSZ)5.-1BSTFS#PEZ w ࠷ॳͷͯͳه๏1BSTFS w ·Ͱςετͳ͔ͬͨ w ߦͷϝιου w·ͩΘΕ͍ͯ·͢ʜ
)%)5.-1BSTFS#PEZNBLFMJOL
ه๏ల։ͷ͠͞ w ͯͳه๏)5.-λά͕͑Δ w ίϝϯτه๏ w εʔύʔ13&ه๏ ςΩετΛ)5.-ʹ͢Δͷ͚ͩͲ )5.-1BSTFSϕʔε
ه๏ల։ͷ͠͞ <script> ͜͜ه๏ల։͠ͳ͍Α </script> <!-‐-‐ ͜͜ফ͑ΔΑ -‐-‐> >|| ه๏ల։͠ͳ͍ͰPREʹͳΔΑ
||<
ه๏ల։ͷ͠͞ <script> >|| ͜͜Ͳ͏ͳΔʁ ||< </script> >|| <!-‐-‐
͜͜Ͳ͏ͳΔʁ -‐-‐> ||<
ه๏ల։ͷ͠͞ ه๏ͱ)5.-Λ ಉ࣌ʹղऍ͠ͳ ͚Ε͍͚ͳ͍
ه๏ల։ͷ͠͞ w ه๏ͷల։ w ΩʔϫʔυϦϯΫ w 944ରࡦ ϗϫΠτϦετʹΑΔTDSJQU੍ݶ ͭͷ͜ͱΛಉ࣌ʹ͍ͬͯΔ
ه๏ల։ͷ͠͞ w ه๏ͱΩʔϫʔυϦϯΫ͕ີ݁߹͍ͯ͠Δ w <>ΩʔϫʔυϦϯΫ͠ͳ͍ه๏<> w ه๏ల։͢ΔͱҙຯΛࣦ͏ Ͳ͏ͯ͜͠͏ͳͬͨ
ه๏ల։ͷ͠͞ ه๏ల։ͱΩʔϫʔ υϦϯΫΛಉ࣌ʹߦ Θͳ͚ΕͳΒͳ͍
͜ͷͨΊ ه๏ల։ͱΩʔϫʔυϦϯΫ͕ີ݁ ߹Ͱ͋ΔͨΊɺ5FYU)BUFOB ͳ Ͳͷه๏ల։͚ͩͷϞδϡʔϧΛ ࡞ͬͯɺ࣮ࡍͷϓϩμΫτʢͯ ͳμΠΞϦʔʣͰར༻Ͱ͖ͳ͔ͬͨ
Ͳ͏͠Α͏
ϝλσʔλʹΑΔૄ݁߹Խ ه๏ల։࣌ʹ ʮ͜ΕҎ্ϦϯΫ͠ͳ͍ʯͱ͍͏ ΧελϜσʔλଐੑΛ༩ <span data-unlink> ͜͜͜ΕҎ্ϦϯΫ͠ͳ͍ </span>
ϝλσʔλʹΑΔૄ݁߹Խ wه๏ύʔα w EBUBVOMJOLଐੑΛ༩ wΩʔϫʔυϦϯΧ w EBUBVOMJOLଐੑΛݟͯϦϯΫΛஅ ૄ݁߹Խ }
The new Text::Hatena w 5FYU9BUFOB DIP Λϕʔεʹ w ΧελϜσʔλଐੑΛͬͯه๏ల։ͱΩʔ ϫʔυϦϯΫΛૄ݁߹Խ
w աڈʢྨࣅʣͷΠϯλʔϑΣʔεޓ w ଟ͘ͷͯͳه๏ʹରԠ w࣮ࡍʹͯͳϒϩάͰར༻͍ͯ͠Δ
ΠϯλʔϑΣʔεޙํޓ use Text::Hatena; my $parser = Text::Hatena->new; my $html =
$parser->parse($string); # Text::Hatena 0.16 style my $html = $parser->html; # Text::Hatena 0.20 style my $html = Text::Hatena->parse($string); # Text::Xatena style my $html = $parser->format($string);
୯ମͰ͑ΔศརϞδϡʔϧ •Text::Hatena::Keyword w ΩʔϫʔυϦϯΧ •Text::Hatena::Embed w 63-ຒΊࠐΈࢧԉ <IUUQFNCFE>ه๏
5FYU)BUFOB,FZXPSE EBUBVOMJOLଐੑΛߟྀͯ͠ΩʔϫʔυϦϯΫ my $parser = Text::Hatena::Keyword->new( rules => [ qr/hoge|fuga/
=> sub { sprintf '/keyword/%s', uri_escape($_) }, [qw/foo bar/] => sub { sprintf '/other/%s', uri_escape($_) }, ], ); my $words = $parser->extract($html); # நग़ my $formatted_html = $parser->format($html); # ϦϯΫ
5FYU)BUFOB&NCFE 63-Λ͢ͱ͍͍ײ͡ʹFNCFE my $embed = Text::Hatena::Embed->new; my $html = $embed->render($url);
XXXTMJEFTIBSFOFUPOJTIJPFNCFEUFYUIBUFOB
ຊެ։͠·ͨ͠ HJUIVCDPNPOJTIJ5FYU)BUFOB Ͳ͏ͧ͝ར༻͍ͩ͘͞ QVMMSFRVFTU͍ͩ͘͞
ͯͳϒϩά ि࿈ଓ৽ػೳϦϦʔεத ຊҰ։ൃ͕ϗοτͳϒϩά hatenablog.com
ਓࡐืू wגࣜձࣾͯͳͰΤϯδχΞͦͷଞ શ৬छΛืू͍ͯ͠·͢ wҰॹʹϒϩάΛ࡞Γ·͠ΐ͏ʂ www.hatena.ne.jp/company/staff
͝ਗ਼ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠