| 1 |
""" |
| 2 |
Python Markdown |
| 3 |
|
| 4 |
A Python implementation of John Gruber's Markdown. |
| 5 |
|
| 6 |
Documentation: https://python-markdown.github.io/ |
| 7 |
GitHub: https://github.com/Python-Markdown/markdown/ |
| 8 |
PyPI: https://pypi.org/project/Markdown/ |
| 9 |
|
| 10 |
Started by Manfred Stienstra (http://www.dwerg.net/). |
| 11 |
Maintained for a few years by Yuri Takhteyev (http://www.freewisdom.org). |
| 12 |
Currently maintained by Waylan Limberg (https://github.com/waylan), |
| 13 |
Dmitry Shachnev (https://github.com/mitya57) and Isaac Muse (https://github.com/facelessuser). |
| 14 |
|
| 15 |
Copyright 2007-2023 The Python Markdown Project (v. 1.7 and later) |
| 16 |
Copyright 2004, 2005, 2006 Yuri Takhteyev (v. 0.2-1.6b) |
| 17 |
Copyright 2004 Manfred Stienstra (the original version) |
| 18 |
|
| 19 |
License: BSD (see LICENSE.md for details). |
| 20 |
""" |
| 21 |
|
| 22 |
from markdown.test_tools import TestCase |
| 23 |
|
| 24 |
|
| 25 |
class TestCodeBlocks(TestCase): |
| 26 |
|
| 27 |
def test_spaced_codeblock(self): |
| 28 |
self.assertMarkdownRenders( |
| 29 |
' # A code block.', |
| 30 |
|
| 31 |
self.dedent( |
| 32 |
""" |
| 33 |
<pre><code># A code block. |
| 34 |
</code></pre> |
| 35 |
""" |
| 36 |
) |
| 37 |
) |
| 38 |
|
| 39 |
def test_tabbed_codeblock(self): |
| 40 |
self.assertMarkdownRenders( |
| 41 |
'\t# A code block.', |
| 42 |
|
| 43 |
self.dedent( |
| 44 |
""" |
| 45 |
<pre><code># A code block. |
| 46 |
</code></pre> |
| 47 |
""" |
| 48 |
) |
| 49 |
) |
| 50 |
|
| 51 |
def test_multiline_codeblock(self): |
| 52 |
self.assertMarkdownRenders( |
| 53 |
' # Line 1\n # Line 2\n', |
| 54 |
|
| 55 |
self.dedent( |
| 56 |
""" |
| 57 |
<pre><code># Line 1 |
| 58 |
# Line 2 |
| 59 |
</code></pre> |
| 60 |
""" |
| 61 |
) |
| 62 |
) |
| 63 |
|
| 64 |
def test_codeblock_with_blankline(self): |
| 65 |
self.assertMarkdownRenders( |
| 66 |
' # Line 1\n\n # Line 2\n', |
| 67 |
|
| 68 |
self.dedent( |
| 69 |
""" |
| 70 |
<pre><code># Line 1 |
| 71 |
|
| 72 |
# Line 2 |
| 73 |
</code></pre> |
| 74 |
""" |
| 75 |
) |
| 76 |
) |
| 77 |
|
| 78 |
def test_codeblock_escape(self): |
| 79 |
self.assertMarkdownRenders( |
| 80 |
' <foo & bar>', |
| 81 |
|
| 82 |
self.dedent( |
| 83 |
""" |
| 84 |
<pre><code><foo & bar> |
| 85 |
</code></pre> |
| 86 |
""" |
| 87 |
) |
| 88 |
) |
| 89 |
|
| 90 |
def test_codeblock_second_line(self): |
| 91 |
self.assertMarkdownRenders( |
| 92 |
'\n Code on the second line', |
| 93 |
self.dedent( |
| 94 |
""" |
| 95 |
<pre><code>Code on the second line |
| 96 |
</code></pre> |
| 97 |
""" |
| 98 |
) |
| 99 |
) |