Zend_Markup-Renderers.xml 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- Reviewed: no -->
  3. <!-- EN-Revision: 24548 -->
  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. <!-- TODO : to be translated -->
  45. <para>
  46. Some renderers (like the <acronym>HTML</acronym> renderer) also have support for a
  47. 'markup' parameter. This replaces the 'start' and 'end' parameters, and
  48. it renders the markups including some default attributes and the
  49. closing markup.
  50. </para>
  51. <sect3 id="zend.markup.renderers.add.callback">
  52. <title>Add a callback markup</title>
  53. <para>
  54. By adding a callback markup, you can do a lot more then just a
  55. simple replace of the markups. For instance, you can change the
  56. contents, use the parameters to influence the output etc.
  57. </para>
  58. <para>
  59. A callback is a class that implements the
  60. <classname>Zend_Markup_Renderer_TokenInterface</classname>
  61. interface. An example of a callback class:
  62. </para>
  63. <programlisting language="php"><![CDATA[
  64. class My_Markup_Renderer_Html_Upper
  65. implements Zend_Markup_Renderer_TokenConverterInterface
  66. {
  67. public function convert(Zend_Markup_Token $token, $text)
  68. {
  69. return '!up!' . strtoupper($text) . '!up!';
  70. }
  71. }
  72. ]]></programlisting>
  73. <para>
  74. Now you can add the 'upper' markup, with as callback, an instance
  75. of the <classname>My_Markup_Renderer_Html_Upper</classname>
  76. class. A simple example:
  77. </para>
  78. <programlisting language="php"><![CDATA[
  79. // Zend_Markup_Parser_BbCode をパーサーとして、
  80. // Zend_Markup_Renderer_Html のインスタンスを生成します。
  81. $bbcode = Zend_Markup::factory('Bbcode');
  82. // これは単純な 'foo' マークアップを作成するでしょう
  83. // 第一引数は自身のマークアップ名を定義します。
  84. // 第二引数はマークアップ型を定義する整数を引数に取ります。
  85. // The third parameter is an array that defines other things about a
  86. // markup, like the markup's group, and (in this case) a start and end markup.
  87. $bbcode->addMarkup(
  88. 'upper',
  89. Zend_Markup_Renderer_RendererAbstract::TYPE_CALLBACK,
  90. array(
  91. 'callback' => new My_Markup_Renderer_Html_Upper(),
  92. 'group' => 'inline'
  93. )
  94. );
  95. // これは 'my !up!MARKUP!up!' と出力されるでしょう。
  96. echo $bbcode->render('my [upper]markup[/upper]');
  97. ]]></programlisting>
  98. </sect3>
  99. </sect2>
  100. <sect2 id="zend.markup.renderers.list">
  101. <title>マークアップ一覧</title>
  102. <table id="zend.markup.renderers.list.markups">
  103. <title>マークアップ一覧</title>
  104. <tgroup cols="2" align="left" colsep="1" rowsep="1">
  105. <thead>
  106. <row>
  107. <entry>入力例 (bbcode)</entry>
  108. <entry>出力例</entry>
  109. </row>
  110. </thead>
  111. <tbody>
  112. <row>
  113. <entry>[b]foo[/b]</entry>
  114. <entry><![CDATA[<strong>foo</strong>]]></entry>
  115. </row>
  116. <row>
  117. <entry>[i]foo[/i]</entry>
  118. <entry><![CDATA[<em>foo</em>]]></entry>
  119. </row>
  120. <row>
  121. <entry>[cite]foo[/cite]</entry>
  122. <entry><![CDATA[<cite>foo</cite>]]></entry>
  123. </row>
  124. <row>
  125. <entry>[del]foo[/del]</entry>
  126. <entry><![CDATA[<del>foo</del>]]></entry>
  127. </row>
  128. <row>
  129. <entry>[ins]foo[/ins]</entry>
  130. <entry><![CDATA[<ins>foo</ins>]]></entry>
  131. </row>
  132. <row>
  133. <entry>[sup]foo[/sup]</entry>
  134. <entry><![CDATA[<sup>foo</sup>]]></entry>
  135. </row>
  136. <row>
  137. <entry>[sub]foo[/sub]</entry>
  138. <entry><![CDATA[<sub>foo</sub>]]></entry>
  139. </row>
  140. <row>
  141. <entry>[span]foo[/span]</entry>
  142. <entry><![CDATA[<span>foo</span>]]></entry>
  143. </row>
  144. <row>
  145. <entry>[acronym title="PHP Hypertext Preprocessor]PHP[/acronym]</entry>
  146. <entry><![CDATA[<acronym title="PHP Hypertext Preprocessor">PHP</acronym>]]></entry>
  147. </row>
  148. <row>
  149. <entry>[url=http://framework.zend.com/]Zend Framework[/url]</entry>
  150. <entry><![CDATA[<a href="http://framework.zend.com/">Zend Framework</a>]]></entry>
  151. </row>
  152. <row>
  153. <entry>[h1]foobar[/h1]</entry>
  154. <entry><![CDATA[<h1>foobar</h1>]]></entry>
  155. </row>
  156. <row>
  157. <entry>[img]http://framework.zend.com/images/logo.gif[/img]</entry>
  158. <entry><![CDATA[<img src="http://framework.zend.com/images/logo.gif" />]]></entry>
  159. </row>
  160. </tbody>
  161. </tgroup>
  162. </table>
  163. </sect2>
  164. </sect1>