usox / html2text
一个用于将HTML转换为纯文本格式的hacklang脚本
v1.0.0
2019-02-27 11:23 UTC
Requires
- ext-libxml: *
- hhvm: ^4
Requires (Dev)
- facebook/fbexpect: ^2.3
- hhvm/hacktest: ^1.4
- hhvm/hhast: ^4.0
This package is auto-updated.
Last update: 2024-08-28 00:12:44 UTC
README
html2text是一个非常简单的脚本,它使用DOM方法将HTML转换为类似于浏览器渲染的格式——非常适合需要快速文本表示的地方。例如
<html> <title>Ignored Title</title> <body> <h1>Hello, World!</h1> <p>This is some e-mail content. Even though it has whitespace and newlines, the e-mail converter will handle it correctly. <p>Even mismatched tags.</p> <div>A div</div> <div>Another div</div> <div>A div<div>within a div</div></div> <a href="http://foo.com">A link</a> </body> </html>
将被转换为
Hello, World!
This is some e-mail content. Even though it has whitespace and newlines, the e-mail converter will handle it correctly.
Even mismatched tags.
A div
Another div
A div
within a div
[A link](http://foo.com)
安装
{ "require": { "usox/html2text": "^1" } }
然后非常简单地使用它
$converter = new \Usox\Html2Text() $text = $converter->convert($html);
您也可以包含提供的html2text.php
,并用$text = convert_html_to_text($html);
代替。
选项
将选项作为convert
的第二个参数传递,例如
$html = 'some fine html'; $options = dict[ 'ignore_errors' => true, // other options go here ]; $converter = new \Usox\Html2Text() echo $converter->convert($html, $options);
测试
在tests/
目录中提供了一些非常基本的测试。运行它们使用composer install && vendor/bin/hacktest tests
。
许可证
html2text
受MIT许可证的约束,这使得它适用于Eclipse和GPL项目。
其他版本
这是一个从这里找到的php版本的移植。