Introducción a Zend Framework

 Aprendiendo Zend Framework

Apéndice

 Referencia de Zend Framework


  • Zend_Gdata
  • Zend_Http
  • Zend_InfoCard
  • Zend_Json
  • Zend_Layout
  • Zend_Ldap
  • Zend_Loader
  • Zend_Locale
  • Zend_Log
  • Zend_Mail
  • Zend_Markup
  • Zend_Measure
  • Zend_Memory
  • Zend_Mime
  • Zend_Navigation
  • Zend_Oauth
  • Zend_OpenId
  • Zend_Paginator
  • Zend_Pdf
  • Zend_ProgressBar
  • Zend_Queue
  • Zend_Reflection
  • Zend_Registry
  • Zend_Rest

  • Zend_Search_Lucene
  • Zend_Serializer
  • Zend_Server
  • Zend_Service
  • Zend_Session
  • Zend_Soap
  • Zend_Tag
  • Zend_Test
  • Zend_Text
  • Zend_TimeSync
  • Zend_Tool
  • Zend_Tool_Framework
  • Zend_Tool_Project
  • Zend_Translate
  • Zend_Uri
  • Zend_Validate
  • Zend_Version
  • Zend_View
  • Zend_Wildfire
  • Zend_XmlRpc
  • ZendX_Console_Process_Unix
  • ZendX_JQuery
  • Traducción al 26.9% - Actualizado el 2011-11-16 - Revisión 24249 - Versión ZF 1.11.x

    46.4. Zend_Markup Renderers

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

    46.4.1. 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:

    // 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]');

    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. Textile doesn't have support for custom markups.

    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.

    46.4.1.1. 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:

    class My_Markup_Renderer_Html_Upper
        
    implements Zend_Markup_Renderer_TokenConverterInterface
    {

        public function 
    convert(Zend_Markup_Token $token$text)
        {
            return 
    '!up!' strtoupper($text) . '!up!';
        }

    }

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

    // 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]');

    46.4.2. List of markups

    Tabla 46.2. 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" />

    digg delicious meneame google twitter technorati facebook

    Comentarios

    Loading...