Thursday, May 23, 2013

Pandoc's Markdown Reference

Pandoc's Markdown Reference

Pandoc實現了基本的Markdown語法外, 還加了一些extention.
細節可參考:
Pandoc's Markdown
Markdown語法
Markdown:Syntax
Pandoc Markdown and ReST Compared

Headers (Setext and atx)

Setext-style只有兩階也就是HTML語法裡的h1h2 tag,-=的個數沒有限制.

atx-style共有6階, h1~h6.

# This is H1.
## This is H2.
### This is H3.
#### ...  
###### This is H6.  

除了階層較多之外, atx-style還可以使用Markdown syntax.

###This is *H3* header.

Output:

This is H3 header.

Inline Formatting

Basic Emphasis

斜體字: *, _ , 粗體字: **, __,

*single asterisks*  
_single underscores_  
**double asterisks**  
__double underscores__  

Output:

single asterisks
single underscores
double asterisks
double underscores


Pandoc Inline

strikeout, superscript and subscript

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

Output:

deleted text
H2O is a liquid.
210 is 1024.


Math

Pandoc可以使用LaTeX來表示數學式子, 可參考Getting Started with LaTeX

$a^2 = b^2 + c^2$  
$x^{17} - 1$  
$M^\bot = \{ f \in V' : f(m) = 0 \mbox{ for all } m \in M \}.$  
$\[ \cos(\theta + \phi) = \cos \theta \cos \phi - \sin \theta \sin \phi \]$  
$\[ |y - x| < \delta \]$ then $\[ |f(y) - f(x)| < \epsilon. \]$  
\newcommand{\tuple}[1]{\langle #1 \rangle}  
$\tuple{a, b, c}$  

output:

a2 = b2 + c2
x17 − 1
M = {f ∈ Vʹ: f(m) = 0for all m ∈ M}. 
[cos(θ + φ) = cosθcosφ − sinθsinφ]
[∣y − x∣ < δ] then [∣f(y) − f(x)∣ < ε. ]

a, b, c

This is an automatic link <http://www.google.com>.  
This is [inline link](http://example.com/ "Title") inline link with title.  
This is [inline link](http://example.com/ ) inline link without title attribute.  
This is [reference link ][ref] with ID.  
This is [reference link][] without ID.  
This is [Inline Internal link](#TOC).  
This is [Internal link].  

[ref]: http://example.com/  
[reference link]: http://www.google.com  
[Internal link]: #pandocs-markdown-reference  

Output:

This is an automatic link http://www.google.com.
This is inline link inline link with title.
This is inline link inline link without title attribute.
This is reference link with ID.
This is reference link without ID.
This is Inline Internal link.
This is Internal link.

Images

Markddown images sytax

![](http://3.bp.bloGspot.com/-BLhmfBdELH0/UBT3uUd7r5I/AAAAAAAAADw/-rnn2kz5vjY/s220/oops_monk01_120.jpg "OopsMonk")

![Alt text][pic2]

[pic2]: http://3.bp.bloGspot.com/-BLhmfBdELH0/UBT3uUd7r5I/AAAAAAAAADw/-rnn2kz5vjY/s220/oops_monk01_120.jpg  

Output:

Alt text

Alt text


Markdown的貼圖不能指定圖片大小, 可以用HTML來放圖片.

<img src="http://3.bp.bloGspot.com/-BLhmfBdELH0/UBT3uUd7r5I/AAAAAAAAADw/-rnn2kz5vjY/s220/oops_monk01_120.jpg" width="50">

Output:

Embedded Video

Markdown沒有嵌入影片的語法, 需要使用HTML.

<iframe src="http://embed.ted.com/talks/lang/zh-tw/ken_robinson_how_to_escape_education_s_death_valley.html"
width="560" height="315" frameborder="0" scrolling="no" 
webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>

Output:

Code block

Basic Code block

This is one line code block `function()`   
``There is a literal backtick (`) here.``  
Bellow is a code block:  

    if(x == 0){
        printf("x = 0");
    else
        printf("x =/= 0");

Output:

This is one line code block function()
There is a literal backtick (`) here.
Bellow is a code block:

if(x == 0){
    printf("x = 0");
else
    printf("x =/= 0");

Pandoc Code Block

Force code block(more then three ~)

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

Output

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

Code Syntax highlight

```python
import os
import sys

def application(env, start_response):  
    start_response('200 OK', [('Content-Type','text/html')])  
    return "Hello WSGI!!"
```

Output:

import os
import sys

def application(env, start_response):  
    start_response('200 OK', [('Content-Type','text/html')])  
    return "Hello WSGI!!"

Line Number

~~~~ {#pycode .python .numberLines startFrom="10"}
import os
import sys

def application(env, start_response):  
    start_response('200 OK', [('Content-Type','text/html')])  
    return "Hello WSGI!!"
~~~~

Output:

10
11
12
13
14
15
import os
import sys

def application(env, start_response):  
    start_response('200 OK', [('Content-Type','text/html')])  
    return "Hello WSGI!!"

Blockquotes

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

Output:

This is a block quote.

A block quote within a block quote.

Nets.

Lists

Basic list

Unordered(Bulleted)

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

Output:

  • fruits
    • apples
      • macintosh
      • red delicious
    • pears
    • peaches
  • vegetables
    • brocolli

Ordered (Numbered)

1. list1.
1. list2.
1. list3.
1. list4.

Output:

  1. list1.
  2. list2.
  3. list3.
  4. list4.

Pandoc List Extension

startnum

5) Five
    i. 5-1
    i. 5-2
5) Six
    iii. 6-1
        * 6-1-1
        * 6-1-2
    iii. 6-2
    iii. 6-3
5) Seven
    a. 7-1
    i. 7-2
        #. 7-2-1
        #. 7-2-2
    i. 7-3

<!-- -->

5) Five again.  

Output:

  1. Five
    1. 5-1
    2. 5-2
  2. Six
    1. 6-1
      • 6-1-1
      • 6-1-2
    2. 6-2
    3. 6-3
  3. Seven
    1. 7-1
    2. 7-2
      1. 7-2-1
      2. 7-2-2
    3. 7-3
  1. Five again.

Definition lists

語法中為:Definition之間為 TAB 鍵.

Term 1

:   Definition 1

Term 2 with *inline markup*

:   Definition 2

        { some code, part of Definition 2 }

    Third paragraph of definition 2.

Output:

Term 1

Definition 1

Term 2 with inline markup

Definition 2

{ some code, part of Definition 2 }

Third paragraph of definition 2.


另一種寫法, 裡面無法放入code block.

Term 1
  ~ Definition 1
Term 2
  ~ Definition 2a  
  ~ Definition 2b

Output:

Term 1
Definition 1
Term 2
Definition 2a
Definition 2b

Example lists

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

Explanation of examples.

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

(@good)  This is a good example.

As (@good) illustrates, ...  

Output:

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

Explanation of examples.

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

  2. This is a good example.

As (4) illustrates, ...

Pandoc Footnotes

註解會出現在文章的最後面.

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.]  

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.

Output:

Here is an inline note.1

Here is a footnote reference,[2] and another.3

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

Pandoc Table

標準的Markdown沒有實現表格的標示.

Simple tables

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

Output:

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

Multiline tables

--------------------------
 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.
--------------------------

Output:

Centered Header Default Aligned Right Aligned Left 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.

----------- ------- --------------- -------------------------
   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.
----------- ------- --------------- -------------------------

Output:

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.

This is end of article, show defined footnotes as below:


  1. Inlines notes are easier to write, since you don't have to pick an identifier and move down to type the note.

  2. Here is the footnote.

  3. 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.

No comments:

Post a Comment