Upgrade to Pro — share decks privately, control downloads, hide ads and more …

The new Text::Hatena

The new Text::Hatena

Yasuhiro Onishi

August 18, 2012
Tweet

More Decks by Yasuhiro Onishi

Other Decks in Programming

Transcript

  1. ͜ ͷ Ն ͷ ࠷ ৽
    5FYU)BUFOB
    Λ͓ಧ͚͠·͢

    େ੢߁༟ JEPOJTIJ
    ͸ͯͳ

    View full-size slide

  2. ࣗݾ঺հ
    w JEPOJTIJେ੢߁༟
    w גࣜձࣾ͸ͯͳ ʙ

    w νʔϑΤϯδχΞ
    w ͸ͯͳϒϩάσΟϨΫλʔ
    w !ZBTVIJSP@POJTIJ
    w 1"64&0/*4)*%FWFM,:51SPG

    View full-size slide

  3. 5FYU)BUFOBͱ͸
    ͸ ͯ ͳ ه ๏ Λ
    )5.-ʹม׵
    ͢ΔϞδϡʔϧ

    View full-size slide

  4. ͸ͯͳه๏ͱ͸
    w ͸ͯͳϒϩά΍͸ͯͳμΠΞϦʔ΍͸ͯͳά
    ϧʔϓͰ࢖͑Δॻࣜ
    w ͔ΜͨΜͳهड़Ͱ)5.-จॻߏ଄΍ࣗಈϦϯ
    Ϋ͕ॻ͚Δ
    w IBUFOBEJBSZHIBUFOBOFKQLFZXPSE
    ͸ͯͳه๏Ұཡ

    View full-size slide

  5. ೖྗࢧԉʢϒϩοΫه๏ʣ

    View full-size slide

  6. ࣗಈϦϯΫʢΠϯϥΠϯه๏ʣ

    View full-size slide

  7. ͨ͘͞Μͷ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

    View full-size slide

  8. 5FYU)BUFOBʙ
    use  Text::Hatena;  #  0.16
    my  $parser  =  Text::Hatena-­‐>new;
         $parser-­‐>parse($text);
    my  $html  =  $parser-­‐>html;  

    View full-size slide

  9. 5FYU)BUFOB
    use  Text::Hatena;  #  0.20
    my  $html  =  Text::Hatena-­‐>parse($text);  

    View full-size slide

  10. 5FYU9BUFOB
    use  Text::Xatena;
    my  $thx  =  Text::Xatena-­‐>new;
         $thx-­‐>format($string);

    View full-size slide

  11. 5FYU)BUFOB-JUF
    use  Text::HatenaLite::Parser;
    my  $html  =  Text::HatenaLite::Parser
    -­‐>parse_string($string);

    View full-size slide

  12. ΋ͬͱͨ͘͞Μͷʜ
    •Hatena::Diary::HTMLParserBody
    •Hatena2::Group::HTMLParserBody
    •Hatena::Bookmark::TextFormat
    •Hatena::Haiku::Body

    View full-size slide

  13. )BUFOB%JBSZ)5.-1BSTFS#PEZ
    w ࠷ॳͷ͸ͯͳه๏1BSTFS
    w ೥·Ͱςετͳ͔ͬͨ
    w ߦͷϝιου
    w·ͩ࢖ΘΕ͍ͯ·͢ʜ

    View full-size slide

  14. )%)5.-1BSTFS#PEZNBLFMJOL

    View full-size slide

  15. ه๏ల։ͷ೉͠͞

    w ͸ͯͳه๏͸)5.-λά͕࢖͑Δ
    w ίϝϯτه๏
    w εʔύʔ13&ه๏
    ςΩετΛ)5.-ʹ͢Δ΋ͷ͚ͩͲ
    )5.-1BSTFSϕʔε

    View full-size slide

  16. ه๏ల։ͷ೉͠͞

    <br/>͜͜͸ه๏ల։͠ͳ͍Α<br/>
    ͜͜͸ফ͑ΔΑ
    -­‐-­‐>
    >||
    ه๏ల։͠ͳ͍ͰPREʹͳΔΑ
    ||<

    View full-size slide

  17. ه๏ల։ͷ೉͠͞

    <br/>>||<br/>͜͜͸Ͳ͏ͳΔʁ<br/>||<  <br/>
    >||
    ͜͜͸Ͳ͏ͳΔʁ
    -­‐-­‐>
    ||<

    View full-size slide

  18. ه๏ల։ͷ೉͠͞

    ه๏ͱ)5.-Λ
    ಉ࣌ʹղऍ͠ͳ
    ͚Ε͹͍͚ͳ͍

    View full-size slide

  19. ه๏ల։ͷ೉͠͞

    w ه๏ͷల։
    w ΩʔϫʔυϦϯΫ
    w 944ରࡦ ϗϫΠτϦετʹΑΔTDSJQU੍ݶ

    ͭͷ͜ͱΛಉ࣌ʹ΍͍ͬͯΔ

    View full-size slide

  20. ه๏ల։ͷ೉͠͞

    w ه๏ͱΩʔϫʔυϦϯΫ͕ີ݁߹͍ͯ͠Δ
    w <>ΩʔϫʔυϦϯΫ͠ͳ͍ه๏<>
    w ه๏ల։͢ΔͱҙຯΛࣦ͏
    Ͳ͏ͯ͜͠͏ͳͬͨ

    View full-size slide

  21. ه๏ల։ͷ೉͠͞

    ه๏ల։ͱΩʔϫʔ
    υϦϯΫΛಉ࣌ʹߦ
    Θͳ͚Ε͹ͳΒͳ͍

    View full-size slide

  22. ͜ͷͨΊ
    ه๏ల։ͱΩʔϫʔυϦϯΫ͕ີ݁
    ߹Ͱ͋ΔͨΊɺ5FYU)BUFOB ͳ
    Ͳͷه๏ల։͚ͩͷϞδϡʔϧΛ
    ࡞ͬͯ΋ɺ࣮ࡍͷϓϩμΫτʢ͸ͯ
    ͳμΠΞϦʔʣͰར༻Ͱ͖ͳ͔ͬͨ

    View full-size slide

  23. ϝλσʔλʹΑΔૄ݁߹Խ
    ه๏ల։࣌ʹ
    ʮ͜ΕҎ্ϦϯΫ͠ͳ͍ʯͱ͍͏
    ΧελϜσʔλଐੑΛ෇༩

    ͜͜͸͜ΕҎ্ϦϯΫ͠ͳ͍

    View full-size slide

  24. ϝλσʔλʹΑΔૄ݁߹Խ
    wه๏ύʔα
    w EBUBVOMJOLଐੑΛ෇༩
    wΩʔϫʔυϦϯΧ
    w EBUBVOMJOLଐੑΛݟͯϦϯΫΛ൑அ
    ૄ݁߹Խ
    }

    View full-size slide

  25. The new Text::Hatena
    w 5FYU9BUFOB ˜DIP
    Λϕʔεʹ
    w ΧελϜσʔλଐੑΛ࢖ͬͯه๏ల։ͱΩʔ
    ϫʔυϦϯΫΛૄ݁߹Խ
    w աڈʢ΍ྨࣅʣͷΠϯλʔϑΣʔεޓ׵
    w ଟ͘ͷ͸ͯͳه๏ʹରԠ
    w࣮ࡍʹ͸ͯͳϒϩάͰར༻͍ͯ͠Δ

    View full-size slide

  26. ΠϯλʔϑΣʔεޙํޓ׵
    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);

    View full-size slide

  27. ୯ମͰ΋࢖͑ΔศརϞδϡʔϧ
    •Text::Hatena::Keyword
    w ΩʔϫʔυϦϯΧ
    •Text::Hatena::Embed
    w 63-ຒΊࠐΈࢧԉ ه๏

    View full-size slide

  28. 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); # ϦϯΫ

    View full-size slide

  29. 5FYU)BUFOB&NCFE
    63-Λ౉͢ͱ͍͍ײ͡ʹFNCFE
    my $embed = Text::Hatena::Embed->new;
    my $html = $embed->render($url);
    XXXTMJEFTIBSFOFUPOJTIJPFNCFEUFYUIBUFOB

    View full-size slide

  30. ຊ೔ެ։͠·ͨ͠
    HJUIVCDPNPOJTIJ5FYU)BUFOB
    Ͳ͏ͧ͝ར༻͍ͩ͘͞
    QVMMSFRVFTU͍ͩ͘͞

    View full-size slide

  31. ͸ͯͳϒϩά
    ि࿈ଓ৽ػೳϦϦʔεத
    ೔ຊҰ։ൃ͕ϗοτͳϒϩά
    hatenablog.com

    View full-size slide

  32. ਓࡐืू
    wגࣜձࣾ͸ͯͳͰ͸ΤϯδχΞͦͷଞ
    શ৬छΛืू͍ͯ͠·͢
    wҰॹʹϒϩάΛ࡞Γ·͠ΐ͏ʂ
    www.hatena.ne.jp/company/staff

    View full-size slide

  33. ͝ਗ਼ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠

    View full-size slide