All Projects → taufik-nurrohman → Parsedown Extra Plugin

taufik-nurrohman / Parsedown Extra Plugin

Licence: mit
Configurable Markdown to HTML converter with Parsedown Extra Plugin.

Projects that are alternatives of or similar to Parsedown Extra Plugin

Vue Styleguidist
Created from react styleguidist for Vue Components with a living style guide
Stars: ✭ 2,133 (+4438.3%)
Mutual labels:  markdown, parser
Craftinginterpreters
Repository for the book "Crafting Interpreters"
Stars: ✭ 4,298 (+9044.68%)
Mutual labels:  markdown, parser
Diagon
Interactive ASCII art diagram generators. 🌟
Stars: ✭ 189 (+302.13%)
Mutual labels:  markdown, parser
Md
A markdown parser and compiler. Built for speed.
Stars: ✭ 128 (+172.34%)
Mutual labels:  markdown, parser
Ngx Markdown
Angular markdown component/directive/pipe/service to parse static, dynamic or remote content to HTML with syntax highlight
Stars: ✭ 687 (+1361.7%)
Mutual labels:  markdown, parser
Snarkdown
😼 A snarky 1kb Markdown parser written in JavaScript
Stars: ✭ 1,813 (+3757.45%)
Mutual labels:  markdown, parser
Termimad
A library to display rich (Markdown) snippets and texts in a rust terminal application
Stars: ✭ 293 (+523.4%)
Mutual labels:  markdown, parser
React Native Markdown Package
React native markdown package is a Library for implementing markdown syntax in React Native
Stars: ✭ 50 (+6.38%)
Mutual labels:  markdown, parser
Remarkable
Markdown parser, done right. Commonmark support, extensions, syntax plugins, high speed - all in one. Gulp and metalsmith plugins available. Used by Facebook, Docusaurus and many others! Use https://github.com/breakdance/breakdance for HTML-to-markdown conversion. Use https://github.com/jonschlinkert/markdown-toc to generate a table of contents.
Stars: ✭ 5,252 (+11074.47%)
Mutual labels:  markdown, parser
React Markdown Editor Lite
a light-weight Markdown editor based on React. 一款轻量的基于React的markdown编辑器
Stars: ✭ 553 (+1076.6%)
Mutual labels:  markdown, parser
Commonmark Java
Java library for parsing and rendering CommonMark (Markdown)
Stars: ✭ 1,675 (+3463.83%)
Mutual labels:  markdown, parser
Markdown Wasm
Markdown parser and HTML generator implemented in WebAssembly, based on md4c
Stars: ✭ 833 (+1672.34%)
Mutual labels:  markdown, parser
Elm Markdown
Pure Elm markdown parsing and rendering
Stars: ✭ 96 (+104.26%)
Mutual labels:  markdown, parser
Ink
A fast and flexible Markdown parser written in Swift.
Stars: ✭ 2,049 (+4259.57%)
Mutual labels:  markdown, parser
Marko
A markdown parser with high extensibility.
Stars: ✭ 77 (+63.83%)
Mutual labels:  markdown, parser
Parsedown
Better Markdown Parser in PHP
Stars: ✭ 13,959 (+29600%)
Mutual labels:  markdown, parser
Md4c
C Markdown parser. Fast. SAX-like interface. Compliant to CommonMark specification.
Stars: ✭ 322 (+585.11%)
Mutual labels:  markdown, parser
Marked
A markdown parser and compiler. Built for speed.
Stars: ✭ 26,556 (+56402.13%)
Mutual labels:  markdown, parser
Mdx linkify
Link recognition for Python Markdown
Stars: ✭ 18 (-61.7%)
Mutual labels:  markdown, extension
Markdown.avalonia
render markdown with Avalonia UI
Stars: ✭ 45 (-4.26%)
Mutual labels:  markdown

Extension for Parsedown Extra

Configurable Markdown to HTML converter with Parsedown Extra.

Parsedown Logo

Contents

Usage

Manual

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

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

# Create
$Parsedown = new ParsedownExtraPlugin;

# Configure
$Parsedown->voidElementSuffix = '>'; // HTML5

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

Composer

From the file manager interface, create a composer.json file in your project folder, then add this content:

{
  "minimum-stability": "dev"
}

From the command line interface, navigate to your project folder then run this command:

composer require taufik-nurrohman/parsedown-extra-plugin

From the file manager interface, create an index.php file in your project folder then require the auto-loader file:

require 'vendor/autoload.php';

# Create
$Parsedown = new ParsedownExtraPlugin;

# Configure
$Parsedown->voidElementSuffix = '>'; // HTML5

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

Features

HTML or XHTML

$Parsedown->voidElementSuffix = '>'; // HTML5

Predefined Abbreviations

$Parsedown->abbreviationData = [
    'CSS' => 'Cascading Style Sheet',
    'HTML' => 'Hyper Text Markup Language',
    'JS' => 'JavaScript'
];

Predefined Reference Links and Images

$Parsedown->referenceData = [
    'mecha-cms' => [
        'url' => 'https://mecha-cms.com',
        'title' => 'Mecha CMS'
    ],
    'test-image' => [
        'url' => 'http://example.com/favicon.ico',
        'title' => 'Test Image'
    ]
);

Automatic rel="nofollow" Attribute on External Links

$Parsedown->linkAttributes = function($Text, $Attributes, &$Element, $Internal) {
    if (!$Internal) {
        return [
            'rel' => 'nofollow',
            'target' => '_blank';
        ];
    }
    return [];
};

Automatic id Attribute on Headers

$Parsedown->headerAttributes = function($Text, $Attributes, &$Element, $Level) {
    $Id = $Attributes['id'] ?? trim(preg_replace('/[^a-z\d\x{4e00}-\x{9fa5}]+/u', '-', strtolower($Text)), '-');
    return ['id' => $Id];
};

Automatic Figure Elements

Every image markup that appears alone in a paragraph will be converted into a figure element automatically.

$Parsedown->figuresEnabled = true;
$Parsedown->figureAttributes = ['class' => 'image'];

$Parsedown->imageAttributesOnParent = ['class', 'id'];

To add a caption below the image, prepend at least one space but less than four spaces to turn the paragraph sequence that comes after the image into an image caption.

This is a paragraph.

![Image](/path/to/image.jpg)
 Image caption.

This is a paragraph.

![Image](/path/to/image.jpg)

 Image caption in a paragraph tag.

This is a paragraph.

![Image](/path/to/image.jpg)

    This is a code block.

This is a paragraph.

FYI, this format is also valid for average Markdown files. And so, it will degraded gracefully when parsed by other Markdown converters.

Custom Code Block Class Format

$Parsedown->blockCodeClassFormat = 'language-%s';

Custom Code Block Contents

$Parsedown->codeHtml = '<span class="my-code">%s</span>';
$Parsedown->blockCodeHtml = '<span class="my-code-block">%s</span>';
// <https://github.com/scrivo/highlight.php>
function doApplyHighlighter(string $Text, array $ClassList, &$Element) {
    $Highlight = new \Highlight\Highlighter;
    $Highlight->setAutodetectLanguages($ClassList);
    $Highlighted = $Highlight->highlightAuto($Text);
    $Element['attributes']['class'] = 'hljs ' . $Highlighted->language;
    return $Highlighted->value;
}

$Parsedown->codeHtml = function($Text, $Attributes, &$Element) {
    return doApplyHighlighter($Text, [], $Element);
};

$Parsedown->blockCodeHtml = function($Text, $Attributes, &$Element) {
    $ClassList = array_filter(explode(' ', $Attributes['class'] ?? ""));
    return doApplyHighlighter($Text, $ClassList, $Element);
};

Put <code> Attributes on <pre> Element

$Parsedown->codeAttributesOnParent = true;

Custom Quote Block Class

$Parsedown->blockQuoteAttributes = ['class' => 'quote'];
$Parsedown->blockQuoteAttributes = function($Text, $Attributes, &$Element) {
    if (strpos($Text, '**Danger:** ') === 0) {
        return ['class' => 'alert alert-danger'];
    }
    if (strpos($Text, '**Info:** ') === 0) {
        return ['class' => 'alert alert-info'];
    }
    return [];
};

Custom Table Attributes

$Parsedown->tableAttributes = ['border' => 1];

Custom Table Alignment Class

$Parsedown->tableColumnAttributes = function($Text, $Attributes, &$Element, $Align) {
    return [
        'class' => $Align ? 'text-' . $Align : null,
        'style' => null // Remove inline styles
    ];
};

Custom Footnote ID Format

$Parsedown->footnoteLinkAttributes = function($Number, $Attributes, &$Element, $Name) {
    return ['href' => '#to:' . $Name];
};

$Parsedown->footnoteReferenceAttributes = function($Number, $Attributes, &$Element, $Name, $Index) {
    return ['id' => 'from:' . $Name . '.' . $Index];
};

$Parsedown->footnoteBackLinkAttributes = function($Number, $Attributes, &$Element, $Name, $Index) {
    return ['href' => '#from:' . $Name . '.' . $Index];
};

$Parsedown->footnoteBackReferenceAttributes = function($Number, $Attributes, &$Element, $Name, $Total) {
    return ['id' => 'to:' . $Name];
};

Custom Footnote Class

$Parsedown->footnoteAttributes = ['class' => 'notes'];

Custom Footnote Link Text

$Parsedown->footnoteLinkHtml = '[%s]';

Custom Footnote Back Link Text

$Parsedown->footnoteBackLinkHtml = '<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 class="php" id="foo">

Property Aliases as Methods

Property aliases are available as methods just to follow the way Parsedown set its configuration data. It uses PHP __call method to generate the class methods automatically:

// This is ...
$Parsedown->setBlockCodeHtml(function() { ... });

// ... equal to this
$Parsedown->blockCodeHtml = function() { ... };
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].