ansi2html modifier


1Presentation

This Smarty modifier transforms into HTML a text containing ANSI escape sequences (terminal output). It uses the ansiToHtml() method of the \Temma\Utils\Text object.

The text is escaped, styles and colors are converted into <span> tags, hyperlinks into <a> tags, and other sequences are removed.


2Usage

This modifier takes no parameter. As line breaks are kept, the result must be displayed in a <pre> tag. Here is an example:

<pre>{$commandOutput|ansi2html}</pre>

3HTML escaping

The modifier escapes the text it receives by itself. With Smarty 5, the HTML it generates is not escaped a second time by the auto-escaping; there is nothing special to do.

With Smarty 4, if auto-escaping is enabled, the nofilter flag must be added:

<pre>{$commandOutput|ansi2html nofilter}</pre>
Warning: with Smarty 5 up to version 5.8.5 included, using ansi2html (like raw or escape) in a tag that displays nothing ({assign}, {if}…) disables the escaping of the next displayed variable.