Skip to content

Commit

Permalink
Temporary fix for <block> tags being included in <p> (fixes #13)
Browse files Browse the repository at this point in the history
  • Loading branch information
albert12132 committed Aug 2, 2014
1 parent 90666c8 commit 8453e41
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
8 changes: 8 additions & 0 deletions templar/markdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ def preprocess(text, markdown_obj):
text, references = get_references(text)
text = remove_pandoc_comments(text)
text = handle_whitespace(text)
text = space_out_block_tags(text)
return text, variables, references, footnotes

TAB_SIZE = 4
Expand Down Expand Up @@ -228,6 +229,13 @@ def get_footnote_backreferences(text, markdown_obj):
def remove_pandoc_comments(text):
return re_pandoc_comment.sub('', text)

re_block_tag = re.compile(r"""
(\n|\A)[^\n]*?<\s*/?\s*block\s+[^\n]+?\s*>.*?(\n|\Z)
""", re.X | re.S)
def space_out_block_tags(text):
return re_block_tag.sub(lambda m: '\n' + m.group(0) + '\n', text)



######################
# Hashed Conversions #
Expand Down
18 changes: 18 additions & 0 deletions tests/test_markdown/test_tag.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,24 @@ def testPrecedingParagraph(self):
"""
self.assertMarkdown(text, expect)

def testBlockTagInParagraphs(self):
text = """
Stuff here
<block hello>
This is a paragraph.
</block hello>
"""
expect = """
<p>Stuff here</p>
<block hello>
<p>This is a paragraph.</p>
</block hello>
"""
self.assertMarkdown(text, expect)

class TagTest(MarkdownTest):
def testBasic(self):
text = """
Expand Down

0 comments on commit 8453e41

Please sign in to comment.