Code Monkey home page Code Monkey logo

idiom's Introduction

Idiom

PHP from Packagist Latest Version Total Downloads GitHub Workflow Status PHPStan License

Lightweight text to HTML parser - tags optional

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.


Installation

Install the library via composer:

composer require decodelabs/idiom

Usage

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);

Metamorph

Idiom also provides a Metamorph Handler so that it can be used via its simplified interface:

use DecodeLabs\Metamorph;

echo Metamorph::{'idiom.extended'}($content);

Output

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.

Safety

Please note, Idiom does not yet exhaustively treat input for malicious entities - this parser should only be used with content considered safe.

Licensing

Idiom is licensed under the MIT License. See LICENSE for the full license text.

idiom's People

Contributors

betterthanclay avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

idiom's Issues

Not able to run this

Hello,

I have tried running this code, but not able to.
This is my php file :

< ?php
use DecodeLabs\Idiom\Parser;

$content = "ss"
echo Metamorph::{'idiom.extended'}($content);
?>

Am I doing something wrong here? When I run this, the code itself gets printed.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.