aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWaylan Limberg <waylan@gmail.com>2010-01-03 23:27:49 -0500
committerWaylan Limberg <waylan@gmail.com>2010-01-03 23:27:49 -0500
commit3587cb2d6ea31723757251c0be86d12625dec7c3 (patch)
tree2ebf029f623762f8a1c74e12d55d1aa428a5d619
parentc2d50b46b536a440b6d73c6bf309bdaf03b90abb (diff)
downloadmarkdown-3587cb2d6ea31723757251c0be86d12625dec7c3.tar.gz
markdown-3587cb2d6ea31723757251c0be86d12625dec7c3.tar.bz2
markdown-3587cb2d6ea31723757251c0be86d12625dec7c3.zip
Added processing of markdown text within raw html to the 'extra' extension. Fixes Ticket 39. NOTE: I did not add a seperate extension which only adds this feature - it is only available as part of 'extra'.
-rw-r--r--markdown/extensions/extra.py2
-rw-r--r--markdown/preprocessors.py6
-rw-r--r--tests/extensions-x-extra/raw-html.html14
-rw-r--r--tests/extensions-x-extra/raw-html.txt12
4 files changed, 32 insertions, 2 deletions
diff --git a/markdown/extensions/extra.py b/markdown/extensions/extra.py
index 4a2ffbf..e569029 100644
--- a/markdown/extensions/extra.py
+++ b/markdown/extensions/extra.py
@@ -44,6 +44,8 @@ class ExtraExtension(markdown.Extension):
def extendMarkdown(self, md, md_globals):
""" Register extension instances. """
md.registerExtensions(extensions, self.config)
+ # Turn on processing of markdown text within raw html
+ md.preprocessors['html_block'].markdown_in_raw = True
def makeExtension(configs={}):
return ExtraExtension(configs=dict(configs))
diff --git a/markdown/preprocessors.py b/markdown/preprocessors.py
index cbf40e3..b199f0a 100644
--- a/markdown/preprocessors.py
+++ b/markdown/preprocessors.py
@@ -227,7 +227,8 @@ class HtmlBlockPreprocessor(Preprocessor):
# if find closing tag
in_tag = False
if self.markdown_in_raw and 'markdown' in attrs.keys():
- start = items[0][:left_index]
+ start = re.sub(r'\smarkdown(=[\'"]?[^> ]*[\'"]?)?',
+ '', items[0][:left_index])
items[0] = items[0][left_index:]
end = items[-1][-len(right_tag)-2:]
items[-1] = items[-1][:-len(right_tag)-2]
@@ -243,7 +244,8 @@ class HtmlBlockPreprocessor(Preprocessor):
if items:
if self.markdown_in_raw and 'markdown' in attrs.keys():
- start = items[0][:left_index]
+ start = re.sub(r'\smarkdown(=[\'"]?[^> ]*[\'"]?)?',
+ '', items[0][:left_index])
items[0] = items[0][left_index:]
end = items[-1][-len(right_tag)-2:]
items[-1] = items[-1][:-len(right_tag)-2]
diff --git a/tests/extensions-x-extra/raw-html.html b/tests/extensions-x-extra/raw-html.html
new file mode 100644
index 0000000..b2a7c4d
--- /dev/null
+++ b/tests/extensions-x-extra/raw-html.html
@@ -0,0 +1,14 @@
+<div>
+
+<p><em>foo</em></p>
+</div>
+
+<div class="baz">
+
+<p><em>bar</em></p>
+</div>
+
+<div>
+
+<p><em>blah</em></p>
+</div> \ No newline at end of file
diff --git a/tests/extensions-x-extra/raw-html.txt b/tests/extensions-x-extra/raw-html.txt
new file mode 100644
index 0000000..284fe0c
--- /dev/null
+++ b/tests/extensions-x-extra/raw-html.txt
@@ -0,0 +1,12 @@
+<div markdown="1">_foo_</div>
+
+<div markdown=1 class="baz">
+_bar_
+</div>
+
+<div markdown>
+
+_blah_
+
+</div>
+