gregwar/rst
gregwar/rst adds reStructuredText parsing to PHP. Convert .rst documents into HTML (and other formats), with a simple API and CLI-friendly usage. Useful for documentation sites, static content, and integrating RST into Laravel or custom apps.
Install via Composer: composer require gregwar/rst. Start with the core flow: instantiate Parser, parse your RST string, then render to HTML:
use Gregwar\RST\Parser;
$rst = "**Hello**\n\nThis is a *paragraph*.";
$html = (new Parser())->parse($rst)->render();
// <p><strong>Hello</strong></p>\n<p>This is a <em>paragraph</em>.</p>
First use case: convert a static .rst file (e.g., docs/CHANGELOG.rst) into an HTML fragment for a Laravel view. Check the repo’s examples/ folder—01_basic.php is the canonical starting point.
.rst content during deploy (e.g., via a Laravel Artisan command) and cache the HTML in the database or filesystem. Great for changelogs, READMEs, or Sphinx-generated docs.RstRenderer service, storing raw RST + rendered HTML. Use Laravel’s caching for performance.NodeVisitor to traverse the AST, then register it with Parser::setNodeVisitor($visitor).Blade::directive('rst', fn ($expression) => "<?php echo app(App\\Services\\RstRenderer::class)->render($expression); ?>");
Parser ignores unknown directives (e.g., .. important::). During development, enable strict mode (new Parser(true)) to surface unexpected syntax—otherwise errors vanish silently.DirectiveInterface, then call Parser::setDirective('mydirective', $instance). This replaces the previous directive, so avoid overwriting built-ins unintentionally.Parser::setErrorHandler(fn ($msg) => logger()->warning('RST parsing: ' . $msg)) to catch subtle layout issues.<pre><code>...</code></pre> with no language tokenization. Add syntax highlighting post-render via JavaScript (e.g., Highlight.js) or a post-processing step (e.g., symfony/dom-crawler + php-highlighter).$node->children or $node->value directly across versions. Prefer NodeVisitor pattern for traversal—Laravel’s cache keys can store serialized ASTs safely, but validate format changes on package upgrades.How can I help you explore Laravel packages today?