Coding Poet, Coding Science

博客文章功能指南

描述文章内容的格式与需求

适应各种展示场合的标记语言

建立主页可以使用基于静态主页的方案或者基于动态主页的方案。动态主页虽然提供的内容类型较为丰富,但是托管方式比较复杂,创作代价比较高,受运行时环境的影响较大,难以同时适应网页、打印等不同场景的需求。我们需要一种

  1. 内容与格式相分离的描述,以允许我们写作时仅需要关注标记内容。这种描述语言要具有强大的表现力,以适应丰富的表现需求(高亮、文本块、编号、代码高亮、表格、抄录、引用、参考文献等);同时又要足够简洁,尽可能自动地计算出渲染需求。
  2. 这种格式能够向HTML网页、LaTeX、PDF、Word以及维基等多种格式转换。在转换的时候需要人工处理的内容要尽量少。因为我们希望复用博客里面的文章到不同场合(不同网站、不同目的、不同输出)的时候尽可能不需要改动

然而,这诸多需求之间存在显著的矛盾。在这些矛盾的折衷中,我们看到基于Pandoc的Markdown标记相对而言最接近于我们理想的情况。这是因为:

  1. 现在已有许多Markdown渲染器作为渲染内容的后端程序。许多人员在根据需求不断地改进Markdown;
  2. 虽然Markdown方言很多。但是Pandoc博采众家之长,兼容多种Markdown格式,同时还可以在自家的Markdown和其它Markdown格式之间互转;
  3. 采用Pandoc标准的Markdown格式,可以向HTML、PDF、演示文稿、Word地格式转换。在转换过程中,基本元素(标题、文字加粗倾斜、列表、图片等)均可以展示出来;在表格、插图、参考文献当中也有部分的支持;
  4. 可以使用过滤器手动改进Pandoc元素的渲染方式。

具有最好展示效果的标记语言

LaTeX目前是已知的一种在表现内容方面质量最高的文本标记形式。除了LaTeX本身在设计理念上的优势,丰富的宏包支持以及庞大用户群的持续贡献也是选择LaTeX的重要的因素。然而,LaTeX语法比较复杂,要生成PDF之外的其它格式,同时保持排版效果是比较困难的。在LaTeX世界当中可以找到处理浮动体、编号、文本块高亮以及图表处理的许多有价值的方案。比如

  1. 通过LaTeX的subfigwrapfigurecaption等宏包提供的环境与命令可以方便地调整图表的组合、编号以及出现位置。
  2. 通过LaTeX的longtabletabularxtabu等宏包提供的环境可以指定表格的宽度、对齐、高亮样式等。Markdown对表格的支持没有LaTeX那样方便。
  3. LaTeX可以通过amssymbeulervm等宏包使用更多的数学符号,还可以自定义数学符号与排版还境,比如范畴论中用到的交换图。这些命令可以在LaTeX文档的导言区中进行配置。
  4. LaTeX有算法宏包algorithmicx、语法高亮宏包listingsminted、化学公式宏包chemfig、UML类图宏包umlcd、乐谱排版宏包abclilypondmusixtex等,可以支持领域特定元素的展示。
  5. 总而言之,LaTeX在做到格式与内容分离的同时,还保持了强大的定制格式的能力。

最能满足实际需求的标记语言

假设现在我们需要写一篇论文,并且还想把论文内容发布到Internet上。抛开在论文背后的实验数据处理等问题,在完成论文的过程中常见的需求有:

  1. 能自动化的东西应该尽量自动化完成。比如引用、编号、参考文献生成;
  2. 论文可能是多个人完成的。这时需要配合Git的版本管理工具,以及diff等修改查看工具,看看每版到底改了些什么东西。并且每个人的计算机环境也不一样,为了更有效地协作,要尽可能使用文本,在标记语言中,将二进制格式以引用的形式展示;
  3. 在论文写作过程中,题目、人员、需要投稿的期刊等都是可能发生变化的。对研究生而言,这些要素往往不是自己能够决定的。所以,为了更好地适应来自导师等方面的变化,也需要把这些因素隔离开。当提出“把本学院的xx添上去”,“把xx的机构与通迅地址改成xx”,“把ACM SIG的论文格式改成IEEE Computer的论文格式”这样的需求的时候,我们能够修改尽可能少的内容,重新编译文章就可以满足新的需求;在课题组里有时还有内部统一的封面和格式;
  4. 有些人习惯看电子版,有些人则偏爱打印的版本;有些人喜爱宽松的行间间距,有些人仍觉得浪费是极大的犯罪。像我,还认为,使用B5纸张或者16K的介质会增加我的耐心。再比如,校对的时候,可能需要每页外侧保持较大的间距。这时也需要我们简单修改一个字段再重新编译,就可以生成不同的版本了;“指定纸张大小”,“指定一个文类”,“为最终版本生成切角效果”这样的任务简单化,可以让作者只关心内容,会节省更多的工作量;
  5. 在调整与适应不同外观的时候,还需要添加其它的内容。比如论文中我们可能用到amsmath或者amssymb等宏包,而有时候模板并未提供这些。这个时候,我们需要主动往新格式当中添加对这些宏包的使用;
  6. 图片和表格往往是最难对付的环节。除了它们的编号之外,所占的位置往往因为几段文字而需要重新调整。比如表格中添加了几段文字,导致本列过长;图片中添加了一个子图,导致需要重新分布各个子图;图表上面添加了几段,导致图表前后留出了大量空白,我们当然希望可以避免每次手动去处理这些东西。
  7. 有时候论文需要准备多个版本。比如去掉参考文献的版本。这个时候,可能就需要一些开关来控制标记语言中某些部分的展示了。

不过,有些时候导师是非常顽固的。导致我们非得延续导师的习惯不可。这时需要另外的解决办法。

当完成论文之后,为使论文得到更多地传播,需要将论文发布到博客上。此时:

  1. 原来论文的结构细节可以得到更多地展现。包括公式、列表、定义、定理、图表、参考文献、章节引用。计算机编程语言中可能还用到一些代码高亮,或者像规约语言那样的数学环境,以及虽然使用图片展示,但是属于Diagram,它们是使用Graphviz与TikZ一类的代码生成的,这些代码生成的图片,应该同样可以适应于HTML环境。并且有必要的话,还可以添加多媒体效果。
  2. 其实有许多细节方面的问题。比如LaTeX太复杂了,直接将LaTeX源文件换成网页上的展示,那似乎只有网页嵌入PDF这一种选择。如果不使用LaTeX而是使用Pandoc的Markdown,那么在论文当中自定义的命令,需要在Pandoc当中提前声明。而这些声明在生成HTML的时候并不能发挥效果。因此,写论文的时候,就需要考虑尽可能使用Markdown能够识别和转换的元素,避免自定义LaTeX命令或者数学符号。
  3. 论文中的图表渲染对于HTML而言也并不是那么容易。因为要实现LaTeX里面的标题、编号、子图、位置关系这些效果,还不能使用LaTeX(而要使用Markdown);同时还要新增加的Markdown标记能够等价地转换成HTML代码。
  4. 同样地,theorem、definition等环境,以及自定义的代码与绘图环境,要能在生成HTML的过程中得到恰当的处理。

一种涵盖各类元素的标记语言

基于Pandoc的Markdown,设计一种更为理想的标记语言类型

Markdown语法以及增强

原文来自Github/riku-Markdown-Syntax-CN。英文原文见daringfireball的博客。本文根据Riku的文档修改而来。

Pandoc’s Description

Pandoc is a Haskell library for converting from one markup format to another, and a command-line tool that uses this library. It can read Markdown, CommonMark, PHP Markdown Extra, GitHub-Flavored Markdown, MultiMarkdown, and (subsets of) Textile, reStructuredText, HTML, LaTeX, MediaWiki markup, TWiki markup, Haddock markup, OPML, Emacs Org mode, DocBook, txt2tags, EPUB, ODT and Word docx; and it can write plain text, Markdown, CommonMark, PHP Markdown Extra, GitHub-Flavored Markdown, MultiMarkdown, reStructuredText, XHTML, HTML5, LaTeX (including beamer slide shows), ConTeXt, RTF, OPML, DocBook, OpenDocument, ODT, Word docx, GNU Texinfo, MediaWiki markup, DokuWiki markup, ZimWiki markup, Haddock markup, EPUB (v2 or v3), FictionBook2, Textile, groff man pages, Emacs Org mode, AsciiDoc, InDesign ICML, TEI Simple, and Slidy, Slideous, DZSlides, reveal.js or S5 HTML slide shows. It can also produce PDF output on systems where LaTeX, ConTeXt, or wkhtmltopdf is installed.

Pandoc’s enhanced version of Markdown includes syntax for footnotes, tables, flexible ordered lists, definition lists, fenced code blocks, superscripts and subscripts, strikeout, metadata blocks, automatic tables of contents, embedded LaTeX math, citations, and Markdown inside HTML block elements. (These enhancements, described further under Pandoc’s Markdown, can be disabled using the markdown_strict input or output format.)

In contrast to most existing tools for converting Markdown to HTML, which use regex substitutions, pandoc has a modular design: it consists of a set of readers, which parse text in a given format and produce a native representation of the document, and a set of writers, which convert this native representation into a target format. Thus, adding an input or output format requires only adding a reader or writer.

Because pandoc’s intermediate representation of a document is less expressive than many of the formats it converts between, one should not expect perfect conversions between every format and every other. Pandoc attempts to preserve the structural elements of a document, but not formatting details such as margin size. And some document elements, such as complex tables, may not fit into pandoc’s simple document model. While conversions from pandoc’s Markdown to all formats aspire to be perfect, conversions from formats more expressive than pandoc’s Markdown can be expected to be lossy.


Markdown宗旨

Markdown 的目标是实现「易读易写」。

可读性,无论如何,都是最重要的。一份使用 Markdown 格式撰写的文件应该可以直接以纯文本发布,并且看起来不会像是由许多标签或是格式指令所构成。Markdown 语法受到一些既有 text-to-HTML 格式的影响,包括 SetextatxTextilereStructuredTextGrutatextEtText,而最大灵感来源其实是纯文本电子邮件的格式。

总之, Markdown 的语法全由一些符号所组成,这些符号经过精挑细选,其作用一目了然。比如:在文字两旁加上星号,看起来就像*强调*。Markdown 的列表看起来,嗯,就是列表。Markdown 的区块引用看起来就真的像是引用一段文字,就像你曾在电子邮件中见过的那样。

兼容 HTML

Markdown 语法的目标是:成为一种适用于网络的书写语言。

Markdown 不是想要取代 HTML,甚至也没有要和它相近,它的语法种类很少,只对应 HTML 标记的一小部分。Markdown 的构想不是要使得 HTML 文档更容易书写。在我看来, HTML 已经很容易写了。Markdown 的理念是,能让文档更容易读、写和随意改。HTML 是一种发布的格式,Markdown 是一种书写的格式。就这样,Markdown 的格式语法只涵盖纯文本可以涵盖的范围。

不在 Markdown 涵盖范围之内的标签,都可以直接在文档里面用 HTML 撰写。不需要额外标注这是 HTML 或是 Markdown;只要直接加标签就可以了。

要制约的只有一些 HTML 区块元素――比如 <div><table><pre><p> 等标签,必须在前后加上空行与其它内容区隔开,还要求它们的开始标签与结尾标签不能用制表符或空格来缩进。Markdown 的生成器有足够智能,不会在 HTML 区块标签外加上不必要的 <p> 标签。

例子如下,在 Markdown 文件里加上一段 HTML 表格:

这是一个普通段落。

<table>
    <tr>
        <td>Foo</td>
    </tr>
</table>

这是另一个普通段落。

请注意,在 HTML 区块标签间的 Markdown 格式语法将不会被处理。比如,你在 HTML 区块内使用 Markdown 样式的*强调*会没有效果。

HTML 的区段(行内)标签如 <span><cite><del> 可以在 Markdown 的段落、列表或是标题里随意使用。依照个人习惯,甚至可以不用 Markdown 格式,而直接采用 HTML 标签来格式化。举例说明:如果比较喜欢 HTML 的 <a><img> 标签,可以直接使用这些标签,而不用 Markdown 提供的链接或是图像标签语法。

和处在 HTML 区块标签间不同,Markdown 语法在 HTML 区段标签间是有效的。

特殊字符自动转换

在 HTML 文件中,有两个字符需要特殊处理: <&< 符号用于起始标签,& 符号则用于标记 HTML 实体,如果你只是想要显示这些字符的原型,你必须要使用实体的形式,像是 &lt;&amp;

& 字符尤其让网络文档编写者受折磨,如果你要打「AT&T」 ,你必须要写成「AT&amp;T」。而网址中的 & 字符也要转换。比如你要链接到:

http://images.google.com/images?num=30&q=larry+bird

你必须要把网址转换写为:

http://images.google.com/images?num=30&amp;q=larry+bird

才能放到链接标签的 href 属性里。不用说也知道这很容易忽略,这也可能是 HTML 标准检验所检查到的错误中,数量最多的。

Markdown 让你可以自然地书写字符,需要转换的由它来处理好了。如果你使用的 & 字符是 HTML 字符实体的一部分,它会保留原状,否则它会被转换成 &amp;。

所以你如果要在文档中插入一个版权符号 ©,你可以这样写:

&copy;

Markdown 会保留它不动。而若你写:

AT&T

Markdown 就会将它转为:

AT&amp;T

类似的状况也会发生在 < 符号上,因为 Markdown 允许 兼容 HTML ,如果你是把 < 符号作为 HTML 标签的定界符使用,那 Markdown 也不会对它做任何转换,但是如果你写:

4 < 5

Markdown 将会把它转换为:

4 &lt; 5

不过需要注意的是,code 范围内,不论是行内还是区块, <& 两个符号都一定会被转换成 HTML 实体,这项特性让你可以很容易地用 Markdown 写 HTML code (和 HTML 相对而言, HTML 语法中,你要把所有的 <& 都转换为 HTML 实体,才能在 HTML 文件里面写出 HTML code。)


区块元素

段落和换行

一个 Markdown 段落是由一个或多个连续的文本行组成,它的前后要有一个以上的空行(空行的定义是显示上看起来像是空的,便会被视为空行。比方说,若某一行只包含空格和制表符,则该行也会被视为空行)。普通段落不该用空格或制表符来缩进。

「由一个或多个连续的文本行组成」这句话其实暗示了 Markdown 允许段落内的强迫换行(插入换行符),这个特性和其他大部分的 text-to-HTML 格式不一样(包括 Movable Type 的「Convert Line Breaks」选项),其它的格式会把每个换行符都转成 <br /> 标签。

如果你确实想要依赖 Markdown 来插入 <br /> 标签的话,在插入处先按入两个以上的空格然后回车。

的确,需要多费点事(多加空格)来产生 <br /> ,但是简单地「每个换行都转换为 <br />」的方法在 Markdown 中并不适合, Markdown 中 email 式的 区块引用 和多段落的 列表 在使用换行来排版的时候,不但更好用,还更方便阅读。

Markdown 支持两种标题的语法,类 Setext 和类 atx 形式。

类 Setext 形式是用底线的形式,利用 = (最高阶标题)和 - (第二阶标题),例如:

This is an H1
=============

This is an H2
-------------

任何数量的 =- 都可以有效果。

类 Atx 形式则是在行首插入 1 到 6 个 # ,对应到标题 1 到 6 阶,例如:

# 这是 H1

## 这是 H2

###### 这是 H6

你可以选择性地「闭合」类 atx 样式的标题,这纯粹只是美观用的,若是觉得这样看起来比较舒适,你就可以在行尾加上 #,而行尾的 # 数量也不用和开头一样(行首的井字符数量决定标题的阶数):

# 这是 H1 #

## 这是 H2 ##

### 这是 H3 ######

区块引用 Blockquotes

Markdown 标记区块引用是使用类似 email 中用 > 的引用方式。如果你还熟悉在 email 信件中的引言部分,你就知道怎么在 Markdown 文件中建立一个区块引用,那会看起来像是你自己先断好行,然后在每行的最前面加上 >

> This is a blockquote with two paragraphs. Lorem ipsum dolor sit amet,
> consectetuer adipiscing elit. Aliquam hendrerit mi posuere lectus.
> Vestibulum enim wisi, viverra nec, fringilla in, laoreet vitae, risus.
> 
> Donec sit amet nisl. Aliquam semper ipsum sit amet velit. Suspendisse
> id sem consectetuer libero luctus adipiscing.

Markdown 也允许你偷懒只在整个段落的第一行最前面加上 >

> This is a blockquote with two paragraphs. Lorem ipsum dolor sit amet,
consectetuer adipiscing elit. Aliquam hendrerit mi posuere lectus.
Vestibulum enim wisi, viverra nec, fringilla in, laoreet vitae, risus.

> Donec sit amet nisl. Aliquam semper ipsum sit amet velit. Suspendisse
id sem consectetuer libero luctus adipiscing.

区块引用可以嵌套(例如:引用内的引用),只要根据层次加上不同数量的 >

> This is the first level of quoting.
>
> > This is nested blockquote.
>
> Back to the first level.

引用的区块内也可以使用其他的 Markdown 语法,包括标题、列表、代码区块等:

> ## 这是一个标题。
> 
> 1.   这是第一行列表项。
> 2.   这是第二行列表项。
> 
> 给出一些例子代码:
> 
>     return shell_exec("echo $input | $markdown_script");

任何像样的文本编辑器都能轻松地建立 email 型的引用。例如在 BBEdit 中,你可以选取文字后然后从选单中选择增加引用阶层

列表

Markdown 支持有序列表和无序列表。

无序列表使用星号、加号或是减号作为列表标记:

*   Red
*   Green
*   Blue

等同于:

+   Red
+   Green
+   Blue

也等同于:

-   Red
-   Green
-   Blue

有序列表则使用数字接着一个英文句点:

1.  Bird
2.  McHale
3.  Parish

很重要的一点是,你在列表标记上使用的数字并不会影响输出的 HTML 结果,上面的列表所产生的 HTML 标记为:

<ol>
<li>Bird</li>
<li>McHale</li>
<li>Parish</li>
</ol>

如果你的列表标记写成:

1.  Bird
1.  McHale
1.  Parish

或甚至是:

3. Bird
1. McHale
8. Parish

你都会得到完全相同的 HTML 输出。重点在于,你可以让 Markdown 文件的列表数字和输出的结果相同,或是你懒一点,你可以完全不用在意数字的正确性。

如果你使用懒惰的写法,建议第一个项目最好还是从 1. 开始,因为 Markdown 未来可能会支持有序列表的 start 属性。

列表项目标记通常是放在最左边,但是其实也可以缩进,最多 3 个空格,项目标记后面则一定要接着至少一个空格或制表符。

要让列表看起来更漂亮,你可以把内容用固定的缩进整理好:

*   Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
    Aliquam hendrerit mi posuere lectus. Vestibulum enim wisi,
    viverra nec, fringilla in, laoreet vitae, risus.
*   Donec sit amet nisl. Aliquam semper ipsum sit amet velit.
    Suspendisse id sem consectetuer libero luctus adipiscing.

但是如果你懒,那也行:

*   Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
Aliquam hendrerit mi posuere lectus. Vestibulum enim wisi,
viverra nec, fringilla in, laoreet vitae, risus.
*   Donec sit amet nisl. Aliquam semper ipsum sit amet velit.
Suspendisse id sem consectetuer libero luctus adipiscing.

如果列表项目间用空行分开,在输出 HTML 时 Markdown 就会将项目内容用 <p> 标签包起来,举例来说:

*   Bird
*   Magic

会被转换为:

<ul>
<li>Bird</li>
<li>Magic</li>
</ul>

但是这个:

*   Bird

*   Magic

会被转换为:

<ul>
<li><p>Bird</p></li>
<li><p>Magic</p></li>
</ul>

列表项目可以包含多个段落,每个项目下的段落都必须缩进 4 个空格或是 1 个制表符:

1.  This is a list item with two paragraphs. Lorem ipsum dolor
    sit amet, consectetuer adipiscing elit. Aliquam hendrerit
    mi posuere lectus.

    Vestibulum enim wisi, viverra nec, fringilla in, laoreet
    vitae, risus. Donec sit amet nisl. Aliquam semper ipsum
    sit amet velit.

2.  Suspendisse id sem consectetuer libero luctus adipiscing.

如果你每行都有缩进,看起来会看好很多,当然,再次地,如果你很懒惰,Markdown 也允许:

*   This is a list item with two paragraphs.

    This is the second paragraph in the list item. You're
only required to indent the first line. Lorem ipsum dolor
sit amet, consectetuer adipiscing elit.

*   Another item in the same list.

如果要在列表项目内放进引用,那 > 就需要缩进:

*   A list item with a blockquote:

    > This is a blockquote
    > inside a list item.

如果要放代码区块的话,该区块就需要缩进两次,也就是 8 个空格或是 2 个制表符:

*   一列表项包含一个列表区块:

        <代码写在这>

当然,项目列表很可能会不小心产生,像是下面这样的写法:

1986. What a great season.

换句话说,也就是在行首出现数字-句点-空白,要避免这样的状况,你可以在句点前面加上反斜杠。

1986\. What a great season.

代码区块

和程序相关的写作或是标签语言原始码通常会有已经排版好的代码区块,通常这些区块我们并不希望它以一般段落文件的方式去排版,而是照原来的样子显示,Markdown 会用 <pre><code> 标签来把代码区块包起来。

要在 Markdown 中建立代码区块很简单,只要简单地缩进 4 个空格或是 1 个制表符就可以,例如,下面的输入:

这是一个普通段落:

    这是一个代码区块。

Markdown 会转换成:

<p>这是一个普通段落:</p>

<pre><code>这是一个代码区块。
</code></pre>

这个每行一阶的缩进(4 个空格或是 1 个制表符),都会被移除,例如:

Here is an example of AppleScript:

    tell application "Foo"
        beep
    end tell

会被转换为:

<p>Here is an example of AppleScript:</p>

<pre><code>tell application "Foo"
    beep
end tell
</code></pre>

一个代码区块会一直持续到没有缩进的那一行(或是文件结尾)。

在代码区块里面, &<> 会自动转成 HTML 实体,这样的方式让你非常容易使用 Markdown 插入范例用的 HTML 原始码,只需要复制贴上,再加上缩进就可以了,剩下的 Markdown 都会帮你处理,例如:

    <div class="footer">
        &copy; 2004 Foo Corporation
    </div>

会被转换为:

<pre><code>&lt;div class="footer"&gt;
    &amp;copy; 2004 Foo Corporation
&lt;/div&gt;
</code></pre>

代码区块中,一般的 Markdown 语法不会被转换,像是星号便只是星号,这表示你可以很容易地以 Markdown 语法撰写 Markdown 语法相关的文件。

Literate Haskell support (in Pandoc)

If you append +lhs (or +literate_haskell) to an appropriate input or output format (markdown, markdown_strict, rst, or latex for input or output; beamer, html or html5 for output only), pandoc will treat the document as literate Haskell source. This means that

  • In Markdown input, “bird track” sections will be parsed as Haskell code rather than block quotations. Text between \begin{code} and \end{code} will also be treated as Haskell code. For ATX-style headers the character ‘=’ will be used instead of ‘#’.

  • In Markdown output, code blocks with classes haskell and literate will be rendered using bird tracks, and block quotations will be indented one space, so they will not be treated as Haskell code. In addition, headers will be rendered setext-style (with underlines) rather than ATX-style (with ‘#’ characters). (This is because ghc treats ‘#’ characters in column 1 as introducing line numbers.)

  • In restructured text input, “bird track” sections will be parsed as Haskell code.

  • In restructured text output, code blocks with class haskell will be rendered using bird tracks.

  • In LaTeX input, text in code environments will be parsed as Haskell code.

  • In LaTeX output, code blocks with class haskell will be rendered inside code environments.

  • In HTML output, code blocks with class haskell will be rendered with class literatehaskell and bird tracks.

Examples:

pandoc -f markdown+lhs -t html

reads literate Haskell source formatted with Markdown conventions and writes ordinary HTML (without bird tracks).

pandoc -f markdown+lhs -t html+lhs

writes HTML with the Haskell code in bird tracks, so it can be copied and pasted as literate Haskell source.

Syntax highlighting

Pandoc will automatically highlight syntax in fenced code blocks that are marked with a language name. The Haskell library highlighting-kate is used for highlighting, which works in HTML, Docx, and LaTeX/PDF output. To see a list of language names that pandoc will recognize, type pandoc --list-highlight-languages.

The color scheme can be selected using the --highlight-style option. The default color scheme is pygments, which imitates the default color scheme used by the Python library pygments (though pygments is not actually used to do the highlighting). To see a list of highlight styles, type pandoc --list-highlight-styles.

To disable highlighting, use the --no-highlight option.

分隔线

你可以在一行中用三个以上的星号、减号、底线来建立一个分隔线,行内不能有其他东西。你也可以在星号或是减号中间插入空格。下面每种写法都可以建立分隔线:

* * *

***

*****

- - -

---------------------------------------

区段元素

Markdown 支持两种形式的链接语法: 行内式参考式两种形式。

不管是哪一种,链接文字都是用 [方括号] 来标记。

要建立一个行内式的链接,只要在方块括号后面紧接着圆括号并插入网址链接即可,如果你还想要加上链接的 title 文字,只要在网址后面,用双引号把 title 文字包起来即可,例如:

This is [an example](http://example.com/ "Title") inline link.

[This link](http://example.net/) has no title attribute.

会产生:

<p>This is <a href="http://example.com/" title="Title">
an example</a> inline link.</p>

<p><a href="http://example.net/">This link</a> has no
title attribute.</p>

如果你是要链接到同样主机的资源,你可以使用相对路径:

See my [About](/about/) page for details.   

参考式的链接是在链接文字的括号后面再接上另一个方括号,而在第二个方括号里面要填入用以辨识链接的标记:

This is [an example][id] reference-style link.

你也可以选择性地在两个方括号中间加上一个空格:

This is [an example] [id] reference-style link.

接着,在文件的任意处,你可以把这个标记的链接内容定义出来:

[id]: http://example.com/  "Optional Title Here"

链接内容定义的形式为:

  • 方括号(前面可以选择性地加上至多三个空格来缩进),里面输入链接文字
  • 接着一个冒号
  • 接着一个以上的空格或制表符
  • 接着链接的网址
  • 选择性地接着 title 内容,可以用单引号、双引号或是括弧包着

下面这三种链接的定义都是相同:

[foo]: http://example.com/  "Optional Title Here"
[foo]: http://example.com/  'Optional Title Here'
[foo]: http://example.com/  (Optional Title Here)

请注意:有一个已知的问题是 Markdown.pl 1.0.1 会忽略单引号包起来的链接 title。

链接网址也可以用尖括号包起来:

[id]: <http://example.com/>  "Optional Title Here"

你也可以把 title 属性放到下一行,也可以加一些缩进,若网址太长的话,这样会比较好看:

[id]: http://example.com/longish/path/to/resource/here
    "Optional Title Here"

网址定义只有在产生链接的时候用到,并不会直接出现在文件之中。

链接辨别标签可以有字母、数字、空白和标点符号,但是并区分大小写,因此下面两个链接是一样的:

[link text][a]
[link text][A]

隐式链接标记功能让你可以省略指定链接标记,这种情形下,链接标记会视为等同于链接文字,要用隐式链接标记只要在链接文字后面加上一个空的方括号,如果你要让 “Google” 链接到 google.com,你可以简化成:

[Google][]

然后定义链接内容:

[Google]: http://google.com/

由于链接文字可能包含空白,所以这种简化型的标记内也许包含多个单词:

Visit [Daring Fireball][] for more information.

然后接着定义链接:

[Daring Fireball]: http://daringfireball.net/

链接的定义可以放在文件中的任何一个地方,我比较偏好直接放在链接出现段落的后面,你也可以把它放在文件最后面,就像是注解一样。

下面是一个参考式链接的范例:

I get 10 times more traffic from [Google] [1] than from
[Yahoo] [2] or [MSN] [3].

  [1]: http://google.com/        "Google"
  [2]: http://search.yahoo.com/  "Yahoo Search"
  [3]: http://search.msn.com/    "MSN Search"

如果改成用链接名称的方式写:

I get 10 times more traffic from [Google][] than from
[Yahoo][] or [MSN][].

  [google]: http://google.com/        "Google"
  [yahoo]:  http://search.yahoo.com/  "Yahoo Search"
  [msn]:    http://search.msn.com/    "MSN Search"

上面两种写法都会产生下面的 HTML。

<p>I get 10 times more traffic from <a href="http://google.com/"
title="Google">Google</a> than from
<a href="http://search.yahoo.com/" title="Yahoo Search">Yahoo</a>
or <a href="http://search.msn.com/" title="MSN Search">MSN</a>.</p>

下面是用行内式写的同样一段内容的 Markdown 文件,提供作为比较之用:

I get 10 times more traffic from [Google](http://google.com/ "Google")
than from [Yahoo](http://search.yahoo.com/ "Yahoo Search") or
[MSN](http://search.msn.com/ "MSN Search").

参考式的链接其实重点不在于它比较好写,而是它比较好读,比较一下上面的范例,使用参考式的文章本身只有 81 个字符,但是用行内形式的却会增加到 176 个字元,如果是用纯 HTML 格式来写,会有 234 个字元,在 HTML 格式中,标签比文本还要多。

使用 Markdown 的参考式链接,可以让文件更像是浏览器最后产生的结果,让你可以把一些标记相关的元数据移到段落文字之外,你就可以增加链接而不让文章的阅读感觉被打断。

强调

Markdown 使用星号(*)和底线(_)作为标记强调字词的符号,被 *_ 包围的字词会被转成用 <em> 标签包围,用两个 *_ 包起来的话,则会被转成 <strong>,例如:

*single asterisks*

_single underscores_

**double asterisks**

__double underscores__

会转成:

<em>single asterisks</em>

<em>single underscores</em>

<strong>double asterisks</strong>

<strong>double underscores</strong>

你可以随便用你喜欢的样式,唯一的限制是,你用什么符号开启标签,就要用什么符号结束。

强调也可以直接插在文字中间:

un*frigging*believable

但是如果你的 *_ 两边都有空白的话,它们就只会被当成普通的符号

如果要在文字前后直接插入普通的星号或底线,你可以用反斜线:

\*this text is surrounded by literal asterisks\*

数学公式展示功能

数学公式使用MathJax插件,下面的是勾股定理: \[a^2+b^2=c^2.\]

代码

如果要标记一小段行内代码,你可以用反引号把它包起来(`),例如:

Use the `printf()` function.

会产生:

<p>Use the <code>printf()</code> function.</p>

如果要在代码区段内插入反引号,你可以用多个反引号来开启和结束代码区段:

``There is a literal backtick (`) here.``

这段语法会产生:

<p><code>There is a literal backtick (`) here.</code></p>

代码区段的起始和结束端都可以放入一个空白,起始端后面一个,结束端前面一个,这样你就可以在区段的一开始就插入反引号:

A single backtick in a code span: `` ` ``

A backtick-delimited string in a code span: `` `foo` ``

会产生:

<p>A single backtick in a code span: <code>`</code></p>

<p>A backtick-delimited string in a code span: <code>`foo`</code></p>

在代码区段内,& 和尖括号会被自动地转成 HTML 实体,这使得插入 HTML 原始码变得很容易,Markdown 会把下面这段:

Please don't use any `<blink>` tags.

转为:

<p>Please don't use any <code>&lt;blink&gt;</code> tags.</p>

你也可以这样写:

`&#8212;` is the decimal-encoded equivalent of `&mdash;`.

以产生:

<p><code>&amp;#8212;</code> is the decimal-encoded
equivalent of <code>&amp;mdash;</code>.</p>

代码展示功能

测试了很多。现在的代码应该是正常的吧。

代码使用Python块,使用Markdown内嵌的支持。

A block of text.

import os
print "hello,world"

代码虽然不是很好看,但是也可以接受。

图片

很明显地,要在纯文字应用中设计一个「自然」的语法来插入图片是有一定难度的。

Markdown 使用一种和链接很相似的语法来标记图片,同样也允许两种样式: 行内式参考式

行内式的图片语法看起来像是:

![Alt text](/path/to/img.jpg)

![Alt text](/path/to/img.jpg "Optional title")

详细叙述如下:

  • 一个惊叹号 !
  • 接着一个方括号,里面放上图片的替代文字
  • 接着一个普通括号,里面放上图片的网址,最后还可以用引号包住并加上 选择性的 ‘title’ 文字。

参考式的图片语法则长得像这样:

![Alt text][id]

「id」是图片参考的名称,图片参考的定义方式则和连结参考一样:

[id]: url/to/image  "Optional title attribute"

到目前为止, Markdown 还没有办法指定图片的宽高,如果你需要的话,你可以使用普通的 <img> 标签。

测试图片功能

  • 基本情况下,直接展示图片
  • 高级情况下,使用fancybox可以展示图片墙

Welcome to Hexo! This is your very first post. Check documentation for more info. If you get any problems when using Hexo, you can find the answer in troubleshooting or you can ask me on GitHub.

Bay

Bay


其它

Markdown 支持以比较简短的自动链接形式来处理网址和电子邮件信箱,只要是用尖括号包起来, Markdown 就会自动把它转成链接。一般网址的链接文字就和链接地址一样,例如:

<http://example.com/>

Markdown 会转为:

<a href="http://example.com/">http://example.com/</a>

邮址的自动链接也很类似,只是 Markdown 会先做一个编码转换的过程,把文字字符转成 16 进位码的 HTML 实体,这样的格式可以糊弄一些不好的邮址收集机器人,例如:

<address@example.com>

Markdown 会转成:

<a href="&#x6D;&#x61;i&#x6C;&#x74;&#x6F;:&#x61;&#x64;&#x64;&#x72;&#x65;
&#115;&#115;&#64;&#101;&#120;&#x61;&#109;&#x70;&#x6C;e&#x2E;&#99;&#111;
&#109;">&#x61;&#x64;&#x64;&#x72;&#x65;&#115;&#115;&#64;&#101;&#120;&#x61;
&#109;&#x70;&#x6C;e&#x2E;&#99;&#111;&#109;</a>

在浏览器里面,这段字串(其实是 <a href="mailto:address@example.com">address@example.com</a>)会变成一个可以点击的「address@example.com」链接。

(这种作法虽然可以糊弄不少的机器人,但并不能全部挡下来,不过总比什么都不做好些。不管怎样,公开你的信箱终究会引来广告信件的。)

反斜杠

Markdown 可以利用反斜杠来插入一些在语法中有其它意义的符号,例如:如果你想要用星号加在文字旁边的方式来做出强调效果(但不用 <em> 标签),你可以在星号的前面加上反斜杠:

\*literal asterisks\*

Markdown 支持以下这些符号前面加上反斜杠来帮助插入普通的符号:

\   反斜线
`   反引号
*   星号
_   底线
{}  花括号
[]  方括号
()  括弧
#   井字号
+   加号
-   减号
.   英文句点
!   惊叹号

Pandoc交叉引用功能

pandoc-crossref filter

Pandoc crossref. Homepage is sec. 5.4.

pandoc-crossref is a pandoc filter for numbering figures, equations, tables and cross-references to them.

Input file (like demo.md) can be converted into html, latex, pdf, md or other formats.

Optionally, you can use cleveref for latex/pdf output, e.g. cleveref pdf, cleveref latex, and listings package, e.g. listings pdf, listings latex

pandoc-citeproc and pandoc-crossref

Since pandoc-crossref uses the same citation syntax as pandoc-citeproc, you have to run former before latter. For example:

pandoc -F pandoc-crossref -F pandoc-citeproc file.md -o file.html

Image labels

Figure 1: Caption

Figure 1: Caption

See Figure~fig. 1.

Subfigures

It’s possible to group figures as subfigures. Basic syntax is as follows:

a

a

b

b

Figure 2: Figure 1: Caption of figure. a — subfigure 1 caption, b — subfigure 2 caption. a — subfigure 1 caption, b — subfigure 2 caption

<div id="fig:figureRef">
![subfigure 1 caption](image1.png){#fig:figureRefA width=40%}

![subfigure 2 caption](image2.png){#fig:figureRefB width=40%}

Caption of figure
</div>

References to subfigures will be rendered as figureNumber (subfigureNumber), e.g., in this particular example, [@fig:figureRefA] will produce fig. 1 (a). Fig 1.(a) : fig. 2 (a) .

Equation labels

\[ math \qquad(1)\]

To label a display equation, append { #eq:label} (with label being something unique to reference this equation by) immediately after math block.

Math block and label can be separated by one or more spaces.

You can also number all display equations with autoEqnLabels metadata setting (see below). Note, however, that you won’t be able to reference equations without explicit labels. See Equation~eq. 1.

Table labels

Table 1: Caption
a b c
1 2 3
4 5 6

To label a table, append { #tbl:label} at the end of table caption (with label being something unique to reference this table by). Caption and label must be separated by at least one space. See Table~tbl. 1.

Code Block labels

There are a couple options to add code block labels. Those work only if code block id starts with lst:, e.g. { #lst:code}.

caption attribute will be treated as code block caption. If code block has both id and caption attributes, it will be treated as numbered code block.

Listing 1: Listing caption

main :: IO () main = putStrLn "Hello World!" 

List Codelst. 1

Table-style captions

Enabled with codeBlockCaptions metadata option. If code block is immediately adjacent to paragraph, starting with Listing: or :, said paragraph will be treated as code block caption.

 Listing: Listing caption
main :: IO ()
main = putStrLn "Hello World!"
<pre> Listing: Listing caption

main :: IO ()
main = putStrLn "Hello World!"

</pre> 

Variables set by pandoc

Some variables are set automatically by pandoc. These vary somewhat depending on the output format, but include metadata fields as well as the following:

title, author, date

allow identification of basic aspects of the document. Included in PDF metadata through LaTeX and ConTeXt. These can be set through a pandoc title block, which allows for multiple authors, or through a YAML metadata block:

---
author:
- Aristotle
- Peter Abelard
...
subtitle
document subtitle, included in HTML, EPUB, LaTeX, ConTeXt, and Word docx; renders in LaTeX only when using a document class that supports \subtitle, such as beamer or the KOMA-Script series (scrartcl, scrreprt, scrbook).1
institute
author affiliations (in LaTeX and Beamer only). Can be a list, when there are multiple authors.
abstract
document summary, included in LaTeX, ConTeXt, AsciiDoc, and Word docx
keywords
list of keywords to be included in HTML, PDF, and AsciiDoc metadata; may be repeated as for author, above
header-includes
contents specified by -H/--include-in-header (may have multiple values)
toc
non-null value if --toc/--table-of-contents was specified
toc-title
title of table of contents (works only with EPUB and docx)
include-before
contents specified by -B/--include-before-body (may have multiple values)
include-after
contents specified by -A/--include-after-body (may have multiple values)
body
body of document
meta-json
JSON representation of all of the document’s metadata

Language variables

lang

identifies the main language of the document, using a code according to BCP 47 (e.g. en or en-GB). For some output formats, pandoc will convert it to an appropriate format stored in the additional variables babel-lang, polyglossia-lang (LaTeX) and context-lang (ConTeXt).

Native pandoc spans and divs with the lang attribute (value in BCP 47) can be used to switch the language in that range.

otherlangs
a list of other languages used in the document in the YAML metadata, according to BCP 47. For example: otherlangs: [en-GB, fr]. This is automatically generated from the lang attributes in all spans and divs but can be overridden. Currently only used by LaTeX through the generated babel-otherlangs and polyglossia-otherlangs variables. The LaTeX writer outputs polyglossia commands in the text but the babel-newcommands variable contains mappings for them to the corresponding babel.
dir

the base direction of the document, either rtl (right-to-left) or ltr (left-to-right).

For bidirectional documents, native pandoc spans and divs with the dir attribute (value rtl or ltr) can be used to override the base direction in some output formats. This may not always be necessary if the final renderer (e.g. the browser, when generating HTML) supports the Unicode Bidirectional Algorithm.

When using LaTeX for bidirectional documents, only the xelatex engine is fully supported (use --latex-engine=xelatex).

Variables for slides

Variables are available for [producing slide shows with pandoc], including all reveal.js configuration options.

slidy-url
base URL for Slidy documents (defaults to http://www.w3.org/Talks/Tools/Slidy2)
slideous-url
base URL for Slideous documents (defaults to slideous)
s5-url
base URL for S5 documents (defaults to s5/default)
revealjs-url
base URL for reveal.js documents (defaults to reveal.js)
theme, colortheme, fonttheme, innertheme, outertheme
themes for LaTeX beamer documents
themeoptions
options for LaTeX beamer themes (a list).
navigation
controls navigation symbols in beamer documents (default is empty for no navigation symbols; other valid values are frame, vertical, and horizontal).
section-titles
enables on “title pages” for new sections in beamer documents (default = true).
beamerarticle
when true, the beamerarticle package is loaded (for producing an article from beamer slides).
colorlinks
add color to link text; automatically enabled if any of linkcolor, citecolor, urlcolor, or toccolor are set (for beamer only).
linkcolor, citecolor, urlcolor, toccolor
color for internal links, citation links, external links, and links in table of contents: uses any of the predefined LaTeX colors (for beamer only).

Variables for LaTeX

LaTeX variables are used when [creating a PDF].

papersize
paper size, e.g. letter, A4
fontsize
font size for body text (e.g. 10pt, 12pt)
documentclass
document class, e.g. article, report, book, memoir
classoption
option for document class, e.g. oneside; may be repeated for multiple options
geometry
option for [geometry] package, e.g. margin=1in; may be repeated for multiple options
margin-left, margin-right, margin-top, margin-bottom
sets margins, if geometry is not used (otherwise geometry overrides these)
linestretch
adjusts line spacing using the [setspace] package, e.g. 1.25, 1.5
fontfamily
font package for use with pdflatex: [TeX Live] includes many options, documented in the LaTeX Font Catalogue. The default is [Latin Modern][lm].
fontfamilyoptions
options for package used as fontfamily: e.g. osf,sc with fontfamily set to mathpazo provides Palatino with old-style figures and true small caps; may be repeated for multiple options
mainfont, sansfont, monofont, mathfont, CJKmainfont
font families for use with xelatex or lualatex: take the name of any system font, using the [fontspec] package. Note that if CJKmainfont is used, the [xecjk] package must be available.
mainfontoptions, sansfontoptions, monofontoptions, mathfontoptions, CJKoptions
options to use with mainfont, sansfont, monofont, mathfont, CJKmainfont in xelatex and lualatex. Allow for any choices available through [fontspec], such as the OpenType features Numbers=OldStyle,Numbers=Proportional. May be repeated for multiple options.
fontenc
allows font encoding to be specified through fontenc package (with pdflatex); default is T1 (see guide to LaTeX font encodings)
microtypeoptions
options to pass to the microtype package
colorlinks
add color to link text; automatically enabled if any of linkcolor, citecolor, urlcolor, or toccolor are set
linkcolor, citecolor, urlcolor, toccolor
color for internal links, citation links, external links, and links in table of contents: uses any of the predefined LaTeX colors
links-as-notes
causes links to be printed as footnotes
indent
uses document class settings for indentation (the default LaTeX template otherwise removes indentation and adds space between paragraphs)
subparagraph
disables default behavior of LaTeX template that redefines (sub)paragraphs as sections, changing the appearance of nested headings in some classes
thanks
specifies contents of acknowledgments footnote after document title.
toc
include table of contents (can also be set using --toc/--table-of-contents)
toc-depth
level of section to include in table of contents
secnumdepth
numbering depth for sections, if sections are numbered
lof, lot
include list of figures, list of tables
bibliography
bibliography to use for resolving references
biblio-style
bibliography style, when used with --natbib and --biblatex.
biblio-title
bibliography title, when used with --natbib and --biblatex.
biblatexoptions
list of options for biblatex.

Variables for ConTeXt

papersize
paper size, e.g. letter, A4, landscape (see ConTeXt Paper Setup); may be repeated for multiple options
layout
options for page margins and text arrangement (see ConTeXt Layout); may be repeated for multiple options
margin-left, margin-right, margin-top, margin-bottom
sets margins, if layout is not used (otherwise layout overrides these)
fontsize
font size for body text (e.g. 10pt, 12pt)
mainfont, sansfont, monofont, mathfont
font families: take the name of any system font (see ConTeXt Font Switching)
linkcolor, contrastcolor
color for links outside and inside a page, e.g. red, blue (see ConTeXt Color)
linkstyle
typeface style for links, e.g. normal, bold, slanted, boldslanted, type, cap, small
indenting
controls indentation of paragraphs, e.g. yes,small,next (see ConTeXt Indentation); may be repeated for multiple options
whitespace
spacing between paragraphs, e.g. none, small (using setupwhitespace)
interlinespace
adjusts line spacing, e.g. 4ex (using setupinterlinespace); may be repeated for multiple options
headertext, footertext
text to be placed in running header or footer (see ConTeXt Headers and Footers); may be repeated up to four times for different placement
pagenumbering
page number style and location (using setuppagenumbering); may be repeated for multiple options
toc
include table of contents (can also be set using --toc/--table-of-contents)
lof, lot
include list of figures, list of tables

Variables for man pages

section
section number in man pages
header
header in man pages
footer
footer in man pages
adjusting
adjusts text to left (l), right (r), center (c), or both (b) margins
hyphenate
if true (the default), hyphenation will be used

Using variables in templates

Variable names are sequences of alphanumerics, -, and _, starting with a letter. A variable name surrounded by $ signs will be replaced by its value. For example, the string $title$ in

<title>$title$</title>

will be replaced by the document title.

To write a literal $ in a template, use $$.

Templates may contain conditionals. The syntax is as follows:

$if(variable)$
X
$else$
Y
$endif$

This will include X in the template if variable has a non-null value; otherwise it will include Y. X and Y are placeholders for any valid template text, and may include interpolated variables or other conditionals. The $else$ section may be omitted.

When variables can have multiple values (for example, author in a multi-author document), you can use the $for$ keyword:

$for(author)$
<meta name="author" content="$author$" />
$endfor$

You can optionally specify a separator to be used between consecutive items:

$for(author)$$author$$sep$, $endfor$

A dot can be used to select a field of a variable that takes an object as its value. So, for example:

$author.name$ ($author.affiliation$)

If you use custom templates, you may need to revise them as pandoc changes. We recommend tracking the changes in the default templates, and modifying your custom templates accordingly. An easy way to do this is to fork the pandoc-templates repository and merge in changes after each pandoc release.

Pandoc’s Markdown

Pandoc understands an extended and slightly revised version of John Gruber’s Markdown syntax. This document explains the syntax, noting differences from standard Markdown. Except where noted, these differences can be suppressed by using the markdown_strict format instead of markdown. An extensions can be enabled by adding +EXTENSION to the format name and disabled by adding -EXTENSION. For example, markdown_strict+footnotes is strict Markdown with footnotes enabled, while markdown-footnotes-pipe_tables is pandoc’s Markdown without footnotes or pipe tables.

Philosophy

Markdown is designed to be easy to write, and, even more importantly, easy to read:

A Markdown-formatted document should be publishable as-is, as plain text, without looking like it’s been marked up with tags or formatting instructions. – John Gruber

This principle has guided pandoc’s decisions in finding syntax for tables, footnotes, and other extensions.

There is, however, one respect in which pandoc’s aims are different from the original aims of Markdown. Whereas Markdown was originally designed with HTML generation in mind, pandoc is designed for multiple output formats. Thus, while pandoc allows the embedding of raw HTML, it discourages it, and provides other, non-HTMLish ways of representing important document elements like definition lists, tables, mathematics, and footnotes.

Paragraphs

A paragraph is one or more lines of text followed by one or more blank lines. Newlines are treated as spaces, so you can reflow your paragraphs as you like. If you need a hard line break, put two or more spaces at the end of a line.

Extension: escaped_line_breaks

A backslash followed by a newline is also a hard line break. Note: in multiline and grid table cells, this is the only way to create a hard line break, since trailing spaces in the cells are ignored.

Headers

There are two kinds of headers: Setext and ATX.

Setext-style headers

A setext-style header is a line of text “underlined” with a row of = signs (for a level one header) or - signs (for a level two header):

A level-one header
==================

A level-two header
------------------

The header text can contain inline formatting, such as emphasis (see Inline formatting, below).

ATX-style headers

An ATX-style header consists of one to six # signs and a line of text, optionally followed by any number of # signs. The number of # signs at the beginning of the line is the header level:

## A level-two header

### A level-three header ###

As with setext-style headers, the header text can contain formatting:

# A level-one header with a [link](/url) and *emphasis*

Extension: blank_before_header

Standard Markdown syntax does not require a blank line before a header. Pandoc does require this (except, of course, at the beginning of the document). The reason for the requirement is that it is all too easy for a # to end up at the beginning of a line by accident (perhaps through line wrapping). Consider, for example:

I like several of their flavors of ice cream:
#22, for example, and #5.

Header identifiers

Extension: header_attributes

Headers can be assigned attributes using this syntax at the end of the line containing the header text:

{#identifier .class .class key=value key=value}

Thus, for example, the following headers will all be assigned the identifier foo:

# My header {#foo}

## My header ##    {#foo}

My other header   {#foo}
---------------

(This syntax is compatible with PHP Markdown Extra.)

Note that although this syntax allows assignment of classes and key/value attributes, writers generally don’t use all of this information. Identifiers, classes, and key/value attributes are used in HTML and HTML-based formats such as EPUB and slidy. Identifiers are used for labels and link anchors in the LaTeX, ConTeXt, Textile, and AsciiDoc writers.

Headers with the class unnumbered will not be numbered, even if --number-sections is specified. A single hyphen (-) in an attribute context is equivalent to .unnumbered, and preferable in non-English documents. So,

# My header {-}

is just the same as

# My header {.unnumbered}

Extension: auto_identifiers

A header without an explicitly specified identifier will be automatically assigned a unique identifier based on the header text. To derive the identifier from the header text,

  • Remove all formatting, links, etc.
  • Remove all footnotes.
  • Remove all punctuation, except underscores, hyphens, and periods.
  • Replace all spaces and newlines with hyphens.
  • Convert all alphabetic characters to lowercase.
  • Remove everything up to the first letter (identifiers may not begin with a number or punctuation mark).
  • If nothing is left after this, use the identifier section.

Thus, for example,

Header Identifier
Header identifiers in HTML header-identifiers-in-html
*Dogs*?--in *my* house? dogs--in-my-house
[HTML], [S5], or [RTF]? html-s5-or-rtf
3. Applications applications
33 section

These rules should, in most cases, allow one to determine the identifier from the header text. The exception is when several headers have the same text; in this case, the first will get an identifier as described above; the second will get the same identifier with -1 appended; the third with -2; and so on.

These identifiers are used to provide link targets in the table of contents generated by the --toc|--table-of-contents option. They also make it easy to provide links from one section of a document to another. A link to this section, for example, might look like this:

See the section on
[header identifiers](#header-identifiers-in-html-latex-and-context).

Note, however, that this method of providing links to sections works only in HTML, LaTeX, and ConTeXt formats.

If the --section-divs option is specified, then each section will be wrapped in a div (or a section, if --html5 was specified), and the identifier will be attached to the enclosing <div> (or <section>) tag rather than the header itself. This allows entire sections to be manipulated using JavaScript or treated differently in CSS.

Extension: implicit_header_references

Pandoc behaves as if reference links have been defined for each header. So, to link to a header

# Header identifiers in HTML

you can simply write

[Header identifiers in HTML]

or

[Header identifiers in HTML][]

or

[the section on header identifiers][header identifiers in
HTML]

instead of giving the identifier explicitly:

[Header identifiers in HTML](#header-identifiers-in-html)

If there are multiple headers with identical text, the corresponding reference will link to the first one only, and you will need to use explicit links to link to the others, as described above.

Like regular reference links, these references are case-insensitive.

Explicit link reference definitions always take priority over implicit header references. So, in the following example, the link will point to bar, not to #foo:

# Foo

[foo]: bar

See [foo]

Block quotations

Markdown uses email conventions for quoting blocks of text. A block quotation is one or more paragraphs or other block elements (such as lists or headers), with each line preceded by a > character and an optional space. (The > need not start at the left margin, but it should not be indented more than three spaces.)

> This is a block quote. This
> paragraph has two lines.
>
> 1. This is a list inside a block quote.
> 2. Second item.

A “lazy” form, which requires the > character only on the first line of each block, is also allowed:

> This is a block quote. This
paragraph has two lines.

> 1. This is a list inside a block quote.
2. Second item.

Among the block elements that can be contained in a block quote are other block quotes. That is, block quotes can be nested:

> This is a block quote.
>
> > A block quote within a block quote.

If the > character is followed by an optional space, that space will be considered part of the block quote marker and not part of the indentation of the contents. Thus, to put an indented code block in a block quote, you need five spaces after the >:

>     code

Extension: blank_before_blockquote

Standard Markdown syntax does not require a blank line before a block quote. Pandoc does require this (except, of course, at the beginning of the document). The reason for the requirement is that it is all too easy for a > to end up at the beginning of a line by accident (perhaps through line wrapping). So, unless the markdown_strict format is used, the following does not produce a nested block quote in pandoc:

> This is a block quote.
>> Nested.

Verbatim (code) blocks

Indented code blocks

A block of text indented four spaces (or one tab) is treated as verbatim text: that is, special characters do not trigger special formatting, and all spaces and line breaks are preserved. For example,

    if (a > 3) {
      moveShip(5 * gravity, DOWN);
    }

The initial (four space or one tab) indentation is not considered part of the verbatim text, and is removed in the output.

Note: blank lines in the verbatim text need not begin with four spaces.

Fenced code blocks

Extension: fenced_code_blocks

In addition to standard indented code blocks, pandoc supports fenced code blocks. These begin with a row of three or more tildes (~) and end with a row of tildes that must be at least as long as the starting row. Everything between these lines is treated as code. No indentation is necessary:

~~~~~~~
if (a > 3) {
  moveShip(5 * gravity, DOWN);
}
~~~~~~~

Like regular code blocks, fenced code blocks must be separated from surrounding text by blank lines.

If the code itself contains a row of tildes or backticks, just use a longer row of tildes or backticks at the start and end:

~~~~~~~~~~~~~~~~
~~~~~~~~~~
code including tildes
~~~~~~~~~~
~~~~~~~~~~~~~~~~

Extension: backtick_code_blocks

Same as fenced_code_blocks, but uses backticks (`) instead of tildes (~).

Extension: fenced_code_attributes

Optionally, you may attach attributes to fenced or backtick code block using this syntax:

~~~~ {#mycode .haskell .numberLines startFrom="100"}
qsort []     = []
qsort (x:xs) = qsort (filter (< x) xs) ++ [x] ++
               qsort (filter (>= x) xs)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Here mycode is an identifier, haskell and numberLines are classes, and startFrom is an attribute with value 100. Some output formats can use this information to do syntax highlighting. Currently, the only output formats that uses this information are HTML and LaTeX. If highlighting is supported for your output format and language, then the code block above will appear highlighted, with numbered lines. (To see which languages are supported, type pandoc --list-highlight-languages.) Otherwise, the code block above will appear as follows:

<pre id="mycode" class="haskell numberLines" startFrom="100">
  <code>
  ...
  </code>
</pre>

A shortcut form can also be used for specifying the language of the code block:

```haskell
qsort [] = []
```

This is equivalent to:

``` {.haskell}
qsort [] = []
```

If the fenced_code_attributes extension is disabled, but input contains class attribute(s) for the code block, the first class attribute will be printed after the opening fence as a bare word.

To prevent all highlighting, use the --no-highlight flag. To set the highlighting style, use --highlight-style. For more information on highlighting, see Syntax highlighting, below.

Line blocks

Extension: line_blocks

A line block is a sequence of lines beginning with a vertical bar (|) followed by a space. The division into lines will be preserved in the output, as will any leading spaces; otherwise, the lines will be formatted as Markdown. This is useful for verse and addresses:

| The limerick packs laughs anatomical
| In space that is quite economical.
|    But the good ones I've seen
|    So seldom are clean
| And the clean ones so seldom are comical

| 200 Main St.
| Berkeley, CA 94718

The lines can be hard-wrapped if needed, but the continuation line must begin with a space.

| The Right Honorable Most Venerable and Righteous Samuel L.
  Constable, Jr.
| 200 Main St.
| Berkeley, CA 94718

This syntax is borrowed from reStructuredText.

Lists

Bullet lists

A bullet list is a list of bulleted list items. A bulleted list item begins with a bullet (*, +, or -). Here is a simple example:

* one
* two
* three

This will produce a “compact” list. If you want a “loose” list, in which each item is formatted as a paragraph, put spaces between the items:

* one

* two

* three

The bullets need not be flush with the left margin; they may be indented one, two, or three spaces. The bullet must be followed by whitespace.

List items look best if subsequent lines are flush with the first line (after the bullet):

* here is my first
  list item.
* and my second.

But Markdown also allows a “lazy” format:

* here is my first
list item.
* and my second.

The four-space rule

A list item may contain multiple paragraphs and other block-level content. However, subsequent paragraphs must be preceded by a blank line and indented four spaces or a tab. The list will look better if the first paragraph is aligned with the rest:

  * First paragraph.

    Continued.

  * Second paragraph. With a code block, which must be indented
    eight spaces:

        { code }

List items may include other lists. In this case the preceding blank line is optional. The nested list must be indented four spaces or one tab:

* fruits
    + apples
        - macintosh
        - red delicious
    + pears
    + peaches
* vegetables
    + broccoli
    + chard

As noted above, Markdown allows you to write list items “lazily,” instead of indenting continuation lines. However, if there are multiple paragraphs or other blocks in a list item, the first line of each must be indented.

+ A lazy, lazy, list
item.

+ Another one; this looks
bad but is legal.

    Second paragraph of second
list item.

Note: Although the four-space rule for continuation paragraphs comes from the official Markdown syntax guide, the reference implementation, Markdown.pl, does not follow it. So pandoc will give different results than Markdown.pl when authors have indented continuation paragraphs fewer than four spaces.

The Markdown syntax guide is not explicit whether the four-space rule applies to all block-level content in a list item; it only mentions paragraphs and code blocks. But it implies that the rule applies to all block-level content (including nested lists), and pandoc interprets it that way.

Ordered lists

Ordered lists work just like bulleted lists, except that the items begin with enumerators rather than bullets.

In standard Markdown, enumerators are decimal numbers followed by a period and a space. The numbers themselves are ignored, so there is no difference between this list:

1.  one
2.  two
3.  three

and this one:

5.  one
7.  two
1.  three

Extension: fancy_lists

Unlike standard Markdown, pandoc allows ordered list items to be marked with uppercase and lowercase letters and roman numerals, in addition to Arabic numerals. List markers may be enclosed in parentheses or followed by a single right-parentheses or period. They must be separated from the text that follows by at least one space, and, if the list marker is a capital letter with a period, by at least two spaces.2

The fancy_lists extension also allows ‘#’ to be used as an ordered list marker in place of a numeral:

#. one
#. two

Extension: startnum

Pandoc also pays attention to the type of list marker used, and to the starting number, and both of these are preserved where possible in the output format. Thus, the following yields a list with numbers followed by a single parenthesis, starting with 9, and a sublist with lowercase roman numerals:

 9)  Ninth
10)  Tenth
11)  Eleventh
       i. subone
      ii. subtwo
     iii. subthree

Pandoc will start a new list each time a different type of list marker is used. So, the following will create three lists:

(2) Two
(5) Three
1.  Four
*   Five

If default list markers are desired, use #.:

#.  one
#.  two
#.  three

Definition lists

Extension: definition_lists

Pandoc supports definition lists, using the syntax of PHP Markdown Extra with some extensions.3

Term 1

:   Definition 1

Term 2 with *inline markup*

:   Definition 2

        { some code, part of Definition 2 }

    Third paragraph of definition 2.

Each term must fit on one line, which may optionally be followed by a blank line, and must be followed by one or more definitions. A definition begins with a colon or tilde, which may be indented one or two spaces.

A term may have multiple definitions, and each definition may consist of one or more block elements (paragraph, code block, list, etc.), each indented four spaces or one tab stop. The body of the definition (including the first line, aside from the colon or tilde) should be indented four spaces. However, as with other Markdown lists, you can “lazily” omit indentation except at the beginning of a paragraph or other block element:

Term 1

:   Definition
with lazy continuation.

    Second paragraph of the definition.

If you leave space before the definition (as in the example above), the text of the definition will be treated as a paragraph. In some output formats, this will mean greater spacing between term/definition pairs. For a more compact definition list, omit the space before the definition:

Term 1
  ~ Definition 1

Term 2
  ~ Definition 2a
  ~ Definition 2b

Note that space between items in a definition list is required. (A variant that loosens this requirement, but disallows “lazy” hard wrapping, can be activated with compact_definition_lists: see Non-pandoc extensions, below.)

Numbered example lists

Extension: example_lists

The special list marker @ can be used for sequentially numbered examples. The first list item with a @ marker will be numbered ‘1’, the next ‘2’, and so on, throughout the document. The numbered examples need not occur in a single list; each new list using @ will take up where the last stopped. So, for example:

(@)  My first example will be numbered (1).
(@)  My second example will be numbered (2).

Explanation of examples.

(@)  My third example will be numbered (3).

Numbered examples can be labeled and referred to elsewhere in the document:

(@good)  This is a good example.

As (@good) illustrates, ...

The label can be any string of alphanumeric characters, underscores, or hyphens.

Compact and loose lists

Pandoc behaves differently from Markdown.pl on some “edge cases” involving lists. Consider this source:

+   First
+   Second:
    -   Fee
    -   Fie
    -   Foe

+   Third

Pandoc transforms this into a “compact list” (with no <p> tags around “First”, “Second”, or “Third”), while Markdown puts <p> tags around “Second” and “Third” (but not “First”), because of the blank space around “Third”. Pandoc follows a simple rule: if the text is followed by a blank line, it is treated as a paragraph. Since “Second” is followed by a list, and not a blank line, it isn’t treated as a paragraph. The fact that the list is followed by a blank line is irrelevant. (Note: Pandoc works this way even when the markdown_strict format is specified. This behavior is consistent with the official Markdown syntax description, even though it is different from that of Markdown.pl.)

Ending a list

What if you want to put an indented code block after a list?

-   item one
-   item two

    { my code block }

Trouble! Here pandoc (like other Markdown implementations) will treat { my code block } as the second paragraph of item two, and not as a code block.

To “cut off” the list after item two, you can insert some non-indented content, like an HTML comment, which won’t produce visible output in any format:

-   item one
-   item two

<!-- end of list -->

    { my code block }

You can use the same trick if you want two consecutive lists instead of one big list:

1.  one
2.  two
3.  three

<!-- -->

1.  uno
2.  dos
3.  tres

Horizontal rules

A line containing a row of three or more *, -, or _ characters (optionally separated by spaces) produces a horizontal rule:

*  *  *  *

---------------

Tables

Four kinds of tables may be used. The first three kinds presuppose the use of a fixed-width font, such as Courier. The fourth kind can be used with proportionally spaced fonts, as it does not require lining up columns.

Extension: table_captions

A caption may optionally be provided with all 4 kinds of tables (as illustrated in the examples below). A caption is a paragraph beginning with the string Table: (or just :), which will be stripped off. It may appear either before or after the table.

Extension: simple_tables

Simple tables look like this:

  Right     Left     Center     Default
-------     ------ ----------   -------
     12     12        12            12
    123     123       123          123
      1     1          1             1

Table:  Demonstration of simple table syntax.

The headers and table rows must each fit on one line. Column alignments are determined by the position of the header text relative to the dashed line below it:4

  • If the dashed line is flush with the header text on the right side but extends beyond it on the left, the column is right-aligned.
  • If the dashed line is flush with the header text on the left side but extends beyond it on the right, the column is left-aligned.
  • If the dashed line extends beyond the header text on both sides, the column is centered.
  • If the dashed line is flush with the header text on both sides, the default alignment is used (in most cases, this will be left).

The table must end with a blank line, or a line of dashes followed by a blank line.

The column headers may be omitted, provided a dashed line is used to end the table. For example:

-------     ------ ----------   -------
     12     12        12             12
    123     123       123           123
      1     1          1              1
-------     ------ ----------   -------

When headers are omitted, column alignments are determined on the basis of the first line of the table body. So, in the tables above, the columns would be right, left, center, and right aligned, respectively.

Extension: multiline_tables

Multiline tables allow headers and table rows to span multiple lines of text (but cells that span multiple columns or rows of the table are not supported). Here is an example:

-------------------------------------------------------------
 Centered   Default           Right Left
  Header    Aligned         Aligned Aligned
----------- ------- --------------- -------------------------
   First    row                12.0 Example of a row that
                                    spans multiple lines.

  Second    row                 5.0 Here's another one. Note
                                    the blank line between
                                    rows.
-------------------------------------------------------------

Table: Here's the caption. It, too, may span
multiple lines.

These work like simple tables, but with the following differences:

  • They must begin with a row of dashes, before the header text (unless the headers are omitted).
  • They must end with a row of dashes, then a blank line.
  • The rows must be separated by blank lines.

In multiline tables, the table parser pays attention to the widths of the columns, and the writers try to reproduce these relative widths in the output. So, if you find that one of the columns is too narrow in the output, try widening it in the Markdown source.

Headers may be omitted in multiline tables as well as simple tables:

----------- ------- --------------- -------------------------
   First    row                12.0 Example of a row that
                                    spans multiple lines.

  Second    row                 5.0 Here's another one. Note
                                    the blank line between
                                    rows.
----------- ------- --------------- -------------------------

: Here's a multiline table without headers.

It is possible for a multiline table to have just one row, but the row should be followed by a blank line (and then the row of dashes that ends the table), or the table may be interpreted as a simple table.

Extension: grid_tables

Grid tables look like this:

: Sample grid table.

+---------------+---------------+--------------------+
| Fruit         | Price         | Advantages         |
+===============+===============+====================+
| Bananas       | $1.34         | - built-in wrapper |
|               |               | - bright color     |
+---------------+---------------+--------------------+
| Oranges       | $2.10         | - cures scurvy     |
|               |               | - tasty            |
+---------------+---------------+--------------------+

The row of =s separates the header from the table body, and can be omitted for a headerless table. The cells of grid tables may contain arbitrary block elements (multiple paragraphs, code blocks, lists, etc.). Cells that span multiple columns or rows are not supported. Grid tables can be created easily using Emacs table mode.

Alignments can be specified as with pipe tables, by putting colons at the boundaries of the separator line after the header:

+---------------+---------------+--------------------+
| Right         | Left          | Centered           |
+==============:+:==============+:==================:+
| Bananas       | $1.34         | built-in wrapper   |
+---------------+---------------+--------------------+

For headerless tables, the colons go on the top line instead:

+--------------:+:--------------+:------------------:+
| Right         | Left          | Centered           |
+---------------+---------------+--------------------+

Extension: pipe_tables

Pipe tables look like this:

| Right | Left | Default | Center |
|------:|:-----|---------|:------:|
|   12  |  12  |    12   |    12  |
|  123  |  123 |   123   |   123  |
|    1  |    1 |     1   |     1  |

  : Demonstration of pipe table syntax.

The syntax is identical to PHP Markdown Extra tables. The beginning and ending pipe characters are optional, but pipes are required between all columns. The colons indicate column alignment as shown. The header cannot be omitted. To simulate a headerless table, include a header with blank cells.

Since the pipes indicate column boundaries, columns need not be vertically aligned, as they are in the above example. So, this is a perfectly legal (though ugly) pipe table:

fruit| price
-----|-----:
apple|2.05
pear|1.37
orange|3.09

The cells of pipe tables cannot contain block elements like paragraphs and lists, and cannot span multiple lines. If a pipe table contains a row whose printable content is wider than the column width (see --columns), then the cell contents will wrap, with the relative cell widths determined by the widths of the separator lines.

Note: pandoc also recognizes pipe tables of the following form, as can be produced by Emacs’ orgtbl-mode:

| One | Two   |
|-----+-------|
| my  | table |
| is  | nice  |

The difference is that + is used instead of |. Other orgtbl features are not supported. In particular, to get non-default column alignment, you’ll need to add colons as above.

Metadata blocks

Extension: pandoc_title_block

If the file begins with a title block

% title
% author(s) (separated by semicolons)
% date

it will be parsed as bibliographic information, not regular text. (It will be used, for example, in the title of standalone LaTeX or HTML output.) The block may contain just a title, a title and an author, or all three elements. If you want to include an author but no title, or a title and a date but no author, you need a blank line:

%
% Author

% My title
%
% June 15, 2006

The title may occupy multiple lines, but continuation lines must begin with leading space, thus:

% My title
  on multiple lines

If a document has multiple authors, the authors may be put on separate lines with leading space, or separated by semicolons, or both. So, all of the following are equivalent:

% Author One
  Author Two

% Author One; Author Two

% Author One;
  Author Two

The date must fit on one line.

All three metadata fields may contain standard inline formatting (italics, links, footnotes, etc.).

Title blocks will always be parsed, but they will affect the output only when the --standalone (-s) option is chosen. In HTML output, titles will appear twice: once in the document head – this is the title that will appear at the top of the window in a browser – and once at the beginning of the document body. The title in the document head can have an optional prefix attached (--title-prefix or -T option). The title in the body appears as an H1 element with class “title”, so it can be suppressed or reformatted with CSS. If a title prefix is specified with -T and no title block appears in the document, the title prefix will be used by itself as the HTML title.

The man page writer extracts a title, man page section number, and other header and footer information from the title line. The title is assumed to be the first word on the title line, which may optionally end with a (single-digit) section number in parentheses. (There should be no space between the title and the parentheses.) Anything after this is assumed to be additional footer and header text. A single pipe character (|) should be used to separate the footer text from the header text. Thus,

% PANDOC(1)

will yield a man page with the title PANDOC and section 1.

% PANDOC(1) Pandoc User Manuals

will also have “Pandoc User Manuals” in the footer.

% PANDOC(1) Pandoc User Manuals | Version 4.0

will also have “Version 4.0” in the header.

Extension: yaml_metadata_block

A YAML metadata block is a valid YAML object, delimited by a line of three hyphens (---) at the top and a line of three hyphens (---) or three dots (...) at the bottom. A YAML metadata block may occur anywhere in the document, but if it is not at the beginning, it must be preceded by a blank line. (Note that, because of the way pandoc concatenates input files when several are provided, you may also keep the metadata in a separate YAML file and pass it to pandoc as an argument, along with your Markdown files:

pandoc chap1.md chap2.md chap3.md metadata.yaml -s -o book.html

Just be sure that the YAML file begins with --- and ends with --- or ....)

Metadata will be taken from the fields of the YAML object and added to any existing document metadata. Metadata can contain lists and objects (nested arbitrarily), but all string scalars will be interpreted as Markdown. Fields with names ending in an underscore will be ignored by pandoc. (They may be given a role by external processors.)

A document may contain multiple metadata blocks. The metadata fields will be combined through a left-biased union: if two metadata blocks attempt to set the same field, the value from the first block will be taken.

When pandoc is used with -t markdown to create a Markdown document, a YAML metadata block will be produced only if the -s/--standalone option is used. All of the metadata will appear in a single block at the beginning of the document.

Note that YAML escaping rules must be followed. Thus, for example, if a title contains a colon, it must be quoted. The pipe character (|) can be used to begin an indented block that will be interpreted literally, without need for escaping. This form is necessary when the field contains blank lines:

---
title:  'This is the title: it contains a colon'
author:
- Author One
- Author Two
tags: [nothing, nothingness]
abstract: |
  This is the abstract.

  It consists of two paragraphs.
...

Template variables will be set automatically from the metadata. Thus, for example, in writing HTML, the variable abstract will be set to the HTML equivalent of the Markdown in the abstract field:

<p>This is the abstract.</p>
<p>It consists of two paragraphs.</p>

Variables can contain arbitrary YAML structures, but the template must match this structure. The author variable in the default templates expects a simple list or string, but can be changed to support more complicated structures. The following combination, for example, would add an affiliation to the author if one is given:

---
title: The document title
author:
- name: Author One
  affiliation: University of Somewhere
- name: Author Two
  affiliation: University of Nowhere
...

To use the structured authors in the example above, you would need a custom template:

$for(author)$
$if(author.name)$
$author.name$$if(author.affiliation)$ ($author.affiliation$)$endif$
$else$
$author$
$endif$
$endfor$

Backslash escapes

Extension: all_symbols_escapable

Except inside a code block or inline code, any punctuation or space character preceded by a backslash will be treated literally, even if it would normally indicate formatting. Thus, for example, if one writes

*\*hello\**

one will get

<em>*hello*</em>

instead of

<strong>hello</strong>

This rule is easier to remember than standard Markdown’s rule, which allows only the following characters to be backslash-escaped:

\`*_{}[]()>#+-.!

(However, if the markdown_strict format is used, the standard Markdown rule will be used.)

A backslash-escaped space is parsed as a nonbreaking space. It will appear in TeX output as ~ and in HTML and XML as \&#160; or \&nbsp;.

A backslash-escaped newline (i.e. a backslash occurring at the end of a line) is parsed as a hard line break. It will appear in TeX output as \\ and in HTML as <br />. This is a nice alternative to Markdown’s “invisible” way of indicating hard line breaks using two trailing spaces on a line.

Backslash escapes do not work in verbatim contexts.

Smart punctuation

Extension

If the --smart option is specified, pandoc will produce typographically correct output, converting straight quotes to curly quotes, --- to em-dashes, -- to en-dashes, and ... to ellipses. Nonbreaking spaces are inserted after certain abbreviations, such as “Mr.”

Note: if your LaTeX template or any included header file call for the [csquotes] package, pandoc will detect this automatically and use \enquote{...} for quoted text.

Inline formatting

Emphasis

To emphasize some text, surround it with *s or _, like this:

This text is _emphasized with underscores_, and this
is *emphasized with asterisks*.

Double * or _ produces strong emphasis:

This is **strong emphasis** and __with underscores__.

A * or _ character surrounded by spaces, or backslash-escaped, will not trigger emphasis:

This is * not emphasized *, and \*neither is this\*.

Extension: intraword_underscores

Because _ is sometimes used inside words and identifiers, pandoc does not interpret a _ surrounded by alphanumeric characters as an emphasis marker. If you want to emphasize just part of a word, use *:

feas*ible*, not feas*able*.

Strikeout

Extension: strikeout

To strikeout a section of text with a horizontal line, begin and end it with ~~. Thus, for example,

This ~~is deleted text.~~

Superscripts and subscripts

Extension: superscript, subscript

Superscripts may be written by surrounding the superscripted text by ^ characters; subscripts may be written by surrounding the subscripted text by ~ characters. Thus, for example,

H~2~O is a liquid.  2^10^ is 1024.

If the superscripted or subscripted text contains spaces, these spaces must be escaped with backslashes. (This is to prevent accidental superscripting and subscripting through the ordinary use of ~ and ^.) Thus, if you want the letter P with ‘a cat’ in subscripts, use P~a\ cat~, not P~a cat~.

Verbatim

To make a short span of text verbatim, put it inside backticks:

What is the difference between `>>=` and `>>`?

If the verbatim text includes a backtick, use double backticks:

Here is a literal backtick `` ` ``.

(The spaces after the opening backticks and before the closing backticks will be ignored.)

The general rule is that a verbatim span starts with a string of consecutive backticks (optionally followed by a space) and ends with a string of the same number of backticks (optionally preceded by a space).

Note that backslash-escapes (and other Markdown constructs) do not work in verbatim contexts:

This is a backslash followed by an asterisk: `\*`.

Extension: inline_code_attributes

Attributes can be attached to verbatim text, just as with fenced code blocks:

`<$>`{.haskell}

Small caps

To write small caps, you can use an HTML span tag:

<span style="font-variant:small-caps;">Small caps</span>

(The semicolon is optional and there may be space after the colon.) This will work in all output formats that support small caps.

Alternatively, you can also use the new bracketed_spans syntax:

[Small caps]{style="font-variant:small-caps;"}

Math

Extension: tex_math_dollars

Anything between two $ characters will be treated as TeX math. The opening $ must have a non-space character immediately to its right, while the closing $ must have a non-space character immediately to its left, and must not be followed immediately by a digit. Thus, $20,000 and $30,000 won’t parse as math. If for some reason you need to enclose text in literal $ characters, backslash-escape them and they won’t be treated as math delimiters.

TeX math will be printed in all output formats. How it is rendered depends on the output format:

Markdown, LaTeX, Emacs Org mode, ConTeXt, ZimWiki
It will appear verbatim between $ characters.
reStructuredText
It will be rendered using an interpreted text role :math:.
AsciiDoc
It will be rendered as latexmath:[...].
Texinfo
It will be rendered inside a @math command.
groff man
It will be rendered verbatim without $’s.
MediaWiki, DokuWiki
It will be rendered inside <math> tags.
Textile
It will be rendered inside <span class="math"> tags.
RTF, OpenDocument, ODT
It will be rendered, if possible, using Unicode characters, and will otherwise appear verbatim.
DocBook
If the --mathml flag is used, it will be rendered using MathML in an inlineequation or informalequation tag. Otherwise it will be rendered, if possible, using Unicode characters.
Docx
It will be rendered using OMML math markup.
FictionBook2
If the --webtex option is used, formulas are rendered as images using CodeCogs or other compatible web service, downloaded and embedded in the e-book. Otherwise, they will appear verbatim.
HTML, Slidy, DZSlides, S5, EPUB

The way math is rendered in HTML will depend on the command-line options selected:

  1. The default is to render TeX math as far as possible using Unicode characters, as with RTF, DocBook, and OpenDocument output. Formulas are put inside a span with class="math", so that they may be styled differently from the surrounding text if needed.

  2. If the --latexmathml option is used, TeX math will be displayed between $ or $$ characters and put in <span> tags with class LaTeX. The [LaTeXMathML] script will be used to render it as formulas. (This trick does not work in all browsers, but it works in Firefox. In browsers that do not support LaTeXMathML, TeX math will appear verbatim between $ characters.)

  3. If the --jsmath option is used, TeX math will be put inside <span> tags (for inline math) or <div> tags (for display math) with class math. The [jsMath] script will be used to render it.

  4. If the --mimetex option is used, the [mimeTeX] CGI script will be called to generate images for each TeX formula. This should work in all browsers. The --mimetex option takes an optional URL as argument. If no URL is specified, it will be assumed that the mimeTeX CGI script is at /cgi-bin/mimetex.cgi.

  5. If the --gladtex option is used, TeX formulas will be enclosed in <eq> tags in the HTML output. The resulting htex file may then be processed by [gladTeX], which will produce image files for each formula and an HTML file with links to these images. So, the procedure is:

    pandoc -s --gladtex myfile.txt -o myfile.htex
    gladtex -d myfile-images myfile.htex
    # produces myfile.html and images in myfile-images
  6. If the --webtex option is used, TeX formulas will be converted to <img> tags that link to an external script that converts formulas to images. The formula will be URL-encoded and concatenated with the URL provided. If no URL is specified, the CodeCogs will be used (https://latex.codecogs.com/png.latex?).

  7. If the --mathjax option is used, TeX math will be displayed between \(...\) (for inline math) or \[...\] (for display math) and put in <span> tags with class math. The [MathJax] script will be used to render it as formulas.

Raw HTML

Extension: raw_html

Markdown allows you to insert raw HTML (or DocBook) anywhere in a document (except verbatim contexts, where <, >, and & are interpreted literally). (Technically this is not an extension, since standard Markdown allows it, but it has been made an extension so that it can be disabled if desired.)

The raw HTML is passed through unchanged in HTML, S5, Slidy, Slideous, DZSlides, EPUB, Markdown, Emacs Org mode, and Textile output, and suppressed in other formats.

Extension: markdown_in_html_blocks

Standard Markdown allows you to include HTML “blocks”: blocks of HTML between balanced tags that are separated from the surrounding text with blank lines, and start and end at the left margin. Within these blocks, everything is interpreted as HTML, not Markdown; so (for example), * does not signify emphasis.

Pandoc behaves this way when the markdown_strict format is used; but by default, pandoc interprets material between HTML block tags as Markdown. Thus, for example, pandoc will turn

<table>
<tr>
<td>*one*</td>
<td>[a link](http://google.com)</td>
</tr>
</table>

into

<table>
<tr>
<td><em>one</em></td>
<td><a href="http://google.com">a link</a></td>
</tr>
</table>

whereas Markdown.pl will preserve it as is.

There is one exception to this rule: text between <script> and <style> tags is not interpreted as Markdown.

This departure from standard Markdown should make it easier to mix Markdown with HTML block elements. For example, one can surround a block of Markdown text with <div> tags without preventing it from being interpreted as Markdown.

Extension: native_divs

Use native pandoc Div blocks for content inside <div> tags. For the most part this should give the same output as markdown_in_html_blocks, but it makes it easier to write pandoc filters to manipulate groups of blocks.

Extension: native_spans

Use native pandoc Span blocks for content inside <span> tags. For the most part this should give the same output as raw_html, but it makes it easier to write pandoc filters to manipulate groups of inlines.

Raw TeX

Extension: raw_tex

In addition to raw HTML, pandoc allows raw LaTeX, TeX, and ConTeXt to be included in a document. Inline TeX commands will be preserved and passed unchanged to the LaTeX and ConTeXt writers. Thus, for example, you can use LaTeX to include BibTeX citations:

This result was proved in \cite{jones.1967}.

Note that in LaTeX environments, like

\begin{tabular}{|l|l|}\hline
Age & Frequency \\ \hline
18--25  & 15 \\
26--35  & 33 \\
36--45  & 22 \\ \hline
\end{tabular}

the material between the begin and end tags will be interpreted as raw LaTeX, not as Markdown.

Inline LaTeX is ignored in output formats other than Markdown, LaTeX, Emacs Org mode, and ConTeXt.

LaTeX macros

Extension: latex_macros

For output formats other than LaTeX, pandoc will parse LaTeX \newcommand and \renewcommand definitions and apply the resulting macros to all LaTeX math. So, for example, the following will work in all output formats, not just LaTeX:

\newcommand{\tuple}[1]{\langle #1 \rangle}

$\tuple{a, b, c}$

In LaTeX output, the \newcommand definition will simply be passed unchanged to the output.

Markdown allows links to be specified in several ways.

If you enclose a URL or email address in pointy brackets, it will become a link:

<http://google.com>
<sam@green.eggs.ham>

An inline link consists of the link text in square brackets, followed by the URL in parentheses. (Optionally, the URL can be followed by a link title, in quotes.)

This is an [inline link](/url), and here's [one with
a title](http://fsf.org "click here for a good time!").

There can be no space between the bracketed part and the parenthesized part. The link text can contain formatting (such as emphasis), but the title cannot.

Email addresses in inline links are not autodetected, so they have to be prefixed with mailto:

[Write me!](mailto:sam@green.eggs.ham)

An explicit reference link has two parts, the link itself and the link definition, which may occur elsewhere in the document (either before or after the link).

The link consists of link text in square brackets, followed by a label in square brackets. (There can be space between the two.) The link definition consists of the bracketed label, followed by a colon and a space, followed by the URL, and optionally (after a space) a link title either in quotes or in parentheses. The label must not be parseable as a citation (assuming the citations extension is enabled): citations take precedence over link labels.

Here are some examples:

[my label 1]: /foo/bar.html  "My title, optional"
[my label 2]: /foo
[my label 3]: http://fsf.org (The free software foundation)
[my label 4]: /bar#special  'A title in single quotes'

The URL may optionally be surrounded by angle brackets:

[my label 5]: <http://foo.bar.baz>

The title may go on the next line:

[my label 3]: http://fsf.org
  "The free software foundation"

Note that link labels are not case sensitive. So, this will work:

Here is [my link][FOO]

[Foo]: /bar/baz

In an implicit reference link, the second pair of brackets is empty:

See [my website][].

[my website]: http://foo.bar.baz

Note: In Markdown.pl and most other Markdown implementations, reference link definitions cannot occur in nested constructions such as list items or block quotes. Pandoc lifts this arbitrary seeming restriction. So the following is fine in pandoc, though not in most other implementations:

> My block [quote].
>
> [quote]: /foo

In a shortcut reference link, the second pair of brackets may be omitted entirely:

See [my website].

[my website]: http://foo.bar.baz

To link to another section of the same document, use the automatically generated identifier (see Header identifiers). For example:

See the [Introduction](#introduction).

or

See the [Introduction].

[Introduction]: #introduction

Internal links are currently supported for HTML formats (including HTML slide shows and EPUB), LaTeX, and ConTeXt.

Images

A link immediately preceded by a ! will be treated as an image. The link text will be used as the image’s alt text:

![la lune](lalune.jpg "Voyage to the moon")

![movie reel]

[movie reel]: movie.gif

Extension: implicit_figures

An image occurring by itself in a paragraph will be rendered as a figure with a caption.5 (In LaTeX, a figure environment will be used; in HTML, the image will be placed in a div with class figure, together with a caption in a p with class caption.) The image’s alt text will be used as the caption.

![This is the caption](/url/of/image.png)

If you just want a regular inline image, just make sure it is not the only thing in the paragraph. One way to do this is to insert a nonbreaking space after the image:

![This image won't be a figure](/url/of/image.png)\ 

Attributes can be set on links and images:

An inline ![image](foo.jpg){#id .class width=30 height=20px}
and a reference ![image][ref] with attributes.

[ref]: foo.jpg "optional title" {#id .class key=val key2="val 2"}

(This syntax is compatible with PHP Markdown Extra when only #id and .class are used.)

For HTML and EPUB, all attributes except width and height (but including srcset and sizes) are passed through as is. The other writers ignore attributes that are not supported by their output format.

The width and height attributes on images are treated specially. When used without a unit, the unit is assumed to be pixels. However, any of the following unit identifiers can be used: px, cm, mm, in, inch and %. There must not be any spaces between the number and the unit. For example:

![](file.jpg){ width=50% }
  • Dimensions are converted to inches for output in page-based formats like LaTeX. Dimensions are converted to pixels for output in HTML-like formats. Use the --dpi option to specify the number of pixels per inch. The default is 96dpi.
  • The % unit is generally relative to some available space. For example the above example will render to <img href="file.jpg" style="width: 50%;" /> (HTML), \includegraphics[width=0.5\textwidth]{file.jpg} (LaTeX), or \externalfigure[file.jpg][width=0.5\textwidth] (ConTeXt).
  • Some output formats have a notion of a class (ConTeXt) or a unique identifier (LaTeX \caption), or both (HTML).
  • When no width or height attributes are specified, the fallback is to look at the image resolution and the dpi metadata embedded in the image file.

Spans

Extension: bracketed_spans

A bracketed sequence of inlines, as one would use to begin a link, will be treated as a span with attributes if it is followed immediately by attributes:

[This is *some text*]{.class key="val"}

Footnotes

Extension: footnotes

Pandoc’s Markdown allows footnotes, using the following syntax:

Here is a footnote reference,[^1] and another.[^longnote]

[^1]: Here is the footnote.

[^longnote]: Here's one with multiple blocks.

    Subsequent paragraphs are indented to show that they
belong to the previous footnote.

        { some.code }

    The whole paragraph can be indented, or just the first
    line.  In this way, multi-paragraph footnotes work like
    multi-paragraph list items.

This paragraph won't be part of the note, because it
isn't indented.

The identifiers in footnote references may not contain spaces, tabs, or newlines. These identifiers are used only to correlate the footnote reference with the note itself; in the output, footnotes will be numbered sequentially.

The footnotes themselves need not be placed at the end of the document. They may appear anywhere except inside other block elements (lists, block quotes, tables, etc.). Each footnote should be separated from surrounding content (including other footnotes) by blank lines.

Extension: inline_notes

Inline footnotes are also allowed (though, unlike regular notes, they cannot contain multiple paragraphs). The syntax is as follows:

Here is an inline note.^[Inlines notes are easier to write, since
you don't have to pick an identifier and move down to type the
note.]

Inline and regular footnotes may be mixed freely.

Citations

Extension: citations

Using an external filter, pandoc-citeproc, pandoc can automatically generate citations and a bibliography in a number of styles. Basic usage is

pandoc --filter pandoc-citeproc myinput.txt

In order to use this feature, you will need to specify a bibliography file using the bibliography metadata field in a YAML metadata section, or --bibliography command line argument. You can supply multiple --bibliography arguments or set bibliography metadata field to YAML array, if you want to use multiple bibliography files. The bibliography may have any of these formats:

Format File extension
BibLaTeX .bib
BibTeX .bibtex
Copac .copac
CSL JSON .json
CSL YAML .yaml
EndNote .enl
EndNote XML .xml
ISI .wos
MEDLINE .medline
MODS .mods
RIS .ris

Note that .bib can be used with both BibTeX and BibLaTeX files; use .bibtex to force BibTeX.

Note that pandoc-citeproc --bib2json and pandoc-citeproc --bib2yaml can produce .json and .yaml files from any of the supported formats.

In-field markup: In BibTeX and BibLaTeX databases, pandoc-citeproc parses a subset of LaTeX markup; in CSL YAML databases, pandoc Markdown; and in CSL JSON databases, an HTML-like markup:

<i>...</i>
italics
<b>...</b>
bold
<span style="font-variant:small-caps;">...</span> or <sc>...</sc>
small capitals
<sub>...</sub>
subscript
<sup>...</sup>
superscript
<span class="nocase">...</span>
prevent a phrase from being capitalized as title case

pandoc-citeproc -j and -y interconvert the CSL JSON and CSL YAML formats as far as possible.

As an alternative to specifying a bibliography file using --bibliography or the YAML metadata field bibliography, you can include the citation data directly in the references field of the document’s YAML metadata. The field should contain an array of YAML-encoded references, for example:

---
references:
- type: article-journal
  id: WatsonCrick1953
  author:
  - family: Watson
    given: J. D.
  - family: Crick
    given: F. H. C.
  issued:
    date-parts:
    - - 1953
      - 4
      - 25
  title: 'Molecular structure of nucleic acids: a structure for deoxyribose
    nucleic acid'
  title-short: Molecular structure of nucleic acids
  container-title: Nature
  volume: 171
  issue: 4356
  page: 737-738
  DOI: 10.1038/171737a0
  URL: http://www.nature.com/nature/journal/v171/n4356/abs/171737a0.html
  language: en-GB
...

(pandoc-citeproc --bib2yaml can produce these from a bibliography file in one of the supported formats.)

Citations and references can be formatted using any style supported by the Citation Style Language, listed in the Zotero Style Repository. These files are specified using the --csl option or the csl metadata field. By default, pandoc-citeproc will use the Chicago Manual of Style author-date format. The CSL project provides further information on finding and editing styles.

To make your citations hyperlinks to the corresponding bibliography entries, add link-citations: true to your YAML metadata.

Citations go inside square brackets and are separated by semicolons. Each citation must have a key, composed of ‘@’ + the citation identifier from the database, and may optionally have a prefix, a locator, and a suffix. The citation key must begin with a letter, digit, or _, and may contain alphanumerics, _, and internal punctuation characters (:.#$%&-+?<>~/). Here are some examples:

Blah blah [see @doe99, pp. 33-35; also @smith04, chap. 1].

Blah blah [@doe99, pp. 33-35, 38-39 and *passim*].

Blah blah [@smith04; @doe99].

pandoc-citeproc detects locator terms in the CSL locale files. Either abbreviated or unabbreviated forms are accepted. In the en-US locale, locator terms can be written in either singular or plural forms, as book, bk./bks.; chapter, chap./chaps.; column, col./cols.; figure, fig./figs.; folio, fol./fols.; number, no./nos.; line, l./ll.; note, n./nn.; opus, op./opp.; page, p./pp.; paragraph, para./paras.; part, pt./pts.; section, sec./secs.; sub verbo, s.v./s.vv.; verse, v./vv.; volume, vol./vols.; /¶¶; §/§§. If no locator term is used, “page” is assumed.

A minus sign (-) before the @ will suppress mention of the author in the citation. This can be useful when the author is already mentioned in the text:

Smith says blah [-@smith04].

You can also write an in-text citation, as follows:

@smith04 says blah.

@smith04 [p. 33] says blah.

If the style calls for a list of works cited, it will be placed at the end of the document. Normally, you will want to end your document with an appropriate header:

last paragraph...

# References

The bibliography will be inserted after this header. Note that the unnumbered class will be added to this header, so that the section will not be numbered.

If you want to include items in the bibliography without actually citing them in the body text, you can define a dummy nocite metadata field and put the citations there:

---
nocite: |
  @item1, @item2
...

@item3

In this example, the document will contain a citation for item3 only, but the bibliography will contain entries for item1, item2, and item3.

It is possible to create a bibliography with all the citations, whether or not they appear in the document, by using a wildcard:

---
nocite: |
  @*
...

For LaTeX or PDF output, you can also use [natbib] or [biblatex] to render bibliography. In order to do so, specify bibliography files as outlined above, and add --natbib or --biblatex argument to pandoc invocation. Bear in mind that bibliography files have to be in respective format (either BibTeX or BibLaTeX).

For more information, see the pandoc-citeproc man page.

Non-pandoc extensions

The following Markdown syntax extensions are not enabled by default in pandoc, but may be enabled by adding +EXTENSION to the format name, where EXTENSION is the name of the extension. Thus, for example, markdown+hard_line_breaks is Markdown with hard line breaks.

Extension: angle_brackets_escapable

Allow < and > to be backslash-escaped, as they can be in GitHub flavored Markdown but not original Markdown. This is implied by pandoc’s default all_symbols_escapable.

Extension: lists_without_preceding_blankline

Allow a list to occur right after a paragraph, with no intervening blank space.

Extension: hard_line_breaks

Causes all newlines within a paragraph to be interpreted as hard line breaks instead of spaces.

Extension: ignore_line_breaks

Causes newlines within a paragraph to be ignored, rather than being treated as spaces or as hard line breaks. This option is intended for use with East Asian languages where spaces are not used between words, but text is divided into lines for readability.

Extension: east_asian_line_breaks

Causes newlines within a paragraph to be ignored, rather than being treated as spaces or as hard line breaks, when they occur between two East Asian wide characters. This is a better choice than ignore_line_breaks for texts that include a mix of East Asian wide characters and other characters.

Extension: emoji

Parses textual emojis like :smile: as Unicode emoticons.

Extension: tex_math_single_backslash

Causes anything between \( and \) to be interpreted as inline TeX math, and anything between \[ and \] to be interpreted as display TeX math. Note: a drawback of this extension is that it precludes escaping ( and [.

Extension: tex_math_double_backslash

Causes anything between \\( and \\) to be interpreted as inline TeX math, and anything between \\[ and \\] to be interpreted as display TeX math.

Extension: markdown_attribute

By default, pandoc interprets material inside block-level tags as Markdown. This extension changes the behavior so that Markdown is only parsed inside block-level tags if the tags have the attribute markdown=1.

Extension: mmd_title_block

Enables a MultiMarkdown style title block at the top of the document, for example:

Title:   My title
Author:  John Doe
Date:    September 1, 2008
Comment: This is a sample mmd title block, with
         a field spanning multiple lines.

See the MultiMarkdown documentation for details. If pandoc_title_block or yaml_metadata_block is enabled, it will take precedence over mmd_title_block.

Extension: abbreviations

Parses PHP Markdown Extra abbreviation keys, like

*[HTML]: Hypertext Markup Language

Note that the pandoc document model does not support abbreviations, so if this extension is enabled, abbreviation keys are simply skipped (as opposed to being parsed as paragraphs).

Makes all absolute URIs into links, even when not surrounded by pointy braces <...>.

Extension: ascii_identifiers

Causes the identifiers produced by auto_identifiers to be pure ASCII. Accents are stripped off of accented Latin letters, and non-Latin letters are omitted.

Parses multimarkdown style key-value attributes on link and image references. This extension should not be confused with the link_attributes extension.

This is a reference ![image][ref] with multimarkdown attributes.

[ref]: http://path.to/image "Image title" width=20px height=30px
       id=myId class="myClass1 myClass2"

Extension: mmd_header_identifiers

Parses multimarkdown style header identifiers (in square brackets, after the header but before any trailing #s in an ATX header).

Extension: compact_definition_lists

Activates the definition list syntax of pandoc 1.12.x and earlier. This syntax differs from the one described above under Definition lists in several respects:

  • No blank line is required between consecutive items of the definition list.
  • To get a “tight” or “compact” list, omit space between consecutive items; the space between a term and its definition does not affect anything.
  • Lazy wrapping of paragraphs is not allowed: the entire definition must be indented four spaces.6

Extensions with formats other than Markdown

Some of the extensions discussed above can be used with formats other than Markdown:

  • auto_identifiers can be used with latex, rst, mediawiki, and textile input (and is used by default).

  • tex_math_dollars, tex_math_single_backslash, and tex_math_double_backslash can be used with html input. (This is handy for reading web pages formatted using MathJax, for example.)

Markdown 免费编辑器

Windows 平台

Linux 平台

Mac 平台

在线编辑器

浏览器插件

高级应用

*** 如有更好的 Markdown 免费编辑器推荐,请到这里反馈,谢谢!


  1. To make subtitle work with other LaTeX document classes, you can add the following to header-includes:

    \providecommand{\subtitle}[1]{%
      \usepackage{titling}
      \posttitle{%
        \par\large#1\end{center}}
    }
  2. The point of this rule is to ensure that normal paragraphs starting with people’s initials, like

    B. Russell was an English philosopher.

    do not get treated as list items.

    This rule will not prevent

    (C) 2007 Joe Smith

    from being interpreted as a list item. In this case, a backslash escape can be used:

    (C\) 2007 Joe Smith
  3. I have been influenced by the suggestions of David Wheeler.

  4. This scheme is due to Michel Fortin, who proposed it on the Markdown discussion list.

  5. This feature is not yet implemented for RTF, OpenDocument, or ODT. In those formats, you’ll just get an image in a paragraph by itself, with no caption.

  6. To see why laziness is incompatible with relaxing the requirement of a blank line between items, consider the following example:

    bar
    :    definition
    foo
    :    definition

    Is this a single list item with two definitions of “bar,” the first of which is lazily wrapped, or two list items? To remove the ambiguity we must either disallow lazy wrapping or require a blank line between list items.