Zend_Markup-Renderers.xml 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- Reviewed: no -->
  3. <sect1 id="zend.markup.renderers">
  4. <title>Zend_Markup Renderers</title>
  5. <para>
  6. <classname>Zend_Markup</classname> is currently shipped with one renderer, the
  7. <acronym>HTML</acronym> renderer.
  8. </para>
  9. <sect2 id="zend.markup.renderers.add">
  10. <title>Adding your own markups</title>
  11. <para>
  12. By adding your own markups, you can add your own functionality to the
  13. <classname>Zend_Markup</classname> renderers. With the markup structure, you can add
  14. about any functionality you want. From simple markups, to complicated markup structures.
  15. A simple example for a 'foo' markup:
  16. </para>
  17. <programlisting language="php"><![CDATA[
  18. // Creates instance of Zend_Markup_Renderer_Html,
  19. // with Zend_Markup_Parser_BbCode as its parser
  20. $bbcode = Zend_Markup::factory('Bbcode');
  21. // this will create a simple 'foo' markup
  22. // The first parameter defines the markup's name.
  23. // The second parameter takes an integer that defines the markups type.
  24. // The third parameter is an array that defines other things about a
  25. // markup, like the markup's group, and (in this case) a start and end markup.
  26. $bbcode->addMarkup(
  27. 'foo',
  28. Zend_Markup_Renderer_RendererAbstract::TYPE_REPLACE,
  29. array(
  30. 'start' => '-bar-',
  31. 'end' => '-baz-',
  32. 'group' => 'inline'
  33. )
  34. );
  35. // now, this will output: 'my -bar-markup-baz-'
  36. echo $bbcode->render('my [foo]markup[/foo]');
  37. ]]></programlisting>
  38. <para>
  39. Please note that creating your own markups only makes sense when your parser also
  40. supports it with a markup structure. Currently, only BBCode supports this.
  41. </para>
  42. <para>
  43. Some renderers (like the <acronym>HTML</acronym> renderer) also have support for a
  44. 'markup' parameter. This replaces the 'start' and 'end' parameters, and
  45. it renders the markups including some default attributes and the
  46. closing markup.
  47. </para>
  48. <sect3 id="zend.markup.renderers.add.callback">
  49. <title>Add a callback markup</title>
  50. <para>
  51. By adding a callback markup, you can do a lot more then just a
  52. simple replace of the markups. For instance, you can change the
  53. contents, use the parameters to influence the output etc.
  54. </para>
  55. <para>
  56. A callback is a class that implements the
  57. <classname>Zend_Markup_Renderer_TokenInterface</classname>
  58. interface. An example of a callback class:
  59. </para>
  60. <programlisting language="php"><![CDATA[
  61. class My_Markup_Renderer_Html_Upper
  62. implements Zend_Markup_Renderer_TokenConverterInterface
  63. {
  64. public function convert(Zend_Markup_Token $token, $text)
  65. {
  66. return '!up!' . strtoupper($text) . '!up!';
  67. }
  68. }
  69. ]]></programlisting>
  70. <para>
  71. Now you can add the 'upper' markup, with as callback, an instance
  72. of the <classname>My_Markup_Renderer_Html_Upper</classname>
  73. class. A simple example:
  74. </para>
  75. <programlisting language="php"><![CDATA[
  76. // Creates instance of Zend_Markup_Renderer_Html,
  77. // with Zend_Markup_Parser_BbCode as its parser
  78. $bbcode = Zend_Markup::factory('Bbcode');
  79. // this will create a simple 'foo' markup
  80. // The first parameter defines the markup's name.
  81. // The second parameter takes an integer that defines the markups type.
  82. // The third parameter is an array that defines other things about a
  83. // markup, like the markup's group, and (in this case) a start and end markup.
  84. $bbcode->addMarkup(
  85. 'upper',
  86. Zend_Markup_Renderer_RendererAbstract::TYPE_CALLBACK,
  87. array(
  88. 'callback' => new My_Markup_Renderer_Html_Upper(),
  89. 'group' => 'inline'
  90. )
  91. );
  92. // now, this will output: 'my !up!MARKUP!up!'
  93. echo $bbcode->render('my [upper]markup[/upper]');
  94. ]]></programlisting>
  95. </sect3>
  96. </sect2>
  97. <sect2 id="zend.markup.renderers.list">
  98. <title>List of markups</title>
  99. <table id="zend.markup.renderers.list.markups">
  100. <title>List of markups</title>
  101. <tgroup cols="2" align="left" colsep="1" rowsep="1">
  102. <thead>
  103. <row>
  104. <entry>Sample input (bbcode)</entry>
  105. <entry>Sample output</entry>
  106. </row>
  107. </thead>
  108. <tbody>
  109. <row>
  110. <entry>[b]foo[/b]</entry>
  111. <entry><![CDATA[<strong>foo</strong>]]></entry>
  112. </row>
  113. <row>
  114. <entry>[i]foo[/i]</entry>
  115. <entry><![CDATA[<em>foo</em>]]></entry>
  116. </row>
  117. <row>
  118. <entry>[cite]foo[/cite]</entry>
  119. <entry><![CDATA[<cite>foo</cite>]]></entry>
  120. </row>
  121. <row>
  122. <entry>[del]foo[/del]</entry>
  123. <entry><![CDATA[<del>foo</del>]]></entry>
  124. </row>
  125. <row>
  126. <entry>[ins]foo[/ins]</entry>
  127. <entry><![CDATA[<ins>foo</ins>]]></entry>
  128. </row>
  129. <row>
  130. <entry>[sup]foo[/sup]</entry>
  131. <entry><![CDATA[<sup>foo</sup>]]></entry>
  132. </row>
  133. <row>
  134. <entry>[sub]foo[/sub]</entry>
  135. <entry><![CDATA[<sub>foo</sub>]]></entry>
  136. </row>
  137. <row>
  138. <entry>[span]foo[/span]</entry>
  139. <entry><![CDATA[<span>foo</span>]]></entry>
  140. </row>
  141. <row>
  142. <entry>[acronym title="PHP Hypertext Preprocessor]PHP[/acronym]</entry>
  143. <entry>
  144. <![CDATA[<acronym title="PHP Hypertext Preprocessor">PHP</acronym>]]>
  145. </entry>
  146. </row>
  147. <row>
  148. <entry>[url=http://framework.zend.com/]Zend Framework[/url]</entry>
  149. <entry>
  150. <![CDATA[<a href="http://framework.zend.com/">Zend Framework</a>]]>
  151. </entry>
  152. </row>
  153. <row>
  154. <entry>[h1]foobar[/h1]</entry>
  155. <entry><![CDATA[<h1>foobar</h1>]]></entry>
  156. </row>
  157. <row>
  158. <entry>[img]http://framework.zend.com/images/logo.gif[/img]</entry>
  159. <entry>
  160. <![CDATA[<img src="http://framework.zend.com/images/logo.gif" />]]>
  161. </entry>
  162. </row>
  163. </tbody>
  164. </tgroup>
  165. </table>
  166. </sect2>
  167. </sect1>