diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2015-07-14 16:09:36 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2015-07-14 16:09:36 +0300 |
commit | 4097896542f2279700794104c7c0728beed38cd0 (patch) | |
tree | 664012755efc30126a0ccef42245ce3068f06adc /wikimarkup.py | |
parent | 28072898f1bd9a925d73ac187d560198d6345524 (diff) | |
download | wikitrans-4097896542f2279700794104c7c0728beed38cd0.tar.gz wikitrans-4097896542f2279700794104c7c0728beed38cd0.tar.bz2 |
Fix processing of environments (numbered/unnumbered lists, definition lists) and indented strings.
* wikimarkup.py (tokread): Always add 'continuation' key to DELIM
entries. Delete whitespace following environment delimiters.
(peektkn): Take an optional offset argument.
(parse0): Handle indentations.
* wiki2html.py (str_ind): Use <dl> to produce indentations.
* wiki2texi.py (str_ind): End text with a newline.
* testdata/colon.html: Update.
* testdata/deflist.html: Update.
* testdata/numlist.html: Update.
* testdata/unlist.html: Update.
Diffstat (limited to 'wikimarkup.py')
-rw-r--r-- | wikimarkup.py | 33 |
1 files changed, 22 insertions, 11 deletions
diff --git a/wikimarkup.py b/wikimarkup.py index 9a79d1e..0c6d2f2 100644 --- a/wikimarkup.py +++ b/wikimarkup.py @@ -184,14 +184,23 @@ class BaseWikiMarkup(object): pos = m.end(0) if m and line[m.start(0)] != '<': - if m.group(0)[0] in envtypes and pos < len(line) and line[pos] == ":": - yield({ 'type': 'DELIM', - 'content': m.group(0), - 'continuation': True }) - pos += 1 + content = m.group(0) + if content[0] in envtypes: + t = { 'type': 'DELIM', + 'content': content, + 'continuation': pos < len(line) and line[pos] == ":" } + if t['continuation']: + t['content'] += t['content'][0] + pos += 1 + + yield(t) + + while pos < len(line) and line[pos] in [' ', '\t']: + pos += 1 else: yield({ 'type': 'DELIM', - 'content': m.group(0) }) + 'content': content, + 'continuation': False}) else: if m: pos -= 1 @@ -305,8 +314,8 @@ class BaseWikiMarkup(object): for i in stack: self.toklist[i]['type'] = 'TEXT' - def peektkn(self): - return self.toklist[self.tokind] + def peektkn(self, off=0): + return self.toklist[self.tokind-off] def setkn(self,val): self.toklist[self.tokind] = val @@ -604,7 +613,7 @@ class BaseWikiMarkup(object): elt = self.parse_env(type, len(tok['content'])) else: elt = self.parse_line() - if 'continuation' not in tok: + if not tok['continuation']: list.append({ 'type': 'ELT', 'subtype': envtypes[tok['content'][0]][1], 'content': elt }) @@ -681,10 +690,12 @@ class BaseWikiMarkup(object): elif tok['content'][0] in envtypes: type = envtypes[tok['content'][0]][0] lev = len(tok['content']) + if tok['content'][0] == ':': + t = self.peektkn(2) + if not (t['type'] == 'DELIM' and t['content'] == ';'): + return self.parse_indent(lev) self.ungetkn() return self.parse_env(type, lev) - elif tok['content'][0] == ":": - return self.parse_indent(len(tok['content'])) else: self.ungetkn() return self.parse_para() |