# MojoMojo: Formatter 記事を整形処理するクラス -------- {{TOC 3-}} ### Formatter とは ### MojoMojo には MojoMojo::Formatter::* というクラスがあり、それらのクラスがwikiの記事を整形処理してHTMLを生成しています。 Markdown や Textile も {{cpan: MojoMojo::Formatter::Markdown}} や {{cpan: MojoMojo::Formatter::Textile}} として実装されていて、何か記事を整形する処理を追加したいときは、Formatter を追加すれば良い仕組みになっています。 ### デフォルト Formatter ### MojoMojo-1.00 でデフォルトでインストールされる Formatter は次のようなものです。 * {{cpan: MojoMojo::Formatter::Amazon}} Include Amazon objects on your page. * {{cpan: MojoMojo::Formatter::CPANHyperlink}} automatically hyperlink CPAN modules when using the syntax { {cpan Some::Module} } * {{cpan: MojoMojo::Formatter::Comment}} Include comments on your page. * {{cpan: MojoMojo::Formatter::Defang}} Scrub user HTML and XSS * {{cpan: MojoMojo::Formatter::Dir}} format local directory as XHTML * {{cpan: MojoMojo::Formatter::DocBook}} format part of content as DocBook * {{cpan: MojoMojo::Formatter::DocBook::Colorize}} * {{cpan: MojoMojo::Formatter::Emote}} MSN Smileys in your text * {{cpan: MojoMojo::Formatter::File}} format file as XHTML * {{cpan: MojoMojo::Formatter::File::DocBook}} format Docbook in xhtml * {{cpan: MojoMojo::Formatter::File::Image}} Image formatter * {{cpan: MojoMojo::Formatter::File::Pod}} format Pod File in xhtml * {{cpan: MojoMojo::Formatter::File::Text}} * {{cpan: MojoMojo::Formatter::GoogleSearch}} Linked Google Search Engine by writing { {google:<search kind> <keyword>} } * {{cpan: MojoMojo::Formatter::IRCLog}} format part of content as an IRC log * {{cpan: MojoMojo::Formatter::Include}} Include files in your content. * {{cpan: MojoMojo::Formatter::Main}} MojoMojo's main formatter, dispatching between Textile and MultiMarkdown * {{cpan: MojoMojo::Formatter::Markdown}} MultiMarkdown formatting for your content. MultiMarkdown is an extension of Markdown, adding support for tables, footnotes, bibliography, automatic cross-references, glossaries, appendices, definition * {{cpan: MojoMojo::Formatter::Pod}} format part of content as POD * {{cpan: MojoMojo::Formatter::RSS}} Include RSS feeds on your page. * {{cpan: MojoMojo::Formatter::Redirect}} Handles { {redirect /path} } * {{cpan: MojoMojo::Formatter::SyntaxHighlight}} syntax highlighting for code blocks * {{cpan: MojoMojo::Formatter::TOC}} generate table of contents * {{cpan: MojoMojo::Formatter::Text}} format plain text as xhtml * {{cpan: MojoMojo::Formatter::Textile}} Texile+SmartyPants formatting for your content * {{cpan: MojoMojo::Formatter::Wiki}} Handle interpage linking. * {{cpan: MojoMojo::Formatter::WikipediaLink }} Linked Wikipedia by writing { {wikipedia:<lang> <word>} } * {{cpan: MojoMojo::Formatter::YouTube}} Embed YouTube player ### Formatter の書き方 ### 上に挙げたいくつもの実装を参考にすれば独自の Formatter を書くのも簡単です。 ポイントは2点あります。 * `format_content_order` MojoMojo の Formatter は {{cpan: Module::Pluggable::Ordered}} によって処理順がコントロールされていて、それぞれの Formatter のなかで、`format_content_order` メソッドを書き、処理順を明示しなければいけません。 デフォルトの処理順は、Formatter のベースクラスとなる {{cpan: MojoMojo::Formatter}} の POD に掲載されています。 * `gen_re` Formatter は記事の中で {{foo}} という中括弧で囲まれた部分を整形処理します。 Formatter の中で、`$class->gen_re(regex)` とすることで、処理するべき記述を取得することができます。 もしも記事全体を整形対象にするなら、`format_content` の第2引数 $content ( `my ( $class, $content, $c ) = @_;` )を書き換えます。 ### Formatter のテスト ### Formatter のテストは、t/ 直下に formatter_*.t というファイル名で置かれます。 デフォルトでインストールされるどの Formatter にもテストがあるので、参考にして書けば難しいところは何もありません。