diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2009-03-03 12:46:32 +0200 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2009-03-03 12:46:32 +0200 |
commit | 6b0bfa216f6512e929dbe63e6c9b9cb6934dc3c5 (patch) | |
tree | 2d730aa5e4afa504bc454f875da21052ee2f914b /wikimarkup.py | |
parent | b5e926d076af2f96cff437ace72c345289d8f92a (diff) | |
download | wikitrans-6b0bfa216f6512e929dbe63e6c9b9cb6934dc3c5.tar.gz wikitrans-6b0bfa216f6512e929dbe63e6c9b9cb6934dc3c5.tar.bz2 |
Fix it/bold parsing + minor bugfixes
Diffstat (limited to 'wikimarkup.py')
-rw-r--r-- | wikimarkup.py | 43 |
1 files changed, 36 insertions, 7 deletions
diff --git a/wikimarkup.py b/wikimarkup.py index 76fc865..baa5c82 100644 --- a/wikimarkup.py +++ b/wikimarkup.py @@ -156,6 +156,16 @@ class BaseWikiMarkup: self.dprint(80, "LEAVE parse_bold=None") return None seq.append(x) + elif self.is_inline_delim(tok): + if textlist: + seq.append((TEXT, textlist)) + textlist = [] + x = self.parse_inline(tok) + if x: + seq.append(x) + else: + self.dprint(80, "LEAVE parse_bold=%s", "None") + return None else: self.dprint(80, "LEAVE parse_bold=None") return None @@ -198,11 +208,21 @@ class BaseWikiMarkup: if textlist: seq.append((TEXT, textlist)) textlist = [] - x = self.parse_bold(True) - if not x: - self.dprint(80, "LEAVE parse_it=%s", "None") - return None - seq.append(x) + x = self.parse_bold(True) + if not x: + self.dprint(80, "LEAVE parse_it=%s", "None") + return None + seq.append(x) + elif self.is_inline_delim(tok): + if textlist: + seq.append((TEXT, textlist)) + textlist = [] + x = self.parse_inline(tok) + if x: + seq.append(x) + else: + self.dprint(80, "LEAVE parse_it=%s", "None") + return None else: self.dprint(80, "LEAVE parse_it=%s", "None") return None @@ -282,6 +302,12 @@ class BaseWikiMarkup: return ret inline_delims = [ "''", "'''", "[", "[[", "{{" ] + + def is_inline_delim(self, tok): + return tok[0] == DELIM and tok[1] in self.inline_delims + def is_block_delim(self, tok): + return tok[0] == DELIM and tok[1] not in self.inline_delims + def parse_inline(self, tok): self.dprint(80, "ENTER parse_inline(%s), tok %s", tok, self.peektkn()) tokind = self.tokind @@ -317,10 +343,12 @@ class BaseWikiMarkup: break else: self.ungetkn() + if self.is_block_delim(tok): + break elif tok[0] == NIL: break elif tok[0] == DELIM: - if tok[1] in self.inline_delims: + if self.is_inline_delim(tok): if textlist: seq.append((TEXT, textlist)) textlist = [] @@ -331,7 +359,8 @@ class BaseWikiMarkup: seq.append(tok) break else: - self.ungetkn() + seq.append((TEXT,tok[1])) + # self.ungetkn() break if textlist: seq.append((TEXT, textlist)) |