From 3587cb2d6ea31723757251c0be86d12625dec7c3 Mon Sep 17 00:00:00 2001 From: Waylan Limberg Date: Sun, 3 Jan 2010 23:27:49 -0500 Subject: 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'. --- markdown/extensions/extra.py | 2 ++ markdown/preprocessors.py | 6 ++++-- tests/extensions-x-extra/raw-html.html | 14 ++++++++++++++ tests/extensions-x-extra/raw-html.txt | 12 ++++++++++++ 4 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 tests/extensions-x-extra/raw-html.html create mode 100644 tests/extensions-x-extra/raw-html.txt 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 @@ +
+ +

foo

+
+ +
+ +

bar

+
+ +
+ +

blah

+
\ 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 @@ +
_foo_
+ +
+_bar_ +
+ +
+ +_blah_ + +
+ -- cgit v1.2.3