allura
修订版 | e01e26f1765af5b7d92152b1276198db766b009b (tree) |
---|---|
时间 | 2010-06-05 05:43:21 |
作者 | Rick Copeland <rcopeland@geek...> |
Commiter | Rick Copeland |
[#526] - fix markdown problem with embedded html
@@ -23,7 +23,7 @@ class ForgeExtension(markdown.Extension): | ||
23 | 23 | self._use_wiki = wiki |
24 | 24 | |
25 | 25 | def extendMarkdown(self, md, md_globals): |
26 | - md.treeprocessors['br'] = LineOrientedTreeProcessor() | |
26 | + md.treeprocessors['br'] = LineOrientedTreeProcessor(md) | |
27 | 27 | md.inlinePatterns['oembed'] = OEmbedPattern(r'\[embed#(.*?)\]') |
28 | 28 | md.inlinePatterns['autolink_1'] = AutolinkPattern(r'(http(?:s?)://\S*)') |
29 | 29 | md.inlinePatterns['artifact'] = ArtifactLinkPattern(self.core_artifact_link) |
@@ -35,15 +35,27 @@ class LineOrientedTreeProcessor(markdown.treeprocessors.Treeprocessor): | ||
35 | 35 | '''Once MD is satisfied with the etree, this runs to replace \n with <br/> |
36 | 36 | within <p>s. |
37 | 37 | ''' |
38 | + | |
39 | + def __init__(self, md): | |
40 | + self._markdown = md | |
41 | + | |
38 | 42 | def run(self, root): |
39 | 43 | for node in root.getiterator('p'): |
40 | - text = markdown.etree.tostring(node).strip() | |
44 | + if not node.text: continue | |
45 | + if '\n' not in node.text: continue | |
46 | + text = self._markdown.serializer(node) | |
47 | + text = self._markdown.postprocessors['raw_html'].run(text) | |
48 | + text = text.strip() | |
41 | 49 | if '\n' not in text: continue |
42 | 50 | new_text = text.replace('\n', '<br/>') |
43 | - new_node = markdown.etree.fromstring(new_text) | |
44 | - node.clear() | |
45 | - node.text = new_node.text | |
46 | - node[:] = list(new_node) | |
51 | + try: | |
52 | + new_node = markdown.etree.fromstring(new_text) | |
53 | + node.clear() | |
54 | + node.text = new_node.text | |
55 | + node[:] = list(new_node) | |
56 | + except SyntaxError: | |
57 | + log.exception('Error adding <br> tags') | |
58 | + pass | |
47 | 59 | return root |
48 | 60 | |
49 | 61 | class ArtifactLinkPattern(markdown.inlinepatterns.LinkPattern): |