| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203 |
- <?xml version="1.0" encoding="UTF-8"?>
- <!-- Reviewed: no -->
- <sect1 id="zend.markup.renderers">
- <title>Zend_Markup Renderers</title>
- <para>
- <classname>Zend_Markup</classname> is currently shipped with one renderer, the
- <acronym>HTML</acronym> renderer.
- </para>
- <sect2 id="zend.markup.renderers.add">
- <title>Adding your own markups</title>
- <para>
- By adding your own markups, you can add your own functionality to the
- <classname>Zend_Markup</classname> renderers. With the markup structure, you can add
- about any functionality you want. From simple markups, to complicated markup structures.
- A simple example for a 'foo' markup:
- </para>
- <programlisting language="php"><![CDATA[
- // Creates instance of Zend_Markup_Renderer_Html,
- // with Zend_Markup_Parser_BbCode as its parser
- $bbcode = Zend_Markup::factory('Bbcode');
- // this will create a simple 'foo' markup
- // The first parameter defines the markup's name.
- // The second parameter takes an integer that defines the markups type.
- // The third parameter is an array that defines other things about a
- // markup, like the markup's group, and (in this case) a start and end markup.
- $bbcode->addMarkup(
- 'foo',
- Zend_Markup_Renderer_RendererAbstract::TYPE_REPLACE,
- array(
- 'start' => '-bar-',
- 'end' => '-baz-',
- 'group' => 'inline'
- )
- );
- // now, this will output: 'my -bar-markup-baz-'
- echo $bbcode->render('my [foo]markup[/foo]');
- ]]></programlisting>
- <para>
- Please note that creating your own markups only makes sense when your parser also
- supports it with a markup structure. Currently, only BBCode supports this.
- </para>
- <para>
- Some renderers (like the <acronym>HTML</acronym> renderer) also have support for a
- 'markup' parameter. This replaces the 'start' and 'end' parameters, and
- it renders the markups including some default attributes and the
- closing markup.
- </para>
- <sect3 id="zend.markup.renderers.add.callback">
- <title>Add a callback markup</title>
- <para>
- By adding a callback markup, you can do a lot more then just a
- simple replace of the markups. For instance, you can change the
- contents, use the parameters to influence the output etc.
- </para>
- <para>
- A callback is a class that implements the
- <classname>Zend_Markup_Renderer_TokenInterface</classname>
- interface. An example of a callback class:
- </para>
- <programlisting language="php"><![CDATA[
- class My_Markup_Renderer_Html_Upper
- implements Zend_Markup_Renderer_TokenConverterInterface
- {
- public function convert(Zend_Markup_Token $token, $text)
- {
- return '!up!' . strtoupper($text) . '!up!';
- }
- }
- ]]></programlisting>
- <para>
- Now you can add the 'upper' markup, with as callback, an instance
- of the <classname>My_Markup_Renderer_Html_Upper</classname>
- class. A simple example:
- </para>
- <programlisting language="php"><![CDATA[
- // Creates instance of Zend_Markup_Renderer_Html,
- // with Zend_Markup_Parser_BbCode as its parser
- $bbcode = Zend_Markup::factory('Bbcode');
- // this will create a simple 'foo' markup
- // The first parameter defines the markup's name.
- // The second parameter takes an integer that defines the markups type.
- // The third parameter is an array that defines other things about a
- // markup, like the markup's group, and (in this case) a start and end markup.
- $bbcode->addMarkup(
- 'upper',
- Zend_Markup_Renderer_RendererAbstract::TYPE_CALLBACK,
- array(
- 'callback' => new My_Markup_Renderer_Html_Upper(),
- 'group' => 'inline'
- )
- );
- // now, this will output: 'my !up!MARKUP!up!'
- echo $bbcode->render('my [upper]markup[/upper]');
- ]]></programlisting>
- </sect3>
- </sect2>
- <sect2 id="zend.markup.renderers.list">
- <title>List of markups</title>
- <table id="zend.markup.renderers.list.markups">
- <title>List of markups</title>
- <tgroup cols="2" align="left" colsep="1" rowsep="1">
- <thead>
- <row>
- <entry>Sample input (bbcode)</entry>
- <entry>Sample output</entry>
- </row>
- </thead>
- <tbody>
- <row>
- <entry>[b]foo[/b]</entry>
- <entry><![CDATA[<strong>foo</strong>]]></entry>
- </row>
- <row>
- <entry>[i]foo[/i]</entry>
- <entry><![CDATA[<em>foo</em>]]></entry>
- </row>
- <row>
- <entry>[cite]foo[/cite]</entry>
- <entry><![CDATA[<cite>foo</cite>]]></entry>
- </row>
- <row>
- <entry>[del]foo[/del]</entry>
- <entry><![CDATA[<del>foo</del>]]></entry>
- </row>
- <row>
- <entry>[ins]foo[/ins]</entry>
- <entry><![CDATA[<ins>foo</ins>]]></entry>
- </row>
- <row>
- <entry>[sup]foo[/sup]</entry>
- <entry><![CDATA[<sup>foo</sup>]]></entry>
- </row>
- <row>
- <entry>[sub]foo[/sub]</entry>
- <entry><![CDATA[<sub>foo</sub>]]></entry>
- </row>
- <row>
- <entry>[span]foo[/span]</entry>
- <entry><![CDATA[<span>foo</span>]]></entry>
- </row>
- <row>
- <entry>[acronym title="PHP Hypertext Preprocessor]PHP[/acronym]</entry>
- <entry>
- <![CDATA[<acronym title="PHP Hypertext Preprocessor">PHP</acronym>]]>
- </entry>
- </row>
- <row>
- <entry>[url=http://framework.zend.com/]Zend Framework[/url]</entry>
- <entry>
- <![CDATA[<a href="http://framework.zend.com/">Zend Framework</a>]]>
- </entry>
- </row>
- <row>
- <entry>[h1]foobar[/h1]</entry>
- <entry><![CDATA[<h1>foobar</h1>]]></entry>
- </row>
- <row>
- <entry>[img]http://framework.zend.com/images/logo.gif[/img]</entry>
- <entry>
- <![CDATA[<img src="http://framework.zend.com/images/logo.gif" />]]>
- </entry>
- </row>
- </tbody>
- </tgroup>
- </table>
- </sect2>
- </sect1>
|