Skip to content

Commit

Permalink
Merge branch 'release/3.0.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
ikirudennis committed Apr 12, 2018
2 parents a5a89b7 + b5478e8 commit 51cbf11
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 10 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.textile
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
h1. Textile Changelog

h2. Version 3.0.2
* BUGFIX: Fix for multiple multi-line paragraphs. ("#62":https://github.com/textile/python-textile/pull/62)

h2. Version 3.0.1
* BUGFIX: Fix improper handling of extended code blocks. ("#61":https://github.com/textile/python-textile/pull/61)

Expand Down
44 changes: 42 additions & 2 deletions tests/test_github_issues.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,9 +290,49 @@ def test_github_issue_57():
Back to 10-4 CAPS </code></pre>
<p>Some multiline Paragragh
<p>Some multiline Paragragh</p>
Here is some output!!! &#8220;Some&#8221; <span class="caps">CAPS</span></p>'''
<p>Here is some output!!! &#8220;Some&#8221; <span class="caps">CAPS</span></p>'''
t = textile.Textile()
result = t.parse(input)
assert result == expect

def test_issue_58():
input = '''p.. First one 'is'
ESCAPED "bad"
p.. Second one 'is'
ESCAPED "bad"
p.. Third one 'is'
ESCAPED "bad"
p.. Last one 'is'
ESCAPED "good" test'''

expect = '''<p>First one &#8216;is&#8217;</p>
<p><span class="caps">ESCAPED</span> &#8220;bad&#8221;</p>
<p>Second one &#8216;is&#8217;</p>
<p><span class="caps">ESCAPED</span> &#8220;bad&#8221;</p>
<p>Third one &#8216;is&#8217;</p>
<p><span class="caps">ESCAPED</span> &#8220;bad&#8221;</p>
<p>Last one &#8216;is&#8217;</p>
<p><span class="caps">ESCAPED</span> &#8220;good&#8221; test</p>'''
t = textile.Textile()
result = t.parse(input)
assert result == expect
41 changes: 34 additions & 7 deletions textile/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,12 @@ def block(self, text):
# the case, we'd want to drop the whitespace which comes after it.
eat_whitespace = False

# check to see if previous block has already been escaped
escaped = False

# check if multiline paragraph (p..) tags <p>..</p> are added to line
multiline_para = False

tag = 'p'
atts = cite = ext = ''

Expand All @@ -458,11 +464,17 @@ def block(self, text):
if ext and out:
# it's out[-2] because the last element in out is the
# whitespace that preceded this line
content = encode_html(out[-2], quotes=True)
content = generate_tag(block.inner_tag, content,
block.inner_atts)
content = generate_tag(block.outer_tag, content,
block.outer_atts)
if not escaped:
content = encode_html(out[-2], quotes=True)
escaped = True
else:
content = out[-2]

if not multiline_para:
content = generate_tag(block.inner_tag, content,
block.inner_atts)
content = generate_tag(block.outer_tag, content,
block.outer_atts)
out[-2] = content
tag, atts, ext, cite, content = match.groups()
block = Block(self, **match.groupdict())
Expand All @@ -479,11 +491,18 @@ def block(self, text):
# pre tags and raw text won't be indented.
if block.outer_tag != 'pre' and not has_raw_text(line):
line = "\t{0}".format(line)

# set having paragraph tags to false
if block.tag == 'p' and ext:
multiline_para = False
# no tag specified
else:
# if we're inside an extended block, add the text from the
# previous line to the front
if ext and out:
if block.tag == 'p':
line = generate_tag(block.tag, line, block.outer_atts)
multiline_para = True
line = '{0}{1}'.format(out.pop(), line)
# the logic in the if statement below is a bit confusing in
# php-textile. I'm still not sure I understand what the php
Expand All @@ -508,7 +527,15 @@ def block(self, text):
else:
line = self.graf(line)

line = self.doPBr(line)
if block.tag == 'p':
escaped = True

if block.tag == 'p' and ext and not multiline_para:
line = generate_tag(block.tag, line, block.outer_atts)
multiline_para = True
else:
line = self.doPBr(line)

line = line.replace('<br>', '<br />')

# if we're in an extended block, and we haven't specified a new
Expand All @@ -533,7 +560,7 @@ def block(self, text):

# at this point, we've gone through all the lines, and if there's still
# an extension in effect, we close it here.
if ext and out:
if ext and out and not block.tag == 'p':
block.content = out.pop()
block.process()
final = generate_tag(block.outer_tag, block.content,
Expand Down
2 changes: 1 addition & 1 deletion textile/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
VERSION = '3.0.1'
VERSION = '3.0.2'

0 comments on commit 51cbf11

Please sign in to comment.