Zend_Markup-Renderers.xml 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  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. Textile
  41. doesn't have support for custom markups.
  42. </para>
  43. <para>
  44. Some renderers (like the <acronym>HTML</acronym> renderer) also have support for a
  45. 'markup' parameter. This replaces the 'start' and 'end' parameters, and
  46. it renders the markups including some default attributes and the
  47. closing markup.
  48. </para>
  49. <sect3 id="zend.markup.renderers.add.callback">
  50. <title>Add a callback markup</title>
  51. <para>
  52. By adding a callback markup, you can do a lot more then just a
  53. simple replace of the markups. For instance, you can change the
  54. contents, use the parameters to influence the output etc.
  55. </para>
  56. <para>
  57. A callback is a class that implements the
  58. <classname>Zend_Markup_Renderer_TokenInterface</classname>
  59. interface. An example of a callback class:
  60. </para>
  61. <programlisting language="php"><![CDATA[
  62. class My_Markup_Renderer_Html_Upper
  63. implements Zend_Markup_Renderer_TokenConverterInterface
  64. {
  65. public function convert(Zend_Markup_Token $token, $text)
  66. {
  67. return '!up!' . strtoupper($text) . '!up!';
  68. }
  69. }
  70. ]]></programlisting>
  71. <para>
  72. Now you can add the 'upper' markup, with as callback, an instance
  73. of the <classname>My_Markup_Renderer_Html_Upper</classname>
  74. class. A simple example:
  75. </para>
  76. <programlisting language="php"><![CDATA[
  77. // Creates instance of Zend_Markup_Renderer_Html,
  78. // with Zend_Markup_Parser_BbCode as its parser
  79. $bbcode = Zend_Markup::factory('Bbcode');
  80. // this will create a simple 'foo' markup
  81. // The first parameter defines the markup's name.
  82. // The second parameter takes an integer that defines the markups type.
  83. // The third parameter is an array that defines other things about a
  84. // markup, like the markup's group, and (in this case) a start and end markup.
  85. $bbcode->addMarkup(
  86. 'upper',
  87. Zend_Markup_Renderer_RendererAbstract::TYPE_CALLBACK,
  88. array(
  89. 'callback' => new My_Markup_Renderer_Html_Upper(),
  90. 'group' => 'inline'
  91. )
  92. );
  93. // now, this will output: 'my !up!MARKUP!up!'
  94. echo $bbcode->render('my [upper]markup[/upper]');
  95. ]]></programlisting>
  96. </sect3>
  97. </sect2>
  98. <sect2 id="zend.markup.renderers.list">
  99. <title>List of markups</title>
  100. <table id="zend.markup.renderers.list.markups">
  101. <title>List of markups</title>
  102. <tgroup cols="2" align="left" colsep="1" rowsep="1">
  103. <thead>
  104. <row>
  105. <entry>Sample input (bbcode)</entry>
  106. <entry>Sample output</entry>
  107. </row>
  108. </thead>
  109. <tbody>
  110. <row>
  111. <entry>[b]foo[/b]</entry>
  112. <entry><![CDATA[<strong>foo</strong>]]></entry>
  113. </row>
  114. <row>
  115. <entry>[i]foo[/i]</entry>
  116. <entry><![CDATA[<em>foo</em>]]></entry>
  117. </row>
  118. <row>
  119. <entry>[cite]foo[/cite]</entry>
  120. <entry><![CDATA[<cite>foo</cite>]]></entry>
  121. </row>
  122. <row>
  123. <entry>[del]foo[/del]</entry>
  124. <entry><![CDATA[<del>foo</del>]]></entry>
  125. </row>
  126. <row>
  127. <entry>[ins]foo[/ins]</entry>
  128. <entry><![CDATA[<ins>foo</ins>]]></entry>
  129. </row>
  130. <row>
  131. <entry>[sup]foo[/sup]</entry>
  132. <entry><![CDATA[<sup>foo</sup>]]></entry>
  133. </row>
  134. <row>
  135. <entry>[sub]foo[/sub]</entry>
  136. <entry><![CDATA[<sub>foo</sub>]]></entry>
  137. </row>
  138. <row>
  139. <entry>[span]foo[/span]</entry>
  140. <entry><![CDATA[<span>foo</span>]]></entry>
  141. </row>
  142. <row>
  143. <entry>[acronym title="PHP Hypertext Preprocessor]PHP[/acronym]</entry>
  144. <entry>
  145. <![CDATA[<acronym title="PHP Hypertext Preprocessor">PHP</acronym>]]>
  146. </entry>
  147. </row>
  148. <row>
  149. <entry>[url=http://framework.zend.com/]Zend Framework[/url]</entry>
  150. <entry>
  151. <![CDATA[<a href="http://framework.zend.com/">Zend Framework</a>]]>
  152. </entry>
  153. </row>
  154. <row>
  155. <entry>[h1]foobar[/h1]</entry>
  156. <entry><![CDATA[<h1>foobar</h1>]]></entry>
  157. </row>
  158. <row>
  159. <entry>[img]http://framework.zend.com/images/logo.gif[/img]</entry>
  160. <entry>
  161. <![CDATA[<img src="http://framework.zend.com/images/logo.gif" />]]>
  162. </entry>
  163. </row>
  164. </tbody>
  165. </tgroup>
  166. </table>
  167. </sect2>
  168. </sect1>