Configurable Markdown to HTML converter with Parsedown Extra Plugin.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
test
LICENSE
ParsedownExtraPlugin.php
README.md
composer.json
test.php

README.md

Extension for Parsedown Extra

Configurable Markdown to HTML converter with Parsedown Extra.

Table of content:

Installation

Include ParsedownExtraPlugin.php just after the Parsedown.php and ParsedownExtra.php:

require 'Parsedown.php';
require 'ParsedownExtra.php';
require 'ParsedownExtraPlugin.php';

$parser = new ParsedownExtraPlugin();

// settings ...
$parser->code_class = 'lang-%s';

echo $parser->text('# Header {.sth}');

Features

HTML or XHTML

$parser->element_suffix = '>'; // HTML5

Predefined Abbreviations

$parser->abbreviations = array(
    'CSS' => 'Cascading Style Sheet',
    'HTML' => 'Hyper Text Markup Language',
    'JS' => 'JavaScript'
);

Predefined Links

$parser->links = array(
    'mecha-cms' => array(
        'url' => 'http://mecha-cms.com',
        'title' => 'Mecha CMS'
    ),
    'test-image' => array(
        'url' => 'http://example.com/favicon.ico',
        'title' => 'Test Image'
    )
);

Automatic rel="nofollow" Attribute on External Links

// custom link attributes
$parser->links_attr = array();

// custom external link attributes
$parser->links_external_attr = array(
    'rel' => 'nofollow',
    'target' => '_blank'
);

// custom image attributes
$parser->images_attr = array(
    'alt' => ""
);

// custom external image attributes
$parser->images_external_attr = array();

Custom Code Class Format

$parser->code_class = 'language-%s';
$parser->code_class = function($text) {
    return trim(str_replace('.', ' ', $text));
};

Custom Code Text Format

$parser->code_text = '<span class="my-code">%s</span>';
$parser->code_block_text = '<span class="my-code-block">%s</span>';
$parser->code_text = function($text) {
    return do_syntax_highlighter($text);
};

$parser->code_block_text = function($text) {
    return do_syntax_highlighter($text);
};

Put <code> Attributes on <pre> Element

$parser->code_block_attr_on_parent = true;

Custom Table Class

$parser->table_class = 'table-bordered';

Custom Table Alignment Class

$parser->table_align_class = 'text-%s';

Custom Footnote ID Format

$parser->footnote_link_id = 'cite_note:%s';

Custom Footnote Back ID Format

$parser->footnote_back_link_id = 'cite_ref:%s-%s';

Custom Footnote Class

$parser->footnote_class = 'footnotes';

Custom Footnote Link Class

$parser->footnote_link_class = 'footnote-ref';

Custom Footnote Back Link Class

$parser->footnote_back_link_class = 'footnote-backref';

Custom Footnote Link Text

$parser->footnote_link_text = '[%s]';
$parser->footnote_link_text = function($text) {
    return '[' . $text . ']';
};

Custom Footnote Back Link Text

$parser->footnote_back_link_text = '<i class="icon icon-back"></i>';

Advance Attribute Parser

  • {#foo}<tag id="foo">
  • {#foo#bar}<tag id="bar">
  • {.foo}<tag class="foo">
  • {.foo.bar}<tag class="foo bar">
  • {#foo.bar.baz}<tag id="foo" class="bar baz">
  • {#foo .bar .baz}<tag id="foo" class="bar baz"> (white-space before # and . becomes optional in my extension)
  • {foo="bar"}<tag foo="bar">
  • {foo="bar baz"}<tag foo="bar baz">
  • {foo='bar'}<tag foo="bar">
  • {foo='bar baz'}<tag foo="bar baz">
  • {foo=bar}<tag foo="bar">
  • {foo=}<tag foo="">
  • {foo}<tag foo="foo">
  • {foo=bar baz}<tag foo="bar" baz="baz">
  • {#a#b.c.d e="f" g="h i" j='k' l='m n' o=p q= r s t="u#v.w.x y=z"}<tag id="b" class="c d" e="f" g="h i" j="k" l="m n" o="p" q="" r="r" s="s" t="u#v.w.x y=z">

Code Block Class Without language- Prefix

Dot prefix in class name are now becomes optional, custom attributes syntax also acceptable:

  • php<pre><code class="language-php">
  • php html<pre><code class="language-php language-html">
  • .php<pre><code class="php">
  • .php.html<pre><code class="php html">
  • .php html<pre><code class="php language-html">
  • {.php #foo}<pre><code id="foo" class="php">