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
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
AWS Lambdaから始まった Serverlessの「熱」とキャリアパス / It started with AWS Lambda Serverless “fever” and career path
seike460
PRO
1
260
RubyLSPのマルチバイト文字対応
notfounds
0
120
見せてあげますよ、「本物のLaravel批判」ってやつを。
77web
7
7.8k
Micro Frontends Unmasked Opportunities, Challenges, Alternatives
manfredsteyer
PRO
0
110
Streams APIとTCPフロー制御 / Web Streams API and TCP flow control
tasshi
2
350
Why Jakarta EE Matters to Spring - and Vice Versa
ivargrimstad
0
1.1k
CSC509 Lecture 09
javiergs
PRO
0
140
3 Effective Rules for Using Signals in Angular
manfredsteyer
PRO
0
120
Creating a Free Video Ad Network on the Edge
mizoguchicoji
0
120
Better Code Design in PHP
afilina
PRO
0
130
flutterkaigi_2024.pdf
kyoheig3
0
150
3 Effective Rules for Using Signals in Angular
manfredsteyer
PRO
0
100
Featured
See All Featured
Optimizing for Happiness
mojombo
376
70k
No one is an island. Learnings from fostering a developers community.
thoeni
19
3k
Building a Modern Day E-commerce SEO Strategy
aleyda
38
6.9k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
42
9.2k
The Invisible Side of Design
smashingmag
298
50k
Being A Developer After 40
akosma
87
590k
How GitHub (no longer) Works
holman
310
140k
How to Ace a Technical Interview
jacobian
276
23k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
364
24k
How to train your dragon (web standard)
notwaldorf
88
5.7k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
25
1.8k
For a Future-Friendly Web
brad_frost
175
9.4k
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
͝ਗ਼ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠