Markdown扩展语法支持

sculpin使用michelf/php-markdown进行解析markdown语法,php-markdown支持基本语法扩展语法,本文列举扩展语法使用。

扩展语法

Inline Html 内嵌HTML

在Markdown Extra中,嵌入HTML tag,可以在任何markdown语句中嵌入HTML Tag, 这在一些markdown很难实现但是html异常容易的场景下,非常有意义。

但是对对于p、div、table、pre等等块级标签,由于markdown的语法标准中,有如下限制:

Block-level HTML elements ” e.g. div, table, pre, p, etc. ” must be separated from surrounding content by blank lines, and the start and end tags of the block should not be indented with tabs or spaces.
HTML块元素比如div、table、pre、p、等等,必须由空行隔开,并且起始标签不能由tab或者空格缩进。

在Markdown Extra扩展语法支持下,上面这个限制被简化了为两个限制:

比如下面item使用了这个语法

这是p tag

这是个div块

HTML代码内嵌入MD支持

HTML块内MD语法支持。MD语法中,块元素内是无法使用MD的。比如说书写一个DIV中,是无法使用MD语法的。 但是中扩展语法中,DIV中是可以支持MD的。 只需要给块元素增加一个 markdown='1'就可以。



<div markdown='1' >; some text </div>

的属性,即可:

some text

指定属性

可以为任意元素设置属性,比如为Head设置id 、class等等属性。方法是直接在元素后面跟个空格然后用花括号把属性围起来。比如说: { #id} 或者 {.class_name},或者{ lang=fr }等等属性 对于链接来说id相当于是锚点,然后在link中使用(#name)指向这个锚点。

    Header 1    { #id }
    ## Header 2 ##      {.class}
    [Link back to header 1](#header1)
    ## Le Site ##    {lang=fr}
    ## Le Site ##    {.main .shine #the-site lang=fr}

还可以为一下几个块元素指定属性

  1. headers
  2. 围圈代码块
  3. Link
  4. 图片
[link](url){.class  #id}  
![img](url){.class  #id}

[linkref]: url "optional title" {.class #id}

请留意: 此处合用了 Jquery的magnific popup插件与 扩展语法 的技能,能够为指定内容设置高亮显示,只需要设置 { .hl }属性,既可。

代码块圈围

把代码,用首尾两行超过三个的~或者`把代码圈围起来。首末行可以加空行

~~~
这是~代码
~~~
   这是~代码
```
这是`代码
```
这是`代码
  1. List item

    Not an indented code block, but a second paragraph in the list item

普通代码块, 无高亮
<p>paragraph <b>emphasis</b>
增加.hl。 高亮代码块
<p>paragraph <b>emphasis</b>
增加.hl。 高亮代码块

切换MD转换器

表格

First Header  | Second Header
------------- | -------------
Content Cell  | Content Cell
Content Cell  | Content Cell

产生如下表格

<table>
<thead>
<tr>
  <th>First Header</th>
  <th>Second Header</th>
</tr>
</thead>
<tbody>
<tr>
  <td>Content Cell</td>
  <td>Content Cell</td>
</tr>
<tr>
  <td>Content Cell</td>
  <td>Content Cell</td>
</tr>
</tbody>
</table>

Defination List

Apple
Pomaceous fruit of plants of the genus Malus in the family Rosaceae.

脚注

脚注内容方括号加


本行有个脚注.[^1] [^1]: 这是脚注内容

缩写

先定义缩写

*[HTML]: Hyper Text Markup Language
*[W3C]:  World Wide Web Consortium

然后在需要使用缩写的地方直接使用。

The HTML specification
is maintained by the W3C.

The HTML specification is maintained by the W3C.

有序列表/序表

只要使用数字引导,就可以,不需要连续,语法引擎会自动处理。

1. 1st line
1. 2st line
1. 3nd line
3. 4th line

<ol>
<li>1st line</li>
<li>2st line</li>
<li>3nd line</li>
<li>4th line</li>
</ol>

重点

一个或者两个星号*、下划线_。 会作为着重符号对待。 单个转成<em> tag, 两个转成<strong> tag。 如果词间下划线,在扩展语法中,不会作为着重符号对待,依旧保留原义。

反斜线转义

除了反斜线,扩展语法支持 冒号:和管道号|来做转义 基础语法中用

\*literal asterisks\*
:*literal asterisks\*
|*literal asterisks\*
  1. *literal asterisks*
  2. *literal asterisks*
  3. *literal asterisks*