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
Less waste, more joy, and a lot more green: How Quarkus makes Java better
hollycummins
0
100
.NET のための通信フレームワーク MagicOnion 入門 / Introduction to MagicOnion
mayuki
1
1.5k
PHP でアセンブリ言語のように書く技術
memory1994
PRO
1
170
シールドクラスをはじめよう / Getting Started with Sealed Classes
mackey0225
4
640
Click-free releases & the making of a CLI app
oheyadam
2
120
ローコードSaaSのUXを向上させるためのTypeScript
taro28
1
610
ActiveSupport::Notifications supporting instrumentation of Rails apps with OpenTelemetry
ymtdzzz
1
230
Snowflake x dbtで作るセキュアでアジャイルなデータ基盤
tsoshiro
2
520
macOS でできる リアルタイム動画像処理
biacco42
9
2.4k
シェーダーで魅せるMapLibreの動的ラスタータイル
satoshi7190
1
480
初めてDefinitelyTypedにPRを出した話
syumai
0
410
3 Effective Rules for Using Signals in Angular
manfredsteyer
PRO
0
100
Featured
See All Featured
What’s in a name? Adding method to the madness
productmarketing
PRO
22
3.1k
Building an army of robots
kneath
302
43k
Git: the NoSQL Database
bkeepers
PRO
427
64k
Why You Should Never Use an ORM
jnunemaker
PRO
54
9.1k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
8
860
Practical Orchestrator
shlominoach
186
10k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
38
1.8k
Side Projects
sachag
452
42k
Making the Leap to Tech Lead
cromwellryan
133
8.9k
How STYLIGHT went responsive
nonsquared
95
5.2k
Into the Great Unknown - MozCon
thekraken
32
1.5k
Mobile First: as difficult as doing things right
swwweet
222
8.9k
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
͝ਗ਼ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠