summaryrefslogtreecommitdiff
path: root/WikiTrans/wikimarkup.py
diff options
context:
space:
mode:
Diffstat (limited to 'WikiTrans/wikimarkup.py')
-rw-r--r--WikiTrans/wikimarkup.py57
1 files changed, 43 insertions, 14 deletions
diff --git a/WikiTrans/wikimarkup.py b/WikiTrans/wikimarkup.py
index ba30269..d56c664 100644
--- a/WikiTrans/wikimarkup.py
+++ b/WikiTrans/wikimarkup.py
@@ -137,6 +137,9 @@ class BaseWikiMarkup(object):
def dump_tag(self, node, level, file):
self.print_dump_prefix(level, file)
file.write("TAG: %s\n" % node['tag'])
+ if 'isblock' in node:
+ self.print_dump_prefix(level, file)
+ file.write("PLACEMENT: %s\n" % ('BLOCK' if node['isblock'] else 'INLINE'))
if 'args' in node:
self.print_dump_prefix(level, file)
file.write("ARGS: %s\n" % node['args'])
@@ -509,7 +512,7 @@ class BaseWikiMarkup(object):
self.dprint(80, "LEAVE parse_ref=None")
return None
elif tok['type'] == 'OTAG':
- list.append(self.parse_til(tok))
+ list.append(self.parse_tag(tok))
else:
seq.append(tok)
@@ -573,7 +576,7 @@ class BaseWikiMarkup(object):
tok = self.peektkn()
if self.newline:
- if re.match("^\s", tok['content']):
+ if 'content' in tok and re.match("^\s", tok['content']):
type = 'PRE'
rx = re.compile("^\S")
else:
@@ -582,7 +585,7 @@ class BaseWikiMarkup(object):
else:
type = 'SEQ'
rx = None
-
+ self.dprint(80, "IN parse_para, type %s", type)
while 1:
tok = self.getkn()
if tok['type'] == 'TEXT':
@@ -601,7 +604,31 @@ class BaseWikiMarkup(object):
textlist.append('\n')
elif tok['type'] == 'NIL':
break
- elif tok['type'] == 'OTAG' or tok['type'] == 'CTAG' or tok['type'] == 'TAG':
+ elif tok['type'] == 'OTAG':
+ save = (self.tokind,self.newline)
+ t = self.parse_tag(tok)
+ if t['type'] == 'TAG' and t['isblock']:
+ del self.toklist[save[0]:self.tokind]
+ self.tokind = save[0]
+ self.toklist[self.tokind] = t
+ self.newline = save[1]
+ break
+ else:
+ if textlist:
+ seq.append({ 'type': 'TEXT',
+ 'content': ''.join(textlist) })
+ textlist = []
+ seq.append(t)
+ elif tok['type'] == 'TAG':
+ if tok['isblock']:
+ break
+ else:
+ if textlist:
+ seq.append({ 'type': 'TEXT',
+ 'content': ''.join(textlist) })
+ textlist = []
+ seq.append(tok)
+ elif tok['type'] == 'CTAG':
self.ungetkn()
break
elif tok['type'] == 'DELIM':
@@ -679,7 +706,7 @@ class BaseWikiMarkup(object):
else:
list.append(tok)
elif tok['type'] == 'OTAG':
- list.append(self.parse_til(tok))
+ list.append(self.parse_tag(tok))
else:
list.append(tok)
self.dprint(80, "LEAVE parse_line=(SEQ, %s)", list)
@@ -725,10 +752,12 @@ class BaseWikiMarkup(object):
self.dprint(80, "LEAVE parse_indent=%s", x)
return x
- def parse_til(self, tag):
- self.dprint(80, "ENTER parse_til(%s)", tag)
+ def parse_tag(self, tag):
+ self.dprint(80, "ENTER parse_tag(%s)", tag)
seq = []
save = self.tokind
+ t = self.peektkn()
+ isblock = t['type'] == 'NL'
while 1:
t = self.parse0()
if t == None or t['type'] == 'NIL':
@@ -746,7 +775,7 @@ class BaseWikiMarkup(object):
tag['content'] = s
if subtree:
self.tree[self.tokind:self.tokind] = subtree
- self.dprint(80, "LEAVE parse_til = %s (tree modified)", tag)
+ self.dprint(80, "LEAVE parse_tag = %s (tree modified)", tag)
self.ungetkn()
return self.parse0()
@@ -757,11 +786,15 @@ class BaseWikiMarkup(object):
ret = { 'type': 'TAG',
'tag': tag['tag'],
'args': tag['args'],
+ 'isblock': isblock,
'content': { 'type': 'SEQ', 'content': seq } }
- self.dprint(80, "LEAVE parse_til = %s", ret)
+ self.dprint(80, "LEAVE parse_tag = %s", ret)
return ret
def parse0(self):
+ if self.tokind == 0:
+ self.newline = True
+ return self.parse_para()
tok = self.getkn()
self.dprint(80, "ENTER parse0(%s)", tok)
toktype = tok['type']
@@ -790,7 +823,7 @@ class BaseWikiMarkup(object):
elif toktype == 'NL':
return { 'type': 'TEXT', 'content': '\n' }
elif toktype == 'OTAG':
- return self.parse_til(tok)
+ return self.parse_tag(tok)
else:
return tok
@@ -810,10 +843,6 @@ class BaseWikiMarkup(object):
break
self.tree.append(subtree)
- if self.nested:
- if self.tree[0]['type'] == 'PARA':
- self.tree[0]['type'] = 'SEQ'
-
if self.debug_level >= 70:
print("TREE DUMP BEGIN")
self.dump(self.tree)

Return to:

Send suggestions and report system problems to the System administrator.