izadori/parsedown-plus

An Extension for Parsedown/ParsedownExtra

v1.0.2 2021-11-27 23:17 UTC

This package is auto-updated.

Last update: 2024-03-28 04:31:15 UTC


README

An Extension for Parsedown/ParsedownExtra.

Features

  1. Auto-generation of table of contents
    1. By specifying the table of contents tag in the text, ParsedownPlus inserts an automatically generated table of contents.
  2. Support for mathematical expressions in LaTeX format
    1. ParsedownPlus recognize $ ... $ or $$ ... $$ as LaTeX-like formulas and do not parse in Markdown text.
    2. $ ... $ is inline and $$ ... $$ is block.
  3. Recognize file name in fenced code
    1. ParsedownPlus recognize ```lang:file ... ``` and set filename in data-filename attribute of <code> tag.

Usage

With composer

When using composer, you move to your project folder and type following command.

composer require izadori/parsedown-plus

Parsedown will be also installed when it is not found. If you use ParsedownExtra, you may install it manually.

composer require erusev/parsedown-extra

You have to require autoload.php to use ParsedownPlus in your project.

require_once __DIR__ . "/vender/autoload.php";

use \Izadori\ParsedownPlus\ParsedownPlus;

$parser = new ParsedownPlus();

$text = <<<EOF
# Equation of _Circle_

$ x_{1}^{2} + x_{2}^{2} = 1 $
EOF;

$line = "It's **inline** text!";

// parses Markdown text
echo $parser->text($text); // prints: <h1>Equation of <em>Circle</em></h1> <p>$  x_{1}^{2} + x_{2}^{2} = 1  $</p>
// parses inline text
echo $parser->line($line); // prints: It's <strong>inline</strong> text!

Without composer

When not using composer, you download ParsedownPlus in your project here.

To use ParsedownPlus, you require Parsedown.php. And you require ParsedownExtra.php if you need. Then, you require ParsedownPlus.php;

require_once __DIR__ . "/Parsedown.php";
require_once __DIR__ . "/ParsedownExtra.php"; // if you need
require_once __DIR__ . "/ParsedownPlus.php";

use /Izadori;

$parser = new ParsedownPlus();

$text = <<<EOF
# Equation of _Circle_

$ x_{1}^{2} + x_{2}^{2} = 1 $
EOF;

$line = "It's **inline** text!";

// parses Markdown text
echo $parser->text($text); // prints: <h1>Equation of <em>Circle</em></h1> <p>$  x_{1}^{2} + x_{2}^{2} = 1  $</p>
// parses inline text
echo $parser->line($line); // prints: It's <strong>inline</strong> text!

Options

ParsedownPlus has some public variables as its options.

variable description
$langPrefix A prefix added class name of language in fenced code.
The default value is language- for prism.js.
$tocTag A associative array with two members, 'begin' and 'end'.
Give the start and end numbers of the heading tags recognizing as table of contents.
$tocIdentTag Specifies a pseudo-tag for inserting a table of contents in the Markdown text as an array of strings.
$tocFormat Specify the format to include the generated table of contents^1.
%s is given as placeholder of the table of contents. ParsedownPlus uses sprintf() function.

About automatically generating table of contentes

The table of contents generated by ParsedownPlus is an ordered-list like the following.

<ol>
  <li>Heading 1</li>
  <li>Heading 2</li>
    <ol>
      <li>Heading 2.1</li>
      <li>Heading 2.2</li>
    </ol>
  <li>Heading 3</li>
</ol>

About bugs and reports

If you find a bug, please send an issue on the Github with the nature of the bug and the Markdown text in which it occurred.

About license

ParsedownPlus is complies with the MIT license. Please refer to the LICENSE file for details.

About author

History

ParsedownPlus.php

  1. 2021.09.02 [ver.1.0.0]
    • Publish on Github
  2. 2021.09.02 [ver.1.0.1]
    • Fixed a bug that prevented ParsedownExtra from working properly.
    • Added the function of using prefix of the class of language name in the fenced code.
  3. 2021.11.28 [ver.1.0.2]
    • Modified to add class="block-math" to <p> tags output in block math formulas.

This document

  1. 2021.09.02
    • Added description to match ParsedownPlus ver.1.0.1.
    • Publish on Github
  2. 2021.09.06
    • Modify sample code.