Idiom provides a simple and easy to use text parser that can convert natural language with an optional subset of HTML tags to full markup ready for consumption.
Get news and updates on the DecodeLabs blog.
Install the library via composer:
composer require decodelabs/idiom
Parse a block of text with optional HTML tags into rendered HTML:
use DecodeLabs\Idiom\Parser;
$content = <<<CONTENT
Idiom allows you to write naturally, converting paragraphs, lines and spaces to the relevant HTML elements.
You can include <strong>tags</strong> where necessary.
<ul>
<li>Block elements like this can be used if extended mode is enabled</li>
<li>Alternatively, content can be rendered as inline HTML with inline mode</li>
</ul>
CONTENT;
$parser = new Parser();
$parser->setExtended(true);
echo $parser->parse($content);
Idiom also provides a Metamorph Handler so that it can be used via its simplified interface:
use DecodeLabs\Metamorph;
echo Metamorph::{'idiom.extended'}($content);
The parsed HTML provided by Idiom is wrapped in a Markup
interface from the Tagged library such that output is handled correctly in all rendering contexts.
Please note, Idiom does not yet exhaustively treat input for malicious entities - this parser should only be used with content considered safe.
Idiom is licensed under the MIT License. See LICENSE for the full license text.