1 <?xml version="1.0" encoding="UTF-8"?>
3 <sect1 id="zend.markup.renderers">
4 <title>Zend_Markup Renderers</title>
7 <classname>Zend_Markup</classname> is currently shipped with one renderer, the
8 <acronym>HTML</acronym> renderer.
11 <sect2 id="zend.markup.renderers.add">
12 <title>Adding your own markups</title>
15 By adding your own markups, you can add your own functionality to the
16 <classname>Zend_Markup</classname> renderers. With the markup structure, you can add
17 about any functionality you want. From simple markups, to complicated markup structures.
18 A simple example for a 'foo' markup:
21 <programlisting language="php"><![CDATA[
22 // Creates instance of Zend_Markup_Renderer_Html,
23 // with Zend_Markup_Parser_BbCode as its parser
24 $bbcode = Zend_Markup::factory('Bbcode');
26 // this will create a simple 'foo' markup
27 // The first parameter defines the markup's name.
28 // The second parameter takes an integer that defines the markups type.
29 // The third parameter is an array that defines other things about a
30 // markup, like the markup's group, and (in this case) a start and end markup.
33 Zend_Markup_Renderer_RendererAbstract::TYPE_REPLACE,
41 // now, this will output: 'my -bar-markup-baz-'
42 echo $bbcode->render('my [foo]markup[/foo]');
46 Please note that creating your own markups only makes sense when your parser also
47 supports it with a markup structure. Currently, only BBCode supports this. Textile
48 doesn't have support for custom markups.
52 Some renderers (like the HTML renderer) also have support for a
53 'markup' parameter. This replaces the 'start' and 'end' parameters, and
54 it renders the markups including some default attributes and the
58 <sect3 id="zend.markup.renderers.add.callback">
59 <title>Add a callback markup</title>
62 By adding a callback markup, you can do a lot more then just a
63 simple replace of the markups. For instance, you can change the
64 contents, use the parameters to influence the output etc.
68 A callback is a class that implements the
69 <classname>Zend_Markup_Renderer_TokenInterface</classname>
70 interface. An example of a callback class:
73 <programlisting language="php"><![CDATA[
74 class My_Markup_Renderer_Html_Upper implements Zend_Markup_Renderer_TokenConverterInterface
77 public function convert(Zend_Markup_Token $token, $text)
79 return '!up!' . strtoupper($text) . '!up!';
86 Now you can add the 'upper' markup, with as callback, an instance
87 of the <classname>My_Markup_Renderer_Html_Upper</classname>
88 class. A simple example:
91 <programlisting language="php"><![CDATA[
92 // Creates instance of Zend_Markup_Renderer_Html,
93 // with Zend_Markup_Parser_BbCode as its parser
94 $bbcode = Zend_Markup::factory('Bbcode');
96 // this will create a simple 'foo' markup
97 // The first parameter defines the markup's name.
98 // The second parameter takes an integer that defines the markups type.
99 // The third parameter is an array that defines other things about a
100 // markup, like the markup's group, and (in this case) a start and end markup.
103 Zend_Markup_Renderer_RendererAbstract::TYPE_REPLACE,
105 'callback' => new My_Markup_Renderer_Html_Upper(),
110 // now, this will output: 'my !up!MARKUP!up!'
111 echo $bbcode->render('my [upper]markup[/upper]');
116 <sect2 id="zend.markup.renderers.list">
117 <title>List of markups</title>
119 <table id="zend.markup.renderers.list.markups">
120 <title>List of markups</title>
122 <tgroup cols="2" align="left" colsep="1" rowsep="1">
125 <entry>Sample input (bbcode)</entry>
126 <entry>Sample output</entry>
132 <entry>[b]foo[/b]</entry>
133 <entry><![CDATA[<strong>foo</strong>]]></entry>
137 <entry>[i]foo[/i]</entry>
138 <entry><![CDATA[<em>foo</em>]]></entry>
142 <entry>[cite]foo[/cite]</entry>
143 <entry><![CDATA[<cite>foo</cite>]]></entry>
147 <entry>[del]foo[/del]</entry>
148 <entry><![CDATA[<del>foo</del>]]></entry>
152 <entry>[ins]foo[/ins]</entry>
153 <entry><![CDATA[<ins>foo</ins>]]></entry>
157 <entry>[sup]foo[/sup]</entry>
158 <entry><![CDATA[<sup>foo</sup>]]></entry>
162 <entry>[sub]foo[/sub]</entry>
163 <entry><![CDATA[<sub>foo</sub>]]></entry>
167 <entry>[span]foo[/span]</entry>
168 <entry><![CDATA[<span>foo</span>]]></entry>
172 <entry>[acronym title="PHP Hypertext Preprocessor]PHP[/acronym]</entry>
175 <![CDATA[<acronym title="PHP Hypertext Preprocessor">PHP</acronym>]]>
180 <entry>[url=http://framework.zend.com/]Zend Framework[/url]</entry>
183 <![CDATA[<a href="http://framework.zend.com/">Zend Framework</a>]]>
188 <entry>[h1]foobar[/h1]</entry>
189 <entry><![CDATA[<h1>foobar</h1>]]></entry>
193 <entry>[img]http://framework.zend.com/images/logo.gif[/img]</entry>
196 <![CDATA[<img src="http://framework.zend.com/images/logo.gif" />]]>