Skip to content

Commit

Permalink
Merge pull request #138 from boscoh/markdown_br_fix
Browse files Browse the repository at this point in the history
Fix Markdown br bug
Thanks to @boscoh for the following:
In the `:markdown` filter, the markdown for implicit `<br>` tag is broken.

The reason is that markdown recognises a line with  `<br>` by two trailing spaces.

However, trailing spaces are stripped when `PlaintextNode.haml` is read.

To fix: when the text is reconstructed to send to the Markdown filter, instead of using the `PlaintextNode.haml` field, `PlaintextNode.raw_haml.lstrip()` is used, which keeps the trailing spaces.
  • Loading branch information
noelbush-xx committed Jul 29, 2013
2 parents 8b72bd0 + f6a56cb commit fe3ba8b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
10 changes: 7 additions & 3 deletions hamlpy/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -593,10 +593,14 @@ def _render(self):
if self.children:
if not _markdown_available:
raise NotAvailableError("Markdown is not available")

self.before = self.render_newlines()[1:]
indent_offset = len(self.children[0].spaces)
text = ''.join(''.join([c.spaces[indent_offset:], c.haml, c.render_newlines()]) for c in self.children)
self.before += markdown(text)
lines = []
for c in self.children:
haml = c.raw_haml.lstrip()
if haml[-1] == '\n':
haml = haml[:-1]
lines.append(c.spaces[indent_offset:] + haml + c.render_newlines())
self.before += markdown( ''.join(lines))
else:
self.after = self.render_newlines()
5 changes: 4 additions & 1 deletion hamlpy/test/templates/filtersMarkdown.hamlpy
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
hello
no paragraph

line break
follow

New paragraph

test
code block
6 changes: 4 additions & 2 deletions hamlpy/test/templates/filtersMarkdown.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<p>hello
no paragraph</p>
<p>line break<br />
follow</p>
<p>New paragraph</p>
<pre><code>test
</code></pre>
<pre><code>code block
</code></pre>

0 comments on commit fe3ba8b

Please sign in to comment.