diff --git a/tests/test_github_issues.py b/tests/test_github_issues.py index 6b5b3d75..bced0dcb 100644 --- a/tests/test_github_issues.py +++ b/tests/test_github_issues.py @@ -290,9 +290,49 @@ def test_github_issue_57(): Back to 10-4 CAPS -

Some multiline Paragragh +

Some multiline Paragragh

-Here is some output!!! “Some” CAPS

''' +

Here is some output!!! “Some” CAPS

''' + 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 = '''

First one ‘is’

+ +

ESCAPED “bad”

+ +

Second one ‘is’

+ + + +

ESCAPED “bad”

+ +

Third one ‘is’

+ +

ESCAPED “bad”

+ +

Last one ‘is’

+ +

ESCAPED “good” test

''' t = textile.Textile() result = t.parse(input) assert result == expect diff --git a/textile/core.py b/textile/core.py index a5dae835..76016f08 100644 --- a/textile/core.py +++ b/textile/core.py @@ -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

..

are added to line + multiline_para = False + tag = 'p' atts = cite = ext = '' @@ -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()) @@ -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 @@ -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('
', '
') # if we're in an extended block, and we haven't specified a new @@ -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,