diff options
-rw-r--r-- | testdata/colon.html | 4 | ||||
-rw-r--r-- | testdata/deflist.html | 3 | ||||
-rw-r--r-- | testdata/numlist.html | 2 | ||||
-rw-r--r-- | testdata/unlist.html | 2 | ||||
-rw-r--r-- | wiki2html.py | 2 | ||||
-rw-r--r-- | wiki2texi.py | 2 | ||||
-rw-r--r-- | wikimarkup.py | 33 |
7 files changed, 29 insertions, 19 deletions
diff --git a/testdata/colon.html b/testdata/colon.html index b9e35ed..2fb6ed3 100644 --- a/testdata/colon.html +++ b/testdata/colon.html @@ -1,4 +1,4 @@ -<dl><dd> A colon (:) indents a line or paragraph.</dd></dl><p>A newline starts a new paragraph. +<dl><dd>A colon (:) indents a line or paragraph.</dd></dl><p>A newline starts a new paragraph. Should only be used on talk pages. -For articles, you probably want the blockquote tag.</p><dl><dd> We use 1 colon to indent once.<dl><dd> We use 2 colons to indent twice.<dl><dd> 3 colons to indent 3 times, and so on.</dd></dl></dd></dl></dd></dl> +For articles, you probably want the blockquote tag.</p><dl><dd>We use 1 colon to indent once.</dd></dl><dl><dd><dl><dd>We use 2 colons to indent twice.</dd></dl></dd></dl><dl><dd><dl><dd><dl><dd>3 colons to indent 3 times, and so on.</dd></dl></dd></dl></dd></dl> diff --git a/testdata/deflist.html b/testdata/deflist.html index 8986533..774f21f 100644 --- a/testdata/deflist.html +++ b/testdata/deflist.html @@ -1,2 +1 @@ -<dl><dt>item 1</dt><dd> definition 1</dd><dt>item 2</dt><dd> definition 2-1</dd><dd> definition 2-2</dd></dl> - +<dl><dt>item 1</dt><dd>definition 1</dd><dt>item 2</dt><dd>definition 2-1</dd><dd>definition 2-2</dd></dl> diff --git a/testdata/numlist.html b/testdata/numlist.html index ce9dd2d..0ce8a9a 100644 --- a/testdata/numlist.html +++ b/testdata/numlist.html @@ -1,2 +1,2 @@ -<ol><li> <i>Numbered lists</i> are:<ol><li> Very organized</li><li> Easy to follow</li></ol></li></ol><p>A newline marks the end of the list.</p><ol><li> New numbering starts with 1.</li></ol> +<ol><li><i>Numbered lists</i> are:<ol><li>Very organized</li><li>Easy to follow</li></ol></li></ol><p>A newline marks the end of the list.</p><ol><li>New numbering starts with 1.</li></ol> diff --git a/testdata/unlist.html b/testdata/unlist.html index 87be30f..ac4d32b 100644 --- a/testdata/unlist.html +++ b/testdata/unlist.html @@ -1,2 +1,2 @@ -<ul><li> <i>Unordered lists</i> are easy to do:<ul><li> Start every line with a star.<ul><li> More stars indicate a deeper level.</li></ul></li></ul> Previous item continues.<ul><li> A newline</li></ul></li><li> in a list </li></ul><p>marks the end of the list.</p><ul><li>Of course you can start again.</li></ul> +<ul><li><i>Unordered lists</i> are easy to do:<ul><li>Start every line with a star.<ul><li>More stars indicate a deeper level.</li></ul>Previous item continues.</li><li>A newline</li></ul></li><li>in a list </li></ul><p>marks the end of the list.</p><ul><li>Of course you can start again.</li></ul> diff --git a/wiki2html.py b/wiki2html.py index 66939c4..f3ea0e3 100644 --- a/wiki2html.py +++ b/wiki2html.py @@ -205,3 +205,3 @@ class HtmlWikiMarkup (WikiMarkup): def str_ind(self, elt): - return (" " * 2 * elt['level']) + self.format(elt['content']) + return ("<dl><dd>" * elt['level']) + self.format(elt['content']) + "</dd></dl>" * elt['level'] diff --git a/wiki2texi.py b/wiki2texi.py index 0b3eb77..e9009ec 100644 --- a/wiki2texi.py +++ b/wiki2texi.py @@ -188,3 +188,3 @@ class TexiWikiMarkup (WikiMarkup): def str_ind(self, elt): - return ("@w{ }" * elt['level']) + self.format(elt['content']) + return ("@w{ }" * elt['level']) + self.format(elt['content']) + '\n' diff --git a/wikimarkup.py b/wikimarkup.py index 9a79d1e..0c6d2f2 100644 --- a/wikimarkup.py +++ b/wikimarkup.py @@ -186,10 +186,19 @@ class BaseWikiMarkup(object): 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: @@ -307,4 +316,4 @@ class BaseWikiMarkup(object): - def peektkn(self): - return self.toklist[self.tokind] + def peektkn(self, off=0): + return self.toklist[self.tokind-off] @@ -606,3 +615,3 @@ class BaseWikiMarkup(object): elt = self.parse_line() - if 'continuation' not in tok: + if not tok['continuation']: list.append({ 'type': 'ELT', @@ -683,6 +692,8 @@ class BaseWikiMarkup(object): 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: |