summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2015-07-15 08:13:44 +0300
committerSergey Poznyakoff <gray@gnu.org.ua>2015-07-15 10:09:36 +0300
commitf97542b428b1a008e2df955cf2047e4b6b9d73d3 (patch)
tree58fd02b5f62f7b08b21fa2749c9ae5a3a693eaa2
parent4097896542f2279700794104c7c0728beed38cd0 (diff)
downloadwikitrans-f97542b428b1a008e2df955cf2047e4b6b9d73d3.tar.gz
wikitrans-f97542b428b1a008e2df955cf2047e4b6b9d73d3.tar.bz2
Fix parsing of <nowiki> blocks.
* wikimarkup.py (tokread): Catch the </nowiki> tag appearing on the same line with the opening <nowiki>. 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.
-rw-r--r--wiki2html.py4
-rw-r--r--wiki2texi.py4
-rw-r--r--wiki2text.py4
-rw-r--r--wikimarkup.py24
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
@@ -170,15 +170,13 @@ class HtmlWikiMarkup (WikiMarkup):
return "<%s>%s</%s>" % (self.envt[type]["hdr"],
string,
self.envt[type]["hdr"])
return string
def str_tag(self, elt):
- if elt['tag'] == 'nowiki':
- return '<pre>' + self.format(elt['content']) + '</pre>'
- elif elt['tag'] == 'code':
+ if elt['tag'] == 'code':
self.nested += 1
s = self.format(elt['content'])
self.nested -= 1
return '<pre><code>' + s + '</code></pre>' #FIXME
else:
s = '<' + elt['tag']
diff --git a/wiki2texi.py b/wiki2texi.py
index e9009ec..3d74f80 100644
--- a/wiki2texi.py
+++ b/wiki2texi.py
@@ -117,15 +117,13 @@ class TexiWikiMarkup (WikiMarkup):
string += self.format(x)
return string
else:
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
if not s.endswith("\n"):
s += "\n"
return '@example\n' + s + '@end example\n'
diff --git a/wiki2text.py b/wiki2text.py
index d4cab81..c92dbc0 100644
--- a/wiki2text.py
+++ b/wiki2text.py
@@ -140,15 +140,13 @@ class TextWikiMarkup (WikiMarkup):
linebuf = ""
linebuf += " " * wsc + s
length += wsc + wlen
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
return s #FIXME
else:
s = '<' + elt['tag']
diff --git a/wikimarkup.py b/wikimarkup.py
index 0c6d2f2..815e89d 100644
--- a/wikimarkup.py
+++ b/wikimarkup.py
@@ -231,33 +231,39 @@ class BaseWikiMarkup(object):
'content': '\n' })
else:
yield({ 'type': 'TEXT',
'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
def input(self):
return None

Return to:

Send suggestions and report system problems to the System administrator.