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.7k
YAPC::Kyoto 2023 Keynote
onishi
3
9.8k
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
JaSST 24 九州:ワークショップ(は除く)実践!マインドマップを活用したソフトウェアテスト+活用事例
satohiroyuki
0
210
Dev ContainersとGitHub Codespacesの素敵な関係
ymd65536
1
120
ピラミッド、アイスクリームコーン、SMURF: 自動テストの最適バランスを求めて / Pyramid Ice-Cream-Cone and SMURF
twada
PRO
8
850
破壊せよ!データ破壊駆動で考えるドメインモデリング / data-destroy-driven
minodriven
15
3.8k
OpenTelemetryでRailsのパフォーマンス分析を始めてみよう(KoR2024)
ymtdzzz
3
1.3k
弊社の「意識チョット低いアーキテクチャ」10選
texmeijin
4
18k
qmuntal/stateless のススメ
sgash708
0
110
Boost Performance and Developer Productivity with Jakarta EE 11
ivargrimstad
0
510
/←このスケジュール表に立ち向かう フロントエンド開発戦略 / A front-end development strategy to tackle a single-slash schedule.
nrslib
1
590
Vertical Architectures for Scalable Angular Applications
manfredsteyer
PRO
0
290
組織に自動テストを書く文化を根付かせる戦略(2024秋版) / Building Automated Test Culture 2024 Autumn Edition
twada
PRO
10
4.4k
色々なIaCツールを実際に触って比較してみる
iriikeita
0
190
Featured
See All Featured
The Invisible Side of Design
smashingmag
297
50k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
250
21k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
31
2.6k
Producing Creativity
orderedlist
PRO
341
39k
What's new in Ruby 2.0
geeforr
342
31k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
25
1.8k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
159
15k
Facilitating Awesome Meetings
lara
49
6k
Code Reviewing Like a Champion
maltzj
519
39k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
47
5k
Designing on Purpose - Digital PM Summit 2013
jponch
115
6.9k
Thoughts on Productivity
jonyablonski
67
4.3k
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
͝ਗ਼ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠