summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Schadt <kingdread@gmx.de>2021-08-16 15:47:59 +0200
committerDaniel Schadt <kingdread@gmx.de>2021-08-16 15:47:59 +0200
commit44479eaa07a177691326291a4d32ac7cd4f61cce (patch)
tree2f921e130ad0f11226e8b58ffe485527bfff60d6
parent2574e7cd44eba6db82a24cac6151ee18a2aca9ae (diff)
downloadwikimini-44479eaa07a177691326291a4d32ac7cd4f61cce.tar.gz
wikimini-44479eaa07a177691326291a4d32ac7cd4f61cce.tar.bz2
wikimini-44479eaa07a177691326291a4d32ac7cd4f61cce.zip
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.
-rw-r--r--wikimini/__init__.py18
1 files 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 "<!NUM!> {}".format(_convert(obj.contents))
+ return "<!NUM!> "
elif str(obj.tag) == "ref":
return ""
elif str(obj.tag) == "table":