How it works

From posting to displaying to editing, s9e\TextFormatter separates its operations in 4 distinct phases:

  • Configuration: configure s9e\TextFormatter and the plugins you want to use, or use a preconfigured bundle.

  • Parsing: the text is parsed and can be stored as an XML document.

  • Rendering: the XML document is transformed into HTML.

  • Unparsing: the XML document is transformed back into plain text.

              ↗         ↘
Original text             XML → Rendering → HTML
              ↖         ↙

The configurator object can be used to generate a parser object and a renderer object. They can be serialized and should be cached for performance. Preconfigured parsers and renderers are available through bundles.

                           ↗    ↕
$configurator → finalize()   (cache)
                           ↘    ↕

The parser object transforms plain text into XML, the renderer object transforms XML into HTML. The XML can be reverted back to the original text using the s9e\TextFormatter\Unparser::unparse() static method. This is done without losing or modifying any content. (apart from a few control characters such as NUL bytes)

      ↗                  ↘
$text                      $xml → $renderer->render() → $html
      ↖                  ↙