1 Fenced Code Blocks 2 ================== 3 4 Summary 5 ------- 6 7 This extension adds a secondary way to define code blocks which overcomes a few 8 limitations of the indented code blocks. 9 10 This extension is included in the standard Markdown library. 11 12 Syntax 13 ------ 14 15 Fenced 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 20 Thus, 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 28 Fenced code blocks can have a blank line as the first and/or last line of a 29 code block and they can also come immediately after a list item without becoming 30 part of the list. 31 32 In addition to PHP Extra's syntax, you can define the language of the code 33 block for use by syntax highlighters etc. The language will be assigned as a 34 class attribute of the ``<code>`` element in the output. Therefore, you should 35 define the language as you would a css class - ``.language``. For consistency 36 with other markdown syntax, the language can *optionally* be wrapped in curly 37 brackets: 38 39 ~~~~{.python} 40 # python code 41 ~~~~ 42 43 ~~~~.html 44 <p>HTML Document</p> 45 ~~~~ 46 47 The above will output: 48 49 <pre><code class="python"># python code 50 </code></pre> 51 52 <pre><code class="html"><p>HTML Document</p> 53 </code></pre> 54 55 Usage 56 ----- 57 58 From the Python interpreter: 59 60 >>> html = markdown.markdown(text, ['fenced_code']) 61 62 63 64