roelofjan-elsinga / content-to-html-parser
此包将内容从字符串或文件转换为要在页面上渲染的HTML字符串
0.5.1
2020-02-05 14:47 UTC
Requires
- php: >=7.2.0
- erusev/parsedown: ^1.7
Requires (Dev)
- phpunit/phpunit: ^8.0.5
README
此包将内容从字符串或文件转换为要在页面上渲染的HTML字符串。
安装
您可以通过Composer使用此包:
composer require roelofjan-elsinga/content-to-html-parser
用法
use ContentParser\ContentParser; $parser = ContentParser::forFile('/absolute/path/to/file.txt'); // OR $parse_string = 'This is some beautiful text'; $parser = ContentParser::forString($parse_string, 'txt'); print $parser->parse(); // This is an HTML string
可用的解析器
目前包含三个解析器
- HTML到HTML:这不会修改字符串
- Markdown到HTML:这解析Markdown到HTML字符串
- TXT到HTML:这通过nl2br()将纯文本解析为可用的HTML标记
可用的方法
此包包含两个命名的构造函数
public static function forFile(string $file_path): ContentParserInterface
public static function forString(string $file_contents, string $file_extension = null): ContentParserInterface
您可以通过调用: public function parse(): string
来解析字符串并获取生成的HTML字符串
如果您想获取底层的解析器,可以使用: public function getParser(): ContentParserInterface
测试
您可以通过在终端中运行 ./vendor/bin/phpunit
来运行包含的测试。
贡献
如果您想贡献,您可以添加额外的ContentParsers或改进当前的解析器。