Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sensiolabs/ansi-to-html
An ANSI to HTML5 converter
https://github.com/sensiolabs/ansi-to-html
Last synced: 4 days ago
JSON representation
An ANSI to HTML5 converter
- Host: GitHub
- URL: https://github.com/sensiolabs/ansi-to-html
- Owner: sensiolabs
- License: mit
- Created: 2013-03-19T07:58:18.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2022-09-30T07:50:47.000Z (about 2 years ago)
- Last Synced: 2024-10-31T06:34:56.835Z (12 days ago)
- Language: PHP
- Size: 27.3 KB
- Stars: 238
- Watchers: 15
- Forks: 31
- Open Issues: 13
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-php - ANSI to HTML5 - An ANSI to HTML5 converter library. (Table of Contents / Strings)
- awesome-php-cn - ANSI to HTML5 - 一个ANSI到HTML5的转换库. (目录 / 字符串 Strings)
- awesome-projects - ANSI to HTML5 - An ANSI to HTML5 converter library. (PHP / Strings)
- awesome-php - ANSI to HTML5 - An ANSI to HTML5 converter library. (Table of Contents / Strings)
README
ANSI to HTML5 Converter
=======================This small library only does one thing: converting a text containing ANSI
codes to an HTML5 fragment:```php
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+php
```
The converter supports different color themes:
```php
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:```php
$converter = new AnsiToHtmlConverter($theme, false);
```And the `asCss()` method of the theme object lets you retrieve the theme styles
as a CSS snippet:```php
$styles = $theme->asCss();
```which you can then use in your HTML document:
```html+php
<?php echo $styles ?>.ansi_box { overflow: auto; padding: 10px 15px; font-family: monospace; }
```
Twig Integration
----------------Register the extension:
```php
use SensioLabs\AnsiConverter\Bridge\Twig\AnsiExtension;$twig->addExtension(AnsiExtension());
```It's possible to use a custom ``AnsiToHtmlConverter``:
```php
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:
```jinja
{# This is only need if the inline styling is disabled #}
{{ ansi_css }}
{{ some_ansi_code|ansi_to_html }}
```