Zend_Markup Parsers

Zend_Markup Renderers

Zend_Markup is currently shipped with one renderer, the HTML renderer.

Adding your own markups

By adding your own markups, you can add your own functionality to the Zend_Markup 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:

  1. // Creates instance of Zend_Markup_Renderer_Html,
  2. // with Zend_Markup_Parser_BbCode as its parser
  3. 'Bbcode');
  4.  
  5. // this will create a simple 'foo' markup
  6. // The first parameter defines the markup's name.
  7. // The second parameter takes an integer that defines the markups type.
  8. // The third parameter is an array that defines other things about a
  9. // markup, like the markup's group, and (in this case) a start and end markup.
  10. $bbcode->addMarkup(
  11.     'foo''start' => '-bar-',
  12.         'end'   => '-baz-',
  13.         'group' => 'inline'
  14.     )
  15. );
  16.  
  17. // now, this will output: 'my -bar-markup-baz-'
  18. 'my [foo]markup[/foo]');

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.

Some renderers (like the HTML 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.

Add a callback markup

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.

A callback is a class that implements the Zend_Markup_Renderer_TokenInterface interface. An example of a callback class:

  1. span style="color: #ff0000;">'!up!''!up!';
  2.     }
  3.  
  4. }

Now you can add the 'upper' markup, with as callback, an instance of the My_Markup_Renderer_Html_Upper class. A simple example:

  1. // Creates instance of Zend_Markup_Renderer_Html,
  2. // with Zend_Markup_Parser_BbCode as its parser
  3. 'Bbcode');
  4.  
  5. // this will create a simple 'foo' markup
  6. // The first parameter defines the markup's name.
  7. // The second parameter takes an integer that defines the markups type.
  8. // The third parameter is an array that defines other things about a
  9. // markup, like the markup's group, and (in this case) a start and end markup.
  10. $bbcode->addMarkup(
  11.     'upper''callback''group'    => 'inline'
  12.     )
  13. );
  14.  
  15. // now, this will output: 'my !up!MARKUP!up!'
  16. 'my [upper]markup[/upper]');

List of markups

List of markups
Sample input (bbcode) Sample output
[b]foo[/b] <strong>foo</strong>
[i]foo[/i] <em>foo</em>
[cite]foo[/cite] <cite>foo</cite>
[del]foo[/del] <del>foo</del>
[ins]foo[/ins] <ins>foo</ins>
[sup]foo[/sup] <sup>foo</sup>
[sub]foo[/sub] <sub>foo</sub>
[span]foo[/span] <span>foo</span>
[acronym title="PHP Hypertext Preprocessor]PHP[/acronym] <acronym title="PHP Hypertext Preprocessor">PHP</acronym>
[url=http://framework.zend.com/]Zend Framework[/url] <a href="http://framework.zend.com/">Zend Framework</a>
[h1]foobar[/h1] <h1>foobar</h1>
[img]http://framework.zend.com/images/logo.gif[/img] <img src="http://framework.zend.com/images/logo.gif" />

Zend_Markup Parsers