Lock in $30 Savings on PRO—Offer Ends Soon! ⏳
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
6.9k
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
N.E.X.T LEVEL
pluu
2
200
見せてあげますよ、「本物のLaravel批判」ってやつを。
77web
7
7.9k
TypeScript でバックもやるって実際どう? 実運用で困ったこと3選
yuichiro_serita
17
6.2k
Cursorでアプリケーションの追加開発や保守をどこまでできるか試したら得るものが多かった話
drumnistnakano
0
170
Full stack testing :: basic to basic
up1
1
710
DevTools extensions で 独自の DevTool を開発する | FlutterKaigi 2024
kokiyoshida
0
220
layerx_20241129.pdf
kyoheig3
1
160
Jakarta EE meets AI
ivargrimstad
0
710
Enabling DevOps and Team Topologies Through Architecture: Architecting for Fast Flow
cer
PRO
0
400
14 Years of iOS: Lessons and Key Points
seyfoyun
0
320
CSC509 Lecture 12
javiergs
PRO
0
170
React CompilerとFine Grained Reactivityと宣言的UIのこれから / The next chapter of declarative UI
ssssota
7
2.6k
Featured
See All Featured
GitHub's CSS Performance
jonrohan
1030
460k
What’s in a name? Adding method to the madness
productmarketing
PRO
22
3.2k
Writing Fast Ruby
sferik
627
61k
Building an army of robots
kneath
302
43k
Adopting Sorbet at Scale
ufuk
73
9.1k
Rebuilding a faster, lazier Slack
samanthasiow
79
8.7k
Done Done
chrislema
181
16k
Unsuck your backbone
ammeep
668
57k
Raft: Consensus for Rubyists
vanstee
136
6.7k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
365
24k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
44
6.8k
Designing for humans not robots
tammielis
250
25k
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
͝ਗ਼ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠