summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--wikimini/document.py20
-rw-r--r--wikimini/formats/gemtext.py4
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)