Coder Social home page Coder Social logo

markua's Introduction

Markua

Build Status Code Climate Scrutinizer Code Quality Code Coverage

league/markua is a Markdown parser for PHP which intends to support the full Markua spec. The Markua spec is still evolving.

Goals

This aims to fully support the Markua specification, and will continue to evolve as the spec does.

League\CommonMark

This package depends on League\CommonMark and functions identically except for using the Markua specification.

Installation

This project can be installed via Composer:

$ composer require league/markua

Basic Usage

The MarkuaConverter class provides a simple wrapper for converting Markua to HTML:

use League\Markua\MarkuaConverter;

$converter = new MarkuaConverter();
echo $converter->convertToHtml('# Hello World!');

// <h1>Hello World!</h1>

Advanced Usage & Customization

The actual conversion process requires two steps:

  1. Parsing the Markdown input into an AST
  2. Rendering the AST document as HTML

Although the MarkuaConverter wrapper simplifies this process for you, advanced users will likely want to do this themselves:

use League\CommonMark\DocParser;
use League\CommonMark\Environment;
use League\CommonMark\HtmlRenderer;
use League\Markua\Environment\Markua;

// Obtain a pre-configured Environment with all the Markua parsers/renderers ready-to-go
$environment = Environment::createEnvironment(new Markua());

// Optional: Add your own parsers/renderers here, if desired
// For example:  $environment->addInlineParser(new TwitterHandleParser());

// Create the document parser and HTML renderer engines
$parser = new DocParser($environment);
$htmlRenderer = new HtmlRenderer($environment);

// Here's our sample input
$markdown = '# Hello World!';

// 1. Parse the Markdown to AST
$documentAST = $parser->parse($markdown);

// Optional: If you want to access/modify the AST before rendering, do it here

// 2. Render the AST as HTML
echo $htmlRenderer->renderBlock($documentAST);

// The output should be:
// <h1>Hello World!</h1>

This approach allows you to access/modify the AST before rendering it.

You can also add custom parsers/renderers by registering them with the Environment class. The league/commonmark documentation provides several customization examples such as:

You can also reference the core CommonMark parsers/renderers as they use the same functionality available to you.

Compatibility with Markua

This project aims to fully support the entire Markua Spec. Other flavors of Markdown may work but are not supported. Any/all changes made to the spec should eventually find their way back into this codebase.

This package is not part of Markua, but rather a compatible derivative.

Documentation

Documentation can be found at markua.thephpleague.com.

Testing

$ ./vendor/bin/phpunit

Stability and Versioning

While this package does work well, the underlying code should not be considered "stable" yet. The original spec may undergo changes in the near future, which will result in corresponding changes to this code. Any methods tagged with @api are not expected to change, but other methods/classes might.

Major release 1.0.0 will be reserved for when both Markua and this project are considered stable. 0.x.x will be used until that happens.

SemVer will be followed closely.

Contributing

If you encounter a bug in the spec, please report it to the Markua project. Any resulting fix will eventually be implemented in this project as well.

Please see CONTRIBUTING for additional details.

Credits & Acknowledgements

License

league/markua is licensed under the BSD-3 license. See the LICENSE file for more details.

markua's People

Contributors

dshafik avatar

Watchers

Stefan Auditor avatar James Cloos avatar

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.