kramdown是markdown的超集,在Jekyll中支持, 可以用于Github搭建博客. 和Jekyll一样, 使用Ruby作为核心语言. 由于Maruku不再更新, Github推荐使用kramdown作为markdown解析. kramdown作为markdown解析器号称速度快, 比PHP markdown和Maruku都要快几倍.

kramdown有很多一般markdown所没有的语法特点, 包括和GFM也有差异.另外也可以很方便地作为文件转换使用. 这里只讨论其markdown重要特色, 不考察其作为解析器的用法.

1.header ID:就是实现html的锚anchor的功能.

例如回到header ID. ## Header {#ID}. 对于setext style(标题名,下行===或—)或atx style(就是常用的#标题模式),效果如下:

Header1

Header2
Header3

GoH1, GoH2, GoH3

2.Footnote脚注

就是链接到footnote html元素的超链接,形式像参考文献一样. [^text]是其形式, text可以是数字或字符串, 但统一显示是1,2,3…(有序列表形式尾注). 尾注内容部分可以是任意元素内容,出现在文章任意地方. 像参考文献一样, 一个显示上标形式标记[^text]定义, 一个使用具体内容解释,使用[^text]: content定义(注意空格或者换行缩进). 如果没有对应就不会显示.

This is some text.1. Other text.2. Not exist: [^noexist]。尾注会显示在文章的最下方

3.Abbreviations 缩略语

就是html的abbr. 鼠标移到相关词上面会出现词义解析. 在文档任意位置 *[word]: explanation 即可.如下:

Move to HTML please.

4.Inline Attribute Lists (IAL) 行内属性标记

IAL就是允许对block元素甚至span元素增加HTML的属性,例如class, name, id, 颜色等.用法简单,在block/span元素后跟{:property=value}即可, 对于id可以直接{: #id},对于class直接{: .classname}. 甚至像css一样先定义一个简称{:shortcut: p1=v1 p2=v2}. 多个相同属性时或者合并(如class),或者覆盖(一般属性,后者覆盖前者.)

对于block元素,这种IAL属性修饰可以在其前,也可以在其后, 可以有多个, 甚至有空格, 直到空行为止.对于span级元素,则必须紧跟其后(同行)并且不能有空格,支持多个IAL紧跟.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
    paragraph1
    {: .c1 #idp1 .c2 title="title"}

    {:refdef: .c1 #idp2 .c2 title="title"}
    paragraph2
    {: refdef}

    This *is*{:.underline} some `code`{:#id}{:.class}.
    A [link](test.html){:rel='something'} and some **tools**{:.tools}.

    This is a Ruby code fragment `x = Class.new`{:.language-ruby}

    HTML code as:

    <p class="c1 c2" id="idp1" title="title">paragraph1</p>

    <p class="c1 c2" id="idp2" title="title">paragraph2</p>

    <p>This <em class="underline">is</em> some <code id="id" class="class">code</code>.
    A <a href="test.html" rel="something">link</a> and some <strong class="tools">tools</strong>.</p>

5.表格

表格在很多Markdown扩展中均有, 包括GFM. 使用|分隔每列, 第一和最后一个|可以省略. 支持对齐(header分隔时|--:|冒号位置), 支持多tbody(再次出现|----|, 中间分隔列可以用+,为了好看)支持尾注(====).

|-----------------+------------+-----------------+----------------|
| Default aligned |Left aligned| Center aligned  | Right aligned  |
|-----------------|:-----------|:---------------:|---------------:|
| First body part |Second cell | Third cell      | fourth cell    |
| Second line     |foo         | **strong**      | baz            |
| Third line      |quux        | baz             | bar            |
|-----------------+------------+-----------------+----------------|
| Second body     |            |                 |                |
| 2 line          |            |                 |                |
|=================+============+=================+================|
| Footer row      |            |                 |                |
|-----------------+------------+-----------------+----------------|

效果如下:

Default aligned Left aligned Center aligned Right aligned
First body part Second cell Third cell fourth cell
Second line foo strong baz
Third line quux baz bar
Second body      
2 line      
Footer row      

6.代码高亮

带行号:

1
2
3
4
5
6
7
8
9
10
    var o = {
        a:10,
        b:{
            // a:12,
            fn:function(){
                console.log(this.a); //undefined
            }
        }
    }
    o.b.fn();

不带行号:

    //载入核心文件
    require(SITE_PATH.'/core/core.php');

    //实例化一个网站应用实例
    $App = new App();
    $App->run();




参考

  1. Some crazy footnote definition. 

  2. Blockquotes can be in a footnote.

    as well as code blocks
    

    or, naturally, simple paragraphs