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
<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:
```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
<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:
```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(AnsiExtension($converter));
```
Then:
```jinja
<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>
```
没有合适的资源?快使用搜索试试~ 我知道了~
ANSI to HTML5 一个将ANSI转换为HTML5的类库
共11个文件
php:6个
license:1个
gitignore:1个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 83 浏览量
2022-04-28
20:58:42
上传
评论
收藏 10KB ZIP 举报
温馨提示
ANSI to HTML5 一个将ANSI转换为HTML5的类库
资源推荐
资源详情
资源评论
收起资源包目录
ansi-to-html-master.zip (11个子文件)
ansi-to-html-master
composer.json 590B
SensioLabs
AnsiConverter
Bridge
Twig
AnsiExtension.php 985B
Tests
AnsiToHtmlConverterTest.php 2KB
AnsiToHtmlConverter.php 5KB
Theme
SolarizedXTermTheme.php 1KB
SolarizedTheme.php 1KB
Theme.php 1KB
LICENSE 1KB
.gitignore 23B
phpunit.xml.dist 573B
README.md 2KB
共 11 条
- 1
资源评论
reg183
- 粉丝: 1818
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功