laravelfy / parsedown-extra-plugin
带有 Parsedown Extra 的可配置 Markdown 到 HTML 转换器。
v0.01
2018-12-25 07:29 UTC
Requires
- erusev/parsedown-extra: ~0.7
This package is auto-updated.
Last update: 2024-09-25 20:05:44 UTC
README
带有 Parsedown Extra 的可配置 Markdown 到 HTML 转换器。
目录
安装
在 Parsedown.php
和 ParsedownExtra.php
之后包含 ParsedownExtraPlugin.php
require 'Parsedown.php'; require 'ParsedownExtra.php'; require 'ParsedownExtraPlugin.php'; $parser = new ParsedownExtraPlugin(); // settings ... $parser->code_class = 'lang-%s'; echo $parser->text('# Header {.sth}');
特性
HTML 或 XHTML
$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' ) );
外部链接自动添加 rel="nofollow"
属性
// 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); };
将 <code>
属性应用于 <pre>
元素
$parser->code_block_attr_on_parent = true;
自定义表格类
$parser->table_class = 'table-bordered';
自定义表格对齐类
$parser->table_align_class = 'text-%s';
自定义脚注 ID 格式
$parser->footnote_link_id = 'cite_note:%s';
自定义脚注回指 ID 格式
$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">
(在我的扩展中,#
和.
前的白空字符现在是可选的){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">
不带 language-
前缀的代码块类
类名中的点前缀现在是可选的,也接受自定义属性语法
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">