PHP library to parse reStructuredText document
The parser can be used this way:
<?php
$parser = new Dusta\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
$parser = $parser->parse($rst);
$head = array();
foreach ($parser->headerNodes as $node) {
$headers[] = $node->render();
}
$headers = $document; // array
$content = $parser->render(); // string
echo '<head>';
foreach ($headers as $value) {
echo $value;
}
echo '</head>';
echo '<body>';
echo $content;
echo '</body>';
Write your own class that extends the Dusta\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
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
This library is under MIT license