diff options
author | Daniel Schadt <kingdread@gmx.de> | 2021-08-20 12:45:57 +0200 |
---|---|---|
committer | Daniel Schadt <kingdread@gmx.de> | 2021-08-20 12:45:57 +0200 |
commit | 22029400ef35ee7eb85bf5d89562738d65a38e75 (patch) | |
tree | 8bca404140ba593df825c9c3039da5211ac13138 | |
parent | d6e7479fb0b845415c9d1bdcc42936a4f36dde39 (diff) | |
download | wikimini-22029400ef35ee7eb85bf5d89562738d65a38e75.tar.gz wikimini-22029400ef35ee7eb85bf5d89562738d65a38e75.tar.bz2 wikimini-22029400ef35ee7eb85bf5d89562738d65a38e75.zip |
fix handling of link items with trailing plural s
-rw-r--r-- | wikimini/document.py | 20 | ||||
-rw-r--r-- | wikimini/formats/gemtext.py | 4 |
2 files changed, 22 insertions, 2 deletions
diff --git a/wikimini/document.py b/wikimini/document.py index a7da2a2..a363c25 100644 --- a/wikimini/document.py +++ b/wikimini/document.py @@ -258,6 +258,26 @@ class Paragraph(Block): if not self.nodes[-1].plain(): del self.nodes[-1] + def is_link_paragraph(self) -> bool: + """Returns whether the paragraph can be considered a "link item". + + A link item is a paragraph that only consists of a link (and + potentially a plural identifier), usually found in the "See also" + section on Wikipedia. + + In case of a link paragraph, the first node will be an + :class:`InlineLink`. + + Returns: + True if the paragraph is a link paragraph. + """ + if not self.nodes: + return False + return (isinstance(self.nodes[0], InlineLink) + and (len(self.nodes) == 1 + or len(self.nodes) == 2 and self.nodes[1].plain() == "s") + ) + @dataclass class Heading(Block): diff --git a/wikimini/formats/gemtext.py b/wikimini/formats/gemtext.py index 935565c..39df956 100644 --- a/wikimini/formats/gemtext.py +++ b/wikimini/formats/gemtext.py @@ -33,9 +33,9 @@ class Gemtext(Format): def render_item_list(self, item_list): for item in item_list.items: - if len(item.nodes) == 1 and isinstance(item.nodes[0], InlineLink): + if item.is_link_paragraph(): link = item.nodes[0] - self.render(BlockLink(link.href, link.title.plain())) + self.render(BlockLink(link.href, item.plain())) else: self.writer.write("* ") self.render(item) |