ProductPromotion
Logo

PHP

made by https://0x3d.site

GitHub - sensiolabs/ansi-to-html: An ANSI to HTML5 converter
An ANSI to HTML5 converter. Contribute to sensiolabs/ansi-to-html development by creating an account on GitHub.
Visit Site

GitHub - sensiolabs/ansi-to-html: An ANSI to HTML5 converter

GitHub - sensiolabs/ansi-to-html: An ANSI to HTML5 converter

ANSI to HTML5 Converter

This small library only does one thing: converting a text containing ANSI codes to an HTML5 fragment:

require_once __DIR__.'/vendor/autoload.php';

use SensioLabs\AnsiConverter\AnsiToHtmlConverter;

$converter = new AnsiToHtmlConverter();

$html = $converter->convert($ansi);

The $ansi variable should contain a text with ANSI codes, and $html will contain the converted HTML5 version of it.

You can then output the HTML5 fragment in any HTML document:

<html>
    <body>
        <pre style="background-color: black; overflow: auto; padding: 10px 15px; font-family: monospace;"
        ><?php echo $html ?></pre>
    </body>
</html>

The converter supports different color themes:

use SensioLabs\AnsiConverter\Theme\SolarizedTheme;

$theme = new SolarizedTheme();
$converter = new AnsiToHtmlConverter($theme);

By default, the colors are inlined into the HTML, but you can also use classes by turning off style inlining:

$converter = new AnsiToHtmlConverter($theme, false);

And the asCss() method of the theme object lets you retrieve the theme styles as a CSS snippet:

$styles = $theme->asCss();

which you can then use in your HTML document:

<html>
    <head>
        <style>
            <?php echo $styles ?>

            .ansi_box { overflow: auto; padding: 10px 15px; font-family: monospace; }
        </style>
    </head>
    <body>
        <pre class="ansi_color_bg_black ansi_color_fg_white ansi_box"><?php echo $html ?></pre>
    </body>
</html>

Twig Integration

Register the extension:

use SensioLabs\AnsiConverter\Bridge\Twig\AnsiExtension;

$twig->addExtension(AnsiExtension());

It's possible to use a custom AnsiToHtmlConverter:

use SensioLabs\AnsiConverter\Bridge\Twig\AnsiExtension;
use SensioLabs\AnsiConverter\Theme\SolarizedTheme;

$theme = new SolarizedTheme();
$converter = new AnsiToHtmlConverter($theme, false);

$twig->addExtension(new AnsiExtension($converter));

Then:

<html>
    <head>
        <style>
            {# This is only need if the inline styling is disabled #}
            {{ ansi_css }}
        </style>
    </head>
    <body>
        {{ some_ansi_code|ansi_to_html }}
    </body>
</html>

More Resources
to explore the angular.

mail [email protected] to add your project or resources here 🔥.

Related Articles
to learn about angular.

FAQ's
to learn more about Angular JS.

mail [email protected] to add more queries here 🔍.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory