Ticket #17714: 17714_markdown_extensions_multiple_options_with_tests.diff
File 17714_markdown_extensions_multiple_options_with_tests.diff, 3.5 KB (added by , 13 years ago) |
---|
-
django/contrib/markup/tests.py
30 30 31 31 ## An h2""" 32 32 33 markdown_content_with_def_list = """Paragraph 1 34 35 ## An h2 36 37 Apple 38 : Pomaceous fruit of plants of the genus Malus in the family Rosaceae. 39 40 Orange 41 : The fruit of an evergreen tree of the genus Citrus.""" 42 33 43 rest_content = """Paragraph 1 34 44 35 45 Paragraph 2 with a link_ … … 64 74 rendered = t.render(Context({'markdown_content':self.markdown_content})).strip() 65 75 self.assertEqual(rendered, self.markdown_content) 66 76 77 @unittest.skipUnless(markdown, 'markdown not installed') 78 def test_markdown_extensions(self): 79 # Define extensions to use as argument to markdown filter. Using 80 # def_list and headerid here because they are included in the standard 81 # Markdown library. 82 extensions = "def_list,headerid(forceid=False, level=3)" 83 t = Template( 84 """{%% load markup %%}""" 85 """{{ markdown_content|markdown:"%s" }}""" % extensions 86 ) 87 c = Context({'markdown_content': self.markdown_content_with_def_list}) 88 rendered = t.render(c) 89 90 # Note that the output should have <h4> and <dl> now 91 pattern = re.compile( 92 r"""\s*<p>Paragraph 1</p>""" 93 """\s*<h4>An h2</h4>""" 94 """\s*<dl>""" 95 """\s*<dt>Apple</dt>""" 96 """\s*<dd>.*?Malus.*?</dd>""" 97 """\s*<dt>Orange</dt>""" 98 """\s*<dd>.*?Citrus.</dd>""" 99 """\s*</dl>""") 100 self.assertTrue(pattern.match(rendered)) 101 67 102 @unittest.skipUnless(docutils, 'docutils not installed') 68 103 def test_docutils(self): 69 104 t = Template("{% load markup %}{{ rest_content|restructuredtext }}") -
django/contrib/markup/templatetags/markup.py
43 43 generated by actual Markdown syntax, pass "safe" as the first 44 44 extension in the list. 45 45 46 Extensions may be given configuration options in the form of key=value 47 pairs, separated by commas and enclosed in parenthesis immediately after 48 the extension name. For example: 49 50 {{ value|markdown:"ext_name(key1=val1, key2=val2),ext2,ext3,..." }} 51 46 52 If the version of Markdown in use does not support extensions, 47 53 they will be silently ignored. 48 54 … … 57 63 # markdown.version was first added in 1.6b. The only version of markdown 58 64 # to fully support extensions before 1.6b was the shortlived 1.6a. 59 65 if hasattr(markdown, 'version'): 60 extensions = [e for e in arg.split(",") if e] 66 extensions = [] 67 # Ensure that splitting into extensions by commas ignores those 68 # commas contained within parenthesis, so that extensions are 69 # allowed multiple configuration options. 70 for part in arg.split("("): 71 if ")" in part and extensions: 72 config, part = part.split(")") 73 extensions[-1] += "(%s)" % config 74 extensions.extend(e for e in part.split(",") if e) 75 61 76 if len(extensions) > 0 and extensions[0] == "safe": 62 77 extensions = extensions[1:] 63 78 safe_mode = True