All Projects → Gregwar → Rst

Gregwar / Rst

Licence: mit
PHP library to parse reStructuredText documents

Projects that are alternatives of or similar to Rst

Anglesharp
👼 The ultimate angle brackets parser library parsing HTML5, MathML, SVG and CSS to construct a DOM based on the official W3C specifications.
Stars: ✭ 4,018 (+4364.44%)
Mutual labels:  parser, library
Badx12
A Python Library for parsing ANSI ASC X12 files.
Stars: ✭ 25 (-72.22%)
Mutual labels:  parser, library
Swaggen
OpenAPI/Swagger 3.0 Parser and Swift code generator
Stars: ✭ 385 (+327.78%)
Mutual labels:  parser, library
Length.js
📏 JavaScript library for length units conversion.
Stars: ✭ 292 (+224.44%)
Mutual labels:  parser, library
Sharpmath
A small .NET math library.
Stars: ✭ 36 (-60%)
Mutual labels:  parser, library
Regex
The Hoa\Regex library.
Stars: ✭ 308 (+242.22%)
Mutual labels:  parser, library
Compiler
The Hoa\Compiler library.
Stars: ✭ 458 (+408.89%)
Mutual labels:  parser, library
Isobmff
C++ Library for ISO/IEC 14496-12 - ISO Base Media File Format (QuickTime, MPEG-4, HEIF, etc)
Stars: ✭ 157 (+74.44%)
Mutual labels:  parser, library
Substitution Schedule Parser
Java library for parsing schools' substitution schedules. Supports multiple different systems mainly used in the German-speaking countries, including Untis, svPlan, and DAVINCI
Stars: ✭ 33 (-63.33%)
Mutual labels:  parser, library
Anglesharp.css
👼 Library to enable support for cascading stylesheets in AngleSharp.
Stars: ✭ 27 (-70%)
Mutual labels:  parser, library
Php Svg
Vector graphics (SVG) library for PHP
Stars: ✭ 256 (+184.44%)
Mutual labels:  parser, library
Cat
Plain C library for parsing AT commands for use in host devices.
Stars: ✭ 77 (-14.44%)
Mutual labels:  parser, library
Vmime
VMime Mail Library
Stars: ✭ 218 (+142.22%)
Mutual labels:  parser, library
Shortcode
Advanced shortcode (BBCode) parser and engine for PHP
Stars: ✭ 331 (+267.78%)
Mutual labels:  parser, library
Sdk
Library for using Grafana' structures in Go programs and client for Grafana REST API.
Stars: ✭ 193 (+114.44%)
Mutual labels:  parser, library
Javalang
Pure Python Java parser and tools
Stars: ✭ 408 (+353.33%)
Mutual labels:  parser, library
Phplrt
PHP Language Recognition Tool
Stars: ✭ 127 (+41.11%)
Mutual labels:  parser, library
Libnmea
Lightweight C library for parsing NMEA 0183 sentences
Stars: ✭ 146 (+62.22%)
Mutual labels:  parser, library
Go Deb Version
A golang library for parsing deb package versions
Stars: ✭ 21 (-76.67%)
Mutual labels:  parser, library
Anglesharp.js
👼 Extends AngleSharp with a .NET-based JavaScript engine.
Stars: ✭ 68 (-24.44%)
Mutual labels:  parser, library

RST

Build status paypal

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 $source file or directory to the $destination file or directory of the build
  • mkdir($directory): create the $directory in build directory
  • addHook($function): adds an hook that will be called after each document is parsed, this hook will be called with the $document as parameter and can then tweak it as you want
  • addBeforeHook($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 nodes
  • processNode() if your directive is adding a node
  • process() 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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].