You are browsing a version that is no longer maintained.

Introduction

The Doctrine RST Parser is a PHP library that can parse reStructuredText documents and render them in HTML or LaTeX.

Installation

You can install the Doctrine RST Parser with composer:

$ composer require doctrine/rst-parser

Basic Usage

Here is an example script that demonstrates how to use the RST Parser. Create a file named rst-test.php in the root of your project and paste the following code:

1require 'vendor/autoload.php'; use Doctrine\RST\Parser; $parser = new 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/doctrine/rst-parser>`_ '; // Parse it $document = $parser->parse($rst); // Render it echo $document->render();
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25

Now execute the script:

$ php rst-test.php

The above would output the following HTML:

1<div class="section" id="hello-world"> <h1>Hello world</h1> </div> <div class="section" id="what-is-it"> <h2>What is it?</h2> <p>This is a <strong>RST</strong> document!</p> </div> <div class="section" id="where-can-i-get-it"> <h2>Where can I get it?</h2> <p>You can get it on the <a href="https://github.com/doctrine/rst-parser">GitHub page</a></p> </div>
2
3
4
5
6
7
8
9
10
11

If you want to render a full HTML document you can do so with the renderDocument() method:

1echo $document->renderDocument();

The above would output the following:

1<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> </head> <body> <div class="section" id="hello-world"> <h1>Hello world</h1> </div> <div class="section" id="what-is-it"> <h2>What is it?</h2> <p>This is a <strong>RST</strong> document!</p> </div> <div class="section" id="where-can-i-get-it"> <h2>Where can I get it?</h2> <p>You can get it on the <a href="https://github.com/doctrine/rst-parser">GitHub page</a></p> </div> </body> </html>
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23

If you would like to customize the rendered HTML take a look at the Customizing Rendering chapter.