Zend_Markup-Renderers.xml 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- Reviewed: no -->
  3. <!-- EN-Revision: 21992 -->
  4. <sect1 id="zend.markup.renderers">
  5. <title>Zend_Markup レンダラー</title>
  6. <para>
  7. <classname>Zend_Markup</classname> には現在ひとつのレンダラー、
  8. <acronym>HTML</acronym> レンダラーが同梱されています。
  9. </para>
  10. <sect2 id="zend.markup.renderers.add">
  11. <title>自作のマークアップを追加</title>
  12. <para>
  13. 自作のマークアップを追加することによって、<classname>Zend_Markup</classname> レンダラーに
  14. 自作の機能の追加できます。 マークアップ構造とともに、
  15. あなたが望むいかなる機能も追加ができます。
  16. 簡潔なマークアップから複雑なマークアップ構造まで。 'foo' マークアップでの単純な例:
  17. </para>
  18. <programlisting language="php"><![CDATA[
  19. // Zend_Markup_Parser_BbCode をパーサーとして、
  20. // Zend_Markup_Renderer_Html のインスタンスを生成します。
  21. $bbcode = Zend_Markup::factory('Bbcode');
  22. // これは単純な 'foo' マークアップを作成するでしょう
  23. // 第一引数は自身のマークアップ名を定義します。
  24. // 第二引数はマークアップの定数で定義された整数を引数に取ります。
  25. // 第三引数は、マークアップについて、マークアップグループと(この例では)開始ならびに終了マークアップのように
  26. // 他のことを配列にて定義します。
  27. $bbcode->addMarkup(
  28. 'foo',
  29. Zend_Markup_Renderer_RendererAbstract::TYPE_REPLACE,
  30. array(
  31. 'start' => '-bar-',
  32. 'end' => '-baz-',
  33. 'group' => 'inline'
  34. )
  35. );
  36. // これは 'my -bar-markup-baz-' と出力されるでしょう。
  37. echo $bbcode->render('my [foo]markup[/foo]');
  38. ]]></programlisting>
  39. <para>
  40. あなたの作成したマークアップは、あなたのパーサーがマークアップ構造もサポートするときに
  41. 機能することに注意してください。現在、 BBCode はこれをサポートします。
  42. Textile はカスタムマークアップをサポートしません。
  43. </para>
  44. <para>
  45. Some renderers (like the <acronym>HTML</acronym> renderer) also have support for a
  46. 'markup' parameter. This replaces the 'start' and 'end' parameters, and
  47. it renders the markups including some default attributes and the
  48. closing markup.
  49. </para>
  50. <sect3 id="zend.markup.renderers.add.callback">
  51. <title>Add a callback markup</title>
  52. <para>
  53. By adding a callback markup, you can do a lot more then just a
  54. simple replace of the markups. For instance, you can change the
  55. contents, use the parameters to influence the output etc.
  56. </para>
  57. <para>
  58. A callback is a class that implements the
  59. <classname>Zend_Markup_Renderer_TokenInterface</classname>
  60. interface. An example of a callback class:
  61. </para>
  62. <programlisting language="php"><![CDATA[
  63. class My_Markup_Renderer_Html_Upper
  64. implements Zend_Markup_Renderer_TokenConverterInterface
  65. {
  66. public function convert(Zend_Markup_Token $token, $text)
  67. {
  68. return '!up!' . strtoupper($text) . '!up!';
  69. }
  70. }
  71. ]]></programlisting>
  72. <para>
  73. Now you can add the 'upper' markup, with as callback, an instance
  74. of the <classname>My_Markup_Renderer_Html_Upper</classname>
  75. class. A simple example:
  76. </para>
  77. <programlisting language="php"><![CDATA[
  78. // Zend_Markup_Parser_BbCode をパーサーとして、
  79. // Zend_Markup_Renderer_Html のインスタンスを生成します。
  80. $bbcode = Zend_Markup::factory('Bbcode');
  81. // これは単純な 'foo' マークアップを作成するでしょう
  82. // 第一引数は自身のマークアップ名を定義します。
  83. // 第二引数はマークアップ型を定義する整数を引数に取ります。
  84. // The third parameter is an array that defines other things about a
  85. // markup, like the markup's group, and (in this case) a start and end markup.
  86. $bbcode->addMarkup(
  87. 'upper',
  88. Zend_Markup_Renderer_RendererAbstract::TYPE_REPLACE,
  89. array(
  90. 'callback' => new My_Markup_Renderer_Html_Upper(),
  91. 'group' => 'inline'
  92. )
  93. );
  94. // これは 'my !up!MARKUP!up!' と出力されるでしょう。
  95. echo $bbcode->render('my [upper]markup[/upper]');
  96. ]]></programlisting>
  97. </sect3>
  98. </sect2>
  99. <sect2 id="zend.markup.renderers.list">
  100. <title>マークアップ一覧</title>
  101. <table id="zend.markup.renderers.list.markups">
  102. <title>マークアップ一覧</title>
  103. <tgroup cols="2" align="left" colsep="1" rowsep="1">
  104. <thead>
  105. <row>
  106. <entry>入力例 (bbcode)</entry>
  107. <entry>出力例</entry>
  108. </row>
  109. </thead>
  110. <tbody>
  111. <row>
  112. <entry>[b]foo[/b]</entry>
  113. <entry><![CDATA[<strong>foo</strong>]]></entry>
  114. </row>
  115. <row>
  116. <entry>[i]foo[/i]</entry>
  117. <entry><![CDATA[<em>foo</em>]]></entry>
  118. </row>
  119. <row>
  120. <entry>[cite]foo[/cite]</entry>
  121. <entry><![CDATA[<cite>foo</cite>]]></entry>
  122. </row>
  123. <row>
  124. <entry>[del]foo[/del]</entry>
  125. <entry><![CDATA[<del>foo</del>]]></entry>
  126. </row>
  127. <row>
  128. <entry>[ins]foo[/ins]</entry>
  129. <entry><![CDATA[<ins>foo</ins>]]></entry>
  130. </row>
  131. <row>
  132. <entry>[sup]foo[/sup]</entry>
  133. <entry><![CDATA[<sup>foo</sup>]]></entry>
  134. </row>
  135. <row>
  136. <entry>[sub]foo[/sub]</entry>
  137. <entry><![CDATA[<sub>foo</sub>]]></entry>
  138. </row>
  139. <row>
  140. <entry>[span]foo[/span]</entry>
  141. <entry><![CDATA[<span>foo</span>]]></entry>
  142. </row>
  143. <row>
  144. <entry>[acronym title="PHP Hypertext Preprocessor]PHP[/acronym]</entry>
  145. <entry><![CDATA[<acronym title="PHP Hypertext Preprocessor">PHP</acronym>]]></entry>
  146. </row>
  147. <row>
  148. <entry>[url=http://framework.zend.com/]Zend Framework[/url]</entry>
  149. <entry><![CDATA[<a href="http://framework.zend.com/">Zend Framework</a>]]></entry>
  150. </row>
  151. <row>
  152. <entry>[h1]foobar[/h1]</entry>
  153. <entry><![CDATA[<h1>foobar</h1>]]></entry>
  154. </row>
  155. <row>
  156. <entry>[img]http://framework.zend.com/images/logo.gif[/img]</entry>
  157. <entry><![CDATA[<img src="http://framework.zend.com/images/logo.gif" />]]></entry>
  158. </row>
  159. </tbody>
  160. </tgroup>
  161. </table>
  162. </sect2>
  163. </sect1>