• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1Fenced Code Blocks
2==================
3
4Summary
5-------
6
7This extension adds a secondary way to define code blocks which overcomes a few
8limitations of the indented code blocks.
9
10This extension is included in the standard Markdown library.
11
12Syntax
13------
14
15Fenced Code Blocks are defined using the syntax established in
16[PHP Markdown Extra][php].
17
18[php]: http://www.michelf.com/projects/php-markdown/extra/#fenced-code-blocks
19
20Thus, the following text (taken from the above referenced PHP documentation):
21
22    This is a paragraph introducing:
23
24    ~~~~~~~~~~~~~~~~~~~~
25    a one-line code block
26    ~~~~~~~~~~~~~~~~~~~~
27
28Fenced code blocks can have a blank line as the first  and/or last line of a
29code block and they can also come immediately after a list item without becoming
30part of the list.
31
32In addition to PHP Extra's syntax, you can define the language of the code
33block for use by syntax highlighters etc. The language will be assigned as a
34class attribute of the ``<code>`` element in the output. Therefore, you should
35define the language as you would a css class - ``.language``. For consistency
36with other markdown syntax, the language can *optionally* be wrapped in curly
37brackets:
38
39    ~~~~{.python}
40    # python code
41    ~~~~
42
43    ~~~~.html
44    <p>HTML Document</p>
45    ~~~~
46
47The above will output:
48
49    <pre><code class="python"># python code
50    </code></pre>
51
52    <pre><code class="html">&lt;p&gt;HTML Document&lt;/p&gt;
53    </code></pre>
54
55Usage
56-----
57
58From the Python interpreter:
59
60    >>> html = markdown.markdown(text, ['fenced_code'])
61
62
63
64