From 44479eaa07a177691326291a4d32ac7cd4f61cce Mon Sep 17 00:00:00 2001 From: Daniel Schadt Date: Mon, 16 Aug 2021 15:47:59 +0200 Subject: Handle lists without extra space Sometimes, lists are written like *text *text Which can throw both the pattern-conversion and Gemini browsers off. It's better to insert the extra space here and be safe. --- wikimini/__init__.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/wikimini/__init__.py b/wikimini/__init__.py index 12c3f31..8100a5c 100644 --- a/wikimini/__init__.py +++ b/wikimini/__init__.py @@ -118,6 +118,20 @@ def _convert(obj: Union[mwp.nodes.Node, mwp.wikicode.Wikicode]) -> str: _convert(after), )) continue + # Pattern: *[[Wikilink]]\n + elif (i >= 1 and + i + 1 < len(obj.nodes) and + re.match("s?\n", str(obj.nodes[i+1])) and + isinstance(node, mwp.nodes.wikilink.Wikilink) and + str(obj.nodes[i-1]) == "*"): + converted.pop() + _, after = next(iterator) + converted.append("=> {} {}{}".format( + page_url(str(node.title)), + _convert(node), + _convert(after), + )) + continue # Default: Just convert the node converted.append(_convert(node)) @@ -128,9 +142,9 @@ def _convert(obj: Union[mwp.nodes.Node, mwp.wikicode.Wikicode]) -> str: # Most tags are handled just fine and can be delegated to strip_code # (inline text styles), however we can do a bit better for list tags. if str(obj.wiki_markup) == "*": - return "*" + return "* " elif str(obj.wiki_markup) == "#": - return " {}".format(_convert(obj.contents)) + return " " elif str(obj.tag) == "ref": return "" elif str(obj.tag) == "table": -- cgit v1.2.3