bredmor/yaro

Extensible Markdown Parser

0.0.1 2019-03-28 03:53 UTC

This package is auto-updated.

Last update: 2024-06-06 06:11:25 UTC


README

Build Status

Yaro is a Parser and Lexer framework meant for Markdown. By Default, Yaro parses basic markdown.

Installation / Usage

From Source:

Clone the repository from GitHub or unzip into your vendor directory. Yaro is packaged for PSR-4 autoloading.

From Composer:

composer require bredmor/yaro

Using in your project:

use bredmor\Yaro\Yaro;
$yaro = new Yaro();
echo $yaro->parse("Your *markdown* text here.");

Adding a new markdown token to the default lexer:

$lexer = new bredmor\Yaro\Lexer\DefaultLexer();
$lexer->setToken('/Your PCRE-compat regex here/', function($match) {
    // Any closure, function name or preg_* function compatible replacement string can be used for the 2nd argument
});
$yaro = new Yaro($lexer);
echo $yaro->parse("Your custom markdown text here.");

Extensibility

You can either extend the default parser or lexer, or implement LexerInterface and ParserInterface on your own, custom classes.

Just pass either to constructor when initiating it and it will be used instead of the default.

$parser = new MyCustomParser();
$yaro = new Yaro(null, $parser); // Using a NULL value for the parser or lexer in the controller will cause Yaro to use the default class.

You can also change the parser or lexer of an existing Yaro object at any time. This allows you to Inject an already configured Yaro instance and swap contexts on the fly.

$yaro = new Yaro();
echo $yaro->parse("My markdown string"); // The string is evaluated using the default lexer
$yaro->setLexer($myOtherLexerClass);
echo $yaro->parse("My other markdown string"); // This string is evaluated using the new lexer

Requirements

PHP 7.2 or above.

Supported Markdown

Yaro's default lexer supports the following markdown:

*Italic Emphasis* with asterisks or underscores

**Bold** with asterisks or underscores

~~Strikethrough~~

----- Horizonal Rulers

#Headings

>Blockquotes (>, >, |, >> and »)

``` Code Blocks

` Inline Code

*Unordered Lists (*, - and +)

  1. Ordered Lists (any number)

[Links](http://example.com)

![Embedded Images](link_to_image.png)

Authors

Contributing

Pull requests, bug reports and feature requests are welcome.

License

Yaro is licensed under the GPLv3 License - see the LICENSE file for details

Acknowledgements

Yaro is named after the individual who really wanted me to write another markdown parser specifically for their use case.