• R/O
  • HTTP
  • SSH
  • HTTPS

提交

标签
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

allura


Commit MetaInfo

修订版e01e26f1765af5b7d92152b1276198db766b009b (tree)
时间2010-06-05 05:43:21
作者Rick Copeland <rcopeland@geek...>
CommiterRick Copeland

Log Message

[#526] - fix markdown problem with embedded html

更改概述

差异

--- a/pyforge/pyforge/lib/markdown_extensions.py
+++ b/pyforge/pyforge/lib/markdown_extensions.py
@@ -23,7 +23,7 @@ class ForgeExtension(markdown.Extension):
2323 self._use_wiki = wiki
2424
2525 def extendMarkdown(self, md, md_globals):
26- md.treeprocessors['br'] = LineOrientedTreeProcessor()
26+ md.treeprocessors['br'] = LineOrientedTreeProcessor(md)
2727 md.inlinePatterns['oembed'] = OEmbedPattern(r'\[embed#(.*?)\]')
2828 md.inlinePatterns['autolink_1'] = AutolinkPattern(r'(http(?:s?)://\S*)')
2929 md.inlinePatterns['artifact'] = ArtifactLinkPattern(self.core_artifact_link)
@@ -35,15 +35,27 @@ class LineOrientedTreeProcessor(markdown.treeprocessors.Treeprocessor):
3535 '''Once MD is satisfied with the etree, this runs to replace \n with <br/>
3636 within <p>s.
3737 '''
38+
39+ def __init__(self, md):
40+ self._markdown = md
41+
3842 def run(self, root):
3943 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()
4149 if '\n' not in text: continue
4250 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
4759 return root
4860
4961 class ArtifactLinkPattern(markdown.inlinepatterns.LinkPattern):