From f97542b428b1a008e2df955cf2047e4b6b9d73d3 Mon Sep 17 00:00:00 2001 From: Sergey Poznyakoff Date: Wed, 15 Jul 2015 08:13:44 +0300 Subject: Fix parsing of blocks. * wikimarkup.py (tokread): Catch the tag appearing on the same line with the opening . Never return nowiki block as a tag, instead yield a sequence of TEXT nodes. * wiki2html.py (str_tag): Update. * wiki2texi.py: Likewise. * wiki2text.py: Likewise. --- wiki2html.py | 4 +--- wiki2texi.py | 4 +--- wiki2text.py | 4 +--- wikimarkup.py | 24 +++++++++++++++--------- 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/wiki2html.py b/wiki2html.py index f3ea0e3..10a3e1b 100644 --- a/wiki2html.py +++ b/wiki2html.py @@ -173,9 +173,7 @@ class HtmlWikiMarkup (WikiMarkup): return string def str_tag(self, elt): - if elt['tag'] == 'nowiki': - return '
' + self.format(elt['content']) + '
' - elif elt['tag'] == 'code': + if elt['tag'] == 'code': self.nested += 1 s = self.format(elt['content']) self.nested -= 1 diff --git a/wiki2texi.py b/wiki2texi.py index e9009ec..3d74f80 100644 --- a/wiki2texi.py +++ b/wiki2texi.py @@ -120,9 +120,7 @@ class TexiWikiMarkup (WikiMarkup): return str(elt) def str_tag(self, elt): - if elt['tag'] == 'nowiki': - return '@example\n' + self.format(elt['content']) + '@end example\n' - elif elt['tag'] == 'code': + if elt['tag'] == 'code': self.nested += 1 s = self.format(elt['content']) self.nested -= 1 diff --git a/wiki2text.py b/wiki2text.py index d4cab81..c92dbc0 100644 --- a/wiki2text.py +++ b/wiki2text.py @@ -143,9 +143,7 @@ class TextWikiMarkup (WikiMarkup): return output + linebuf def str_tag(self, elt): - if elt['tag'] == 'nowiki': - return self.format(elt['content']) - elif elt['tag'] == 'code': + if elt['tag'] == 'code': self.nested += 1 s = self.format(elt['content']) self.nested -= 1 diff --git a/wikimarkup.py b/wikimarkup.py index 0c6d2f2..815e89d 100644 --- a/wikimarkup.py +++ b/wikimarkup.py @@ -234,27 +234,33 @@ class BaseWikiMarkup(object): 'content': line[pos:] }) if t: + line = rest + pos = 0 if t['type'] == 'OTAG' and t['tag'] == 'nowiki': - s = '' - if not m.group('closed'): + if m.group('closed'): + pass + else: while 1: try: - l = self.input() - m = ctag.match(l) + m = ctag.match(line) if m and m.group('tag') == t['tag']: + yield({ 'type': 'TEXT', + 'content': m.group('pfx') }) + pos = m.end(0) break - s += l + + yield({ 'type': 'TEXT', + 'content': line }) + + line = self.input() except StopIteration: break - t['type'] = 'TAG' - t['content'] = {'type': 'TEXT', 'content': s} + continue yield(t) if t['type'] == 'OTAG' and m.group('closed'): t['type'] = 'CTAG' yield(t) - line = rest - pos = 0 else: line = None -- cgit v1.2.1