Skip to content

Commit 51cbf11

Browse files
committed
Merge branch 'release/3.0.2'
2 parents a5a89b7 + b5478e8 commit 51cbf11

File tree

4 files changed

+80
-10
lines changed

4 files changed

+80
-10
lines changed

CHANGELOG.textile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
h1. Textile Changelog
22

3+
h2. Version 3.0.2
4+
* BUGFIX: Fix for multiple multi-line paragraphs. ("#62":https://github.com/textile/python-textile/pull/62)
5+
36
h2. Version 3.0.1
47
* BUGFIX: Fix improper handling of extended code blocks. ("#61":https://github.com/textile/python-textile/pull/61)
58

tests/test_github_issues.py

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,9 +290,49 @@ def test_github_issue_57():
290290
291291
Back to 10-4 CAPS </code></pre>
292292
293-
<p>Some multiline Paragragh
293+
<p>Some multiline Paragragh</p>
294294
295-
Here is some output!!! &#8220;Some&#8221; <span class="caps">CAPS</span></p>'''
295+
<p>Here is some output!!! &#8220;Some&#8221; <span class="caps">CAPS</span></p>'''
296+
t = textile.Textile()
297+
result = t.parse(input)
298+
assert result == expect
299+
300+
def test_issue_58():
301+
input = '''p.. First one 'is'
302+
303+
ESCAPED "bad"
304+
305+
p.. Second one 'is'
306+
307+
308+
309+
ESCAPED "bad"
310+
311+
p.. Third one 'is'
312+
313+
ESCAPED "bad"
314+
315+
p.. Last one 'is'
316+
317+
ESCAPED "good" test'''
318+
319+
expect = '''<p>First one &#8216;is&#8217;</p>
320+
321+
<p><span class="caps">ESCAPED</span> &#8220;bad&#8221;</p>
322+
323+
<p>Second one &#8216;is&#8217;</p>
324+
325+
326+
327+
<p><span class="caps">ESCAPED</span> &#8220;bad&#8221;</p>
328+
329+
<p>Third one &#8216;is&#8217;</p>
330+
331+
<p><span class="caps">ESCAPED</span> &#8220;bad&#8221;</p>
332+
333+
<p>Last one &#8216;is&#8217;</p>
334+
335+
<p><span class="caps">ESCAPED</span> &#8220;good&#8221; test</p>'''
296336
t = textile.Textile()
297337
result = t.parse(input)
298338
assert result == expect

textile/core.py

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,12 @@ def block(self, text):
433433
# the case, we'd want to drop the whitespace which comes after it.
434434
eat_whitespace = False
435435

436+
# check to see if previous block has already been escaped
437+
escaped = False
438+
439+
# check if multiline paragraph (p..) tags <p>..</p> are added to line
440+
multiline_para = False
441+
436442
tag = 'p'
437443
atts = cite = ext = ''
438444

@@ -458,11 +464,17 @@ def block(self, text):
458464
if ext and out:
459465
# it's out[-2] because the last element in out is the
460466
# whitespace that preceded this line
461-
content = encode_html(out[-2], quotes=True)
462-
content = generate_tag(block.inner_tag, content,
463-
block.inner_atts)
464-
content = generate_tag(block.outer_tag, content,
465-
block.outer_atts)
467+
if not escaped:
468+
content = encode_html(out[-2], quotes=True)
469+
escaped = True
470+
else:
471+
content = out[-2]
472+
473+
if not multiline_para:
474+
content = generate_tag(block.inner_tag, content,
475+
block.inner_atts)
476+
content = generate_tag(block.outer_tag, content,
477+
block.outer_atts)
466478
out[-2] = content
467479
tag, atts, ext, cite, content = match.groups()
468480
block = Block(self, **match.groupdict())
@@ -479,11 +491,18 @@ def block(self, text):
479491
# pre tags and raw text won't be indented.
480492
if block.outer_tag != 'pre' and not has_raw_text(line):
481493
line = "\t{0}".format(line)
494+
495+
# set having paragraph tags to false
496+
if block.tag == 'p' and ext:
497+
multiline_para = False
482498
# no tag specified
483499
else:
484500
# if we're inside an extended block, add the text from the
485501
# previous line to the front
486502
if ext and out:
503+
if block.tag == 'p':
504+
line = generate_tag(block.tag, line, block.outer_atts)
505+
multiline_para = True
487506
line = '{0}{1}'.format(out.pop(), line)
488507
# the logic in the if statement below is a bit confusing in
489508
# php-textile. I'm still not sure I understand what the php
@@ -508,7 +527,15 @@ def block(self, text):
508527
else:
509528
line = self.graf(line)
510529

511-
line = self.doPBr(line)
530+
if block.tag == 'p':
531+
escaped = True
532+
533+
if block.tag == 'p' and ext and not multiline_para:
534+
line = generate_tag(block.tag, line, block.outer_atts)
535+
multiline_para = True
536+
else:
537+
line = self.doPBr(line)
538+
512539
line = line.replace('<br>', '<br />')
513540

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

534561
# at this point, we've gone through all the lines, and if there's still
535562
# an extension in effect, we close it here.
536-
if ext and out:
563+
if ext and out and not block.tag == 'p':
537564
block.content = out.pop()
538565
block.process()
539566
final = generate_tag(block.outer_tag, block.content,

textile/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
VERSION = '3.0.1'
1+
VERSION = '3.0.2'

0 commit comments

Comments
 (0)