gregwar/rst
Composer 安装命令:
composer require gregwar/rst
包简介
PHP library to parse reStructuredText documents
README 文档
README
PHP library to parse reStructuredText document
Usage
The parser can be used this way:
<?php $parser = new Gregwar\RST\Parser; // RST document $rst = ' Hello world =========== What is it? ---------- This is a **RST** document! Where can I get it? ------------------- You can get it on the `GitHub page <https://github.com/Gregwar/RST>`_ '; // Parse it $document = $parser->parse($rst); // Render it echo $document; /* Will output, in HTML mode: <a id="title.1"></a><h1>Hello world</h1> <a id="title.1.1"></a><h2>What is it?</h2> <p>This is a <b>RST</b> document!</p> <a id="title.1.2"></a><h2>Where can I get it?</h2> <p>You can get it on the <a href="https://github.com/Gregwar/RST">GitHub page</a></p> */
For more information, you can have a look at test/document/document.rst and its result
test/document/document.html
Using the builder
The builder is another tool that will parses a whole tree of documents and generates an output directory containing files.
You can simply use it with:
<?php $builder = new Gregwar\RST\Builder; $builder->build('input', 'output');
It will parses all the files in the input directory, starting with index.rst and
scanning for dependencies references and generates you target files in the output
directory. Default format is HTML.
You can use those methods on it to customize the build:
copy($source, $destination): copy the$sourcefile or directory to the$destinationfile or directory of the buildmkdir($directory): create the$directoryin build directoryaddHook($function): adds an hook that will be called after each document is parsed, this hook will be called with the$documentas parameter and can then tweak it as you wantaddBeforeHook($function): adds an hook that will be called before parsing the document, the parser will be passed as a parameter
Abort on error
In some situation you want the build to continue even if there is some errors, like missing references:
<?php // Using parser $parser->getEnvironment()->getErrorManager()->abortOnError(false); // Using builder $builder->getErrorManager()->abortOnError(false);
Writing directives
Step 1: Extends the Directive class
Write your own class that extends the Gregwar\RST\Directive class, and define the
method getName() that return the directive name.
You can then redefine one of the following method:
processAction()if your directive simply tweak the document without modifying the nodesprocessNode()if your directive is adding a nodeprocess()if your directive is tweaking the node that just follows it
See Directive.php for more information
Step 2: Register your directive
You can register your directive by directly calling registerDirective() on your
Parser object.
Else, you will have to also create your own kernel by extending the Kernel class
and adding your own logic to define extra directives, see Kernel.php for more information.
Then, pass the kernel when constructing the Parser or the Builder
License
This library is under MIT license
gregwar/rst 适用场景与选型建议
gregwar/rst 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 514.31k 次下载、GitHub Stars 达 93, 最近一次更新时间为 2013 年 07 月 04 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「parser」 「markup」 「rst」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 gregwar/rst 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 gregwar/rst 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 gregwar/rst 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
PHP library to parse reStructuredText documents and generate HTML or LaTeX documents.
Texy converts plain text in easy to read Texy syntax into structurally valid (X)HTML. It supports adding of images, links, nested lists, tables and has full support for CSS. Texy supports hyphenation of long words (which reflects language rules), clickable emails and URL (emails are obfuscated again
Easy to use SDK with grabber for multiple platforms at once like YouTube, Dailymotion, Facebook and more.
PHPDoc to Sphinx phpdomain tool
An MT940 bank statement parser for PHP
PHP library to parse reStructuredText documents
统计信息
- 总下载量: 514.31k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 94
- 点击次数: 28
- 依赖项目数: 15
- 推荐数: 3
其他信息
- 授权协议: MIT
- 更新时间: 2013-07-04