aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWaylan Limberg <waylan@gmail.com>2008-08-26 13:01:17 -0400
committerWaylan Limberg <waylan@gmail.com>2008-08-26 13:01:17 -0400
commita4c80246770b87ca3d2cce5b5184901fd2495a7d (patch)
tree4bdbdf2b58f86471a4bf252e9330dd413c2c8f2a
parentebefa9bb10a0b3aebb134ed8fb06b79f97040999 (diff)
downloadmarkdown-a4c80246770b87ca3d2cce5b5184901fd2495a7d.tar.gz
markdown-a4c80246770b87ca3d2cce5b5184901fd2495a7d.tar.bz2
markdown-a4c80246770b87ca3d2cce5b5184901fd2495a7d.zip
Fixed ticket 12. Insert code placeholder into a wrapping ET element rather than parent_elem.text as text will alway be at beginning of doc. The wrapping element is a <p> tag as, later, when the rawhtml is inserted, markdown will first check for the placeholder inside a <p> tag, and if the placeholder is the *only* content of the <p> tag, replace the entire <p> tag - not just the placeholder. Perhaps a little hacky, but this is how markdown works internally anyway.
-rw-r--r--markdown_extensions/codehilite.py7
-rw-r--r--tests/extensions-x-codehilite/code.html11
2 files changed, 7 insertions, 11 deletions
diff --git a/markdown_extensions/codehilite.py b/markdown_extensions/codehilite.py
index 890a66b..edfcedb 100644
--- a/markdown_extensions/codehilite.py
+++ b/markdown_extensions/codehilite.py
@@ -204,10 +204,9 @@ class CodeHiliteExtention(markdown.Extension):
text = "\n".join(detabbed).rstrip()+"\n"
code = CodeHilite(text, linenos=self.config['force_linenos'][0])
placeholder = md.htmlStash.store(code.hilite(), safe=True)
- if parent_elem.text:
- parent_elem.text += placeholder
- else:
- parent_elem.text = placeholder
+ # This wrapping p element will be removed when inserting raw html
+ p = markdown.etree.SubElement(parent_elem, 'p')
+ p.text = placeholder
md._processSection(parent_elem, theRest, inList)
md._processCodeBlock = _hiliteCodeBlock
diff --git a/tests/extensions-x-codehilite/code.html b/tests/extensions-x-codehilite/code.html
index 43b09ea..6a8ee91 100644
--- a/tests/extensions-x-codehilite/code.html
+++ b/tests/extensions-x-codehilite/code.html
@@ -1,7 +1,5 @@
-
-<p>Some text
-</p>
-<table><tr><td class="linenos"><pre>1
+<p>Some text</p>
+<table class="codehilitetable"><tr><td class="linenos"><pre>1
2
3
4
@@ -13,7 +11,6 @@
<span class="k">def</span> <span class="nf">getCompiledRegExp</span> <span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="p">:</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">compiled_re</span>
</pre></div>
-</td></tr></table><p>More text
-</p>
-
+</td></tr></table>
+<p>More text</p> \ No newline at end of file