From a730bc6d8e77c2b39586cb826d79c7c70a1030f5 Mon Sep 17 00:00:00 2001 From: "Jorj X. McKie" Date: Fri, 28 Oct 2022 14:11:33 -0400 Subject: [PATCH] Make "href" a mandatory argument in Xml.add_link() The link target must always be specified. Only the its display in the text is optional. --- docs/xml-class.rst | 2 +- fitz/fitz.i | 10 +++------- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/docs/xml-class.rst b/docs/xml-class.rst index 1f5c688c8..491d8b86c 100644 --- a/docs/xml-class.rst +++ b/docs/xml-class.rst @@ -103,7 +103,7 @@ There is no need to ever directly construct an :ref:`Xml` object: after creating :arg width: if provided, either an absolute (int) value, or a percentage string like "30%". A percentage value refers to the width of the specified ``where`` rectangle in :meth:`Story.place`. If this value is provided and ``height`` is omitted, the image will be included keeping its aspect ratio. :arg height: if provided, either an absolute (int) value, or a percentage string like "30%". A percentage value refers to the height of the specified ``where`` rectangle in :meth:`Story.place`. If this value is provided and ``width`` is omitted, the image's aspect ratio will be honored. - .. method:: add_link(href=None, text=None) + .. method:: add_link(href, text=None) Add an :htmlTag:`a` tag - inline element, treated like text. diff --git a/fitz/fitz.i b/fitz/fitz.i index 837766641..7e4289c29 100644 --- a/fitz/fitz.i +++ b/fitz/fitz.i @@ -13122,17 +13122,13 @@ struct Xml self.append_child(child) return child - def add_link(self, href=None, text=None): + def add_link(self, href, text=None): """Add a hyperlink ("a" tag)""" child = self.create_element("a") - if not isinstance(href, str): - href = text if not isinstance(text, str): text = href - if href: - child.set_attribute("href", href) - if text: - child.append_child(self.create_text_node(text)) + child.set_attribute("href", href) + child.append_child(self.create_text_node(text)) prev = self.span_bottom() if prev == None: prev = self