diff options
-rw-r--r-- | markdown/extensions/fenced_code.py | 4 | ||||
-rw-r--r-- | tests/extensions/fenced_code_blocks.html | 70 | ||||
-rw-r--r-- | tests/extensions/fenced_code_blocks.txt | 80 | ||||
-rw-r--r-- | tests/extensions/test.cfg | 6 |
4 files changed, 158 insertions, 2 deletions
diff --git a/markdown/extensions/fenced_code.py b/markdown/extensions/fenced_code.py index e5b3350..87cdfc8 100644 --- a/markdown/extensions/fenced_code.py +++ b/markdown/extensions/fenced_code.py @@ -49,6 +49,8 @@ Language tags: <pre><code class="python"># Some python code </code></pre> +Optionally backticks instead of tildes as per how github's code block markdown is identified. + Copyright 2007-2008 [Waylan Limberg](http://achinghead.com/). Project website: <http://www.freewisdom.org/project/python-markdown/Fenced__Code__Blocks> @@ -69,7 +71,7 @@ from markdown.extensions.codehilite import CodeHilite, CodeHiliteExtension # Global vars FENCED_BLOCK_RE = re.compile( \ - r'(?P<fence>^~{3,})[ ]*(\{?\.(?P<lang>[a-zA-Z0-9_-]*)\}?)?[ ]*\n(?P<code>.*?)(?P=fence)[ ]*$', + r'(?P<fence>^(?:~{3,}|`{3,}))[ ]*(\{?\.(?P<lang>[a-zA-Z0-9_-]*)\}?)?[ ]*\n(?P<code>.*?)(?P=fence)[ ]*$', re.MULTILINE|re.DOTALL ) CODE_WRAP = '<pre><code%s>%s</code></pre>' diff --git a/tests/extensions/fenced_code_blocks.html b/tests/extensions/fenced_code_blocks.html new file mode 100644 index 0000000..4a0a625 --- /dev/null +++ b/tests/extensions/fenced_code_blocks.html @@ -0,0 +1,70 @@ +Xo<pre><code>Fenced +</code></pre> + +<p>Code block starting and ending with empty lines:</p> + +<pre><code><br /><br />Fenced + + +</code></pre> + +<p>Indented code block containing fenced code block sample:</p> + +<pre><code>~~~ +Fenced +~~~ +</code></pre> + +<p>Fenced code block with indented code block sample:</p> + +<pre><code>Some text + + Indented code block sample code +</code></pre> + +<p>Fenced code block with long markers:</p> + +<pre><code>Fenced +</code></pre> + +<p>Fenced code block with fenced code block markers of different length in it:</p> + +<pre><code>In code block +~~~ +Still in code block +~~~~~ +Still in code block +</code></pre> + +<p>Fenced code block with Markdown header and horizontal rule:</p> + +<pre><code>#test +--- +</code></pre> + +<p>Fenced code block with link definitions, footnote definition and +abbreviation definitions:</p> + +<pre><code>[example]: http://example.com/ + +[^1]: Footnote def + +*[HTML]: HyperText Markup Language +</code></pre> + +<pre><code>[example]: http://backticks.com/ + +[^1]: Footnote def + +*[HTML]: HyperText Markup Language +</code></pre> + +<pre><code>testing tildes in backticks + +~~~ +</code></pre> + +<pre><code>testing tildes in backticks + +``` +</code></pre> diff --git a/tests/extensions/fenced_code_blocks.txt b/tests/extensions/fenced_code_blocks.txt new file mode 100644 index 0000000..be0f997 --- /dev/null +++ b/tests/extensions/fenced_code_blocks.txt @@ -0,0 +1,80 @@ +~~~ +Fenced +~~~ + +Code block starting and ending with empty lines: +~~~ + + +Fenced + + +~~~ + +Indented code block containing fenced code block sample: + + ~~~ + Fenced + ~~~ + +Fenced code block with indented code block sample: + +~~~ +Some text + + Indented code block sample code +~~~ + +Fenced code block with long markers: + +~~~~~~~~~~~~~~~~~~ +Fenced +~~~~~~~~~~~~~~~~~~ + +Fenced code block with fenced code block markers of different length in it: + +~~~~ +In code block +~~~ +Still in code block +~~~~~ +Still in code block +~~~~ + +Fenced code block with Markdown header and horizontal rule: + +~~~ +#test +--- +~~~ + +Fenced code block with link definitions, footnote definition and +abbreviation definitions: + +~~~ +[example]: http://example.com/ + +[^1]: Footnote def + +*[HTML]: HyperText Markup Language +~~~ + +``` +[example]: http://backticks.com/ + +[^1]: Footnote def + +*[HTML]: HyperText Markup Language +``` + +````` +testing tildes in backticks + +~~~ +````` + +~~~ +testing backticks in tildes + +``` +~~~ diff --git a/tests/extensions/test.cfg b/tests/extensions/test.cfg index 671f2a5..c271b02 100644 --- a/tests/extensions/test.cfg +++ b/tests/extensions/test.cfg @@ -4,7 +4,7 @@ extensions=attr_list [codehilite] extensions=codehilite # This passes or not based on version of pygments. -skip=1 +skip=1 [toc] extensions=toc @@ -20,3 +20,7 @@ extensions=toc [wikilinks] extensions=wikilinks + +[fenced_code_blocks] +extensions=fenced_code +normalize=1 |