Extension for Parsedown Extra
Configurable Markdown to HTML converter with Parsedown Extra.
- 1. Installation
- 2. Features
- HTML or XHTML
- Predefined Abbreviations
- Predefined Links
- Automatic
rel="nofollow"
Attribute on External Links - Custom Code Class Format
- Custom Code Text Format
- Put
<code>
Attributes on<pre>
Element - Custom Table Class
- Custom Table Alignment Class
- Custom Footnote ID Format
- Custom Footnote Back ID Format
- Custom Footnote Class
- Custom Footnote Link Class
- Custom Footnote Back Link Class
- Custom Footnote Link Text
- Custom Footnote Back Link Text
- Advance Attribute Parser
- Code Block Class Without
language-
Prefix
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}');
$parser->element_suffix = '>'; // HTML5
$parser->abbreviations = array(
'CSS' => 'Cascading Style Sheet',
'HTML' => 'Hyper Text Markup Language',
'JS' => 'JavaScript'
);
$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'
)
);
// 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();
$parser->code_class = 'language-%s';
$parser->code_class = function($text) {
return trim(str_replace('.', ' ', $text));
};
$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);
};
$parser->code_block_attr_on_parent = true;
$parser->table_class = 'table-bordered';
$parser->table_align_class = 'text-%s';
$parser->footnote_link_id = 'cite_note:%s';
$parser->footnote_back_link_id = 'cite_ref:%s-%s';
$parser->footnote_class = 'footnotes';
$parser->footnote_link_class = 'footnote-ref';
$parser->footnote_back_link_class = 'footnote-backref';
$parser->footnote_link_text = '[%s]';
$parser->footnote_link_text = function($text) {
return '[' . $text . ']';
};
$parser->footnote_back_link_text = '<i class="icon icon-back"></i>';
{#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">
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">