PHPackages                             ntzwbr/markdown - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. ntzwbr/markdown

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

ntzwbr/markdown
===============

A new flavor to cebe/markdown inspired by https://github.com/dreikanter/markdown-grid

0.9.2(12y ago)137MITHTMLPHP &gt;=5.4.0

Since Feb 18Pushed 11y ago1 watchersCompare

[ Source](https://github.com/Netzweberei/markdown)[ Packagist](https://packagist.org/packages/ntzwbr/markdown)[ Docs](http://www.cebe.cc/markdown)[ RSS](/packages/ntzwbr-markdown/feed)WikiDiscussions master Synced 4d ago

READMEChangelogDependencies (2)Versions (5)Used By (0)

A super fast, highly extensible markdown parser for PHP
=======================================================

[](#a-super-fast-highly-extensible-markdown-parser-for-php)

[![Latest Stable Version](https://camo.githubusercontent.com/a66d5da6020dc8158936ccfbe7e9bbb64caa435d47190245308ed1e5a3ad4053/68747470733a2f2f706f7365722e707567782e6f72672f636562652f6d61726b646f776e2f762f737461626c652e706e67)](https://packagist.org/packages/cebe/markdown)[![Total Downloads](https://camo.githubusercontent.com/7c4ce6acd4e0ae9d081ed29a0cb8b6b816c762399d088a5c89fcdeaffc8afe50/68747470733a2f2f706f7365722e707567782e6f72672f636562652f6d61726b646f776e2f646f776e6c6f6164732e706e67)](https://packagist.org/packages/cebe/markdown)[![Build Status](https://camo.githubusercontent.com/10ae21a490dbd55e1be7eb2f1532d7538b07e41aeb0aee5c0c1d496a38162177/68747470733a2f2f7365637572652e7472617669732d63692e6f72672f636562652f6d61726b646f776e2e706e67)](http://travis-ci.org/cebe/markdown)[![Tested against HHVM](https://camo.githubusercontent.com/41b25f455ea40a200f847d8fa2b1e15b40cd8895ea1645ad0f36f20d14c2ee1d/687474703a2f2f6868766d2e683463632e64652f62616467652f636562652f6d61726b646f776e2e706e67)](http://hhvm.h4cc.de/package/cebe/markdown)[![Code Coverage](https://camo.githubusercontent.com/167d51dae262f0ee77cfb676f95fa973191aad68b7648daabc64de7cae01ce30/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f636562652f6d61726b646f776e2f6261646765732f636f7665726167652e706e673f733d64623661663334326435356265613634393330376566333131666264353336616262396261623736)](https://scrutinizer-ci.com/g/cebe/markdown/)

Markdown Grid Extension
-----------------------

[](#markdown-grid-extension)

### A new Flavor to cebe/markdown inspired by

[](#a-new-flavor-to-cebemarkdown-inspired-by-httpsgithubcomdreikantermarkdown-grid)

This is [Markdown](http://daringfireball.net/projects/markdown/) extension for grid building. It provides minimal and straightforward syntax to create multicolumn text layouts. By default the extension generates [Twitter Bootstrap](http://twitter.github.com/bootstrap/) compatible HTML code but it is intended to be template-agnostic. It could be configured to use any other HTML/CSS framework (e.g. [Skeleton](http://getskeleton.com)) or custom design.

### The Syntax

[](#the-syntax)

Markdown syntax extension is pretty simple. Page source example below defines a three-column page fragment:

```
-- row 5,2,5 --
First column contains couple of paragraphs. Lorem ipsum dolor sit amet,
consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore
et dolore magna aliqua.

Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi
ut aliquip ex ea commodo consequat.
----
Some images in the middle column:
![One](image-1.png)
![Two](image-2.png)
----
And some **more** text in the _third_ column. Duis aute irure dolor in
reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.

[Excepteur](http://excepteur.org ) sint occaecat cupidatat non proident, sunt
in culpa qui officia deserunt mollit anim id est laborum.
-- end --
```

Comma separated list of numbers after the `row` instruction is an optional definition for columns width. This example uses 12-column Twitter Bootstrap grid, so "5, 2, 5" corresponds to "41.5%, 17%, 41.5%" relatively to the total page width.

Usage
-----

[](#usage)

### In your PHP project

[](#in-your-php-project)

To parse your markdown you need only two lines of code. The first one is to choose the markdown flavor as one of the following:

- Original Markdown: `$parser = new \cebe\markdown\Markdown();`
- Github Flavored Markdown: `$parser = new \cebe\markdown\GithubMarkdown();`
- Markdown Extra: `$parser = new \cebe\markdown\MarkdownExtra();`

The next step is to call the `parse()`-method for parsing the text using the full markdown language or calling the `parseParagraph()`-method to parse only inline elements.

Here are some examples:

```
// original markdown and parse full text
$parser = new \cebe\markdown\Markdown();
$parser->parse($markdown);

// use github markdown
$parser = new \cebe\markdown\GithubMarkdown();
$parser->parse($markdown);

// use markdown extra
$parser = new \cebe\markdown\MarkdownExtra();
$parser->parse($markdown);

// use markdown extra with bootstrap-grid
$parser = new \cebe\markdown\BootstrapMarkdown();
$parser->parse($markdown);

// parse only inline elements (useful for one-line descriptions)
$parser = new \cebe\markdown\GithubMarkdown();
$parser->parseParagraph($markdown);
```

You may optionally set one of the following options on the parser object:

For all Markdown Flavors:

- `$parser->html5 = true` to enable HTML5 output instead of HTML4.
- `$parser->keepListStartNumber = true` to enable keeping the numbers of ordered lists as specified in the markdown. The default behavior is to always start from 1 and increment by one regardless of the number in markdown.

For GithubMarkdown:

- `$parser->enableNewlines = true` to convert all newlines to ``-tags. By default only newlines with two preceding spaces are converted to ``-tags.

### The command line script

[](#the-command-line-script)

You can use it to render this readme:

```
bin/markdown README.md > README.html

```

Using github flavored markdown:

```
bin/markdown --flavor=gfm README.md > README.html

```

or convert the original markdown description to html using the unix pipe:

```
curl http://daringfireball.net/projects/markdown/syntax.text | bin/markdown > md.html

```

Here is the full Help output you will see when running `bin/markdown --help`:

```
PHP Markdown to HTML converter
------------------------------

by Carsten Brandt

Usage:
    bin/markdown [--flavor=] [file.md]

    --flavor  specifies the markdown flavor to use. If omitted the original markdown by John Gruber [1] will be used.
              Available flavors:

              gfm   - Github flavored markdown [2]
              extra - Markdown Extra [3]

    --help    shows this usage information.

    If no file is specified input will be read from STDIN.

Examples:

    Render a file with original markdown:

        bin/markdown README.md > README.html

    Render a file using gihtub flavored markdown:

        bin/markdown --flavor=gfm README.md > README.html

    Convert the original markdown description to html using STDIN:

        curl http://daringfireball.net/projects/markdown/syntax.text | bin/markdown > md.html

[1] http://daringfireball.net/projects/markdown/syntax
[2] https://help.github.com/articles/github-flavored-markdown
[3] http://michelf.ca/projects/php-markdown/extra/

```

Extending the language
----------------------

[](#extending-the-language)

Markdown consists of two types of language elements, I'll call them block and inline elements simlar to what you have in HTML with `` and ``. Block elements are normally spreads over several lines and are separated by blank lines. The most basic block element is a paragraph (``). Inline elements are elements that are added inside of block elements i.e. inside of text.

This markdown parser allows you to extend the markdown language by changing existing elements behavior and also adding new block and inline elements. You do this by extending from the parser class and adding/overriding class methods and properties. For the different element types there are different ways to extend them as you will see in the following sections.

### Adding block elements

[](#adding-block-elements)

The markdown is parsed line by line to identify each non-empty line as one of the block element types. This job is performed by the `indentifyLine()` method which takes the array of lines and the number of the current line to identify as an argument. This method returns the name of the identified block element which will then be used to parse it. In the following example we will implement support for [fenced code blocks](https://help.github.com/articles/github-flavored-markdown#fenced-code-blocks "Fenced code block feature of github flavored markdown") which are part of the github flavored markdown.

```
