Zend_Markup
には現在ひとつのレンダラー、
HTML レンダラーが同梱されています。
自作のマークアップを追加することによって、Zend_Markup
レンダラーに
自作の機能の追加できます。 マークアップ構造とともに、
あなたが望むいかなる機能も追加ができます。
簡潔なマークアップから複雑なマークアップ構造まで。 'foo' マークアップでの単純な例:
// Zend_Markup_Parser_BbCode をパーサーとして、 // Zend_Markup_Renderer_Html のインスタンスを生成します。 $bbcode = Zend_Markup::factory('Bbcode'); // これは単純な 'foo' マークアップを作成するでしょう // 第一引数は自身のマークアップ名を定義します。 // 第二引数はマークアップの定数で定義された整数を引数に取ります。 // 第三引数は、マークアップについて、マークアップグループと(この例では)開始ならびに終了マークアップのように // 他のことを配列にて定義します。 $bbcode->addMarkup( 'foo', Zend_Markup_Renderer_RendererAbstract::TYPE_REPLACE, array( 'start' => '-bar-', 'end' => '-baz-', 'group' => 'inline' ) ); // これは 'my -bar-markup-baz-' と出力されるでしょう。 echo $bbcode->render('my [foo]markup[/foo]');
あなたの作成したマークアップは、あなたのパーサーがマークアップ構造もサポートするときに 機能することに注意してください。現在、 BBCode はこれをサポートします。 Textile はカスタムマークアップをサポートしません。
Some renderers (like the HTML renderer) also have support for a 'markup' parameter. This replaces the 'start' and 'end' parameters, and it renders the markups including some default attributes and the closing markup.
By adding a callback markup, you can do a lot more then just a simple replace of the markups. For instance, you can change the contents, use the parameters to influence the output etc.
A callback is a class that implements the
Zend_Markup_Renderer_TokenInterface
interface. An example of a callback class:
class My_Markup_Renderer_Html_Upper implements Zend_Markup_Renderer_TokenConverterInterface { public function convert(Zend_Markup_Token $token, $text) { return '!up!' . strtoupper($text) . '!up!'; } }
Now you can add the 'upper' markup, with as callback, an instance
of the My_Markup_Renderer_Html_Upper
class. A simple example:
// Zend_Markup_Parser_BbCode をパーサーとして、 // Zend_Markup_Renderer_Html のインスタンスを生成します。 $bbcode = Zend_Markup::factory('Bbcode'); // これは単純な 'foo' マークアップを作成するでしょう // 第一引数は自身のマークアップ名を定義します。 // 第二引数はマークアップ型を定義する整数を引数に取ります。 // The third parameter is an array that defines other things about a // markup, like the markup's group, and (in this case) a start and end markup. $bbcode->addMarkup( 'upper', Zend_Markup_Renderer_RendererAbstract::TYPE_CALLBACK, array( 'callback' => new My_Markup_Renderer_Html_Upper(), 'group' => 'inline' ) ); // これは 'my !up!MARKUP!up!' と出力されるでしょう。 echo $bbcode->render('my [upper]markup[/upper]');
表116 マークアップ一覧
入力例 (bbcode) | 出力例 |
---|---|
[b]foo[/b] | <strong>foo</strong> |
[i]foo[/i] | <em>foo</em> |
[cite]foo[/cite] | <cite>foo</cite> |
[del]foo[/del] | <del>foo</del> |
[ins]foo[/ins] | <ins>foo</ins> |
[sup]foo[/sup] | <sup>foo</sup> |
[sub]foo[/sub] | <sub>foo</sub> |
[span]foo[/span] | <span>foo</span> |
[acronym title="PHP Hypertext Preprocessor]PHP[/acronym] | <acronym title="PHP Hypertext Preprocessor">PHP</acronym> |
[url=http://framework.zend.com/]Zend Framework[/url] | <a href="http://framework.zend.com/">Zend Framework</a> |
[h1]foobar[/h1] | <h1>foobar</h1> |
[img]http://framework.zend.com/images/logo.gif[/img] | <img src="http://framework.zend.com/images/logo.gif" /> |