Skip to content

Commit

Permalink
Make "href" a mandatory argument in Xml.add_link()
Browse files Browse the repository at this point in the history
The link target must always be specified. Only the its display in the text is optional.
  • Loading branch information
JorjMcKie authored and julian-smith-artifex-com committed Nov 1, 2022
1 parent ec94705 commit a730bc6
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
2 changes: 1 addition & 1 deletion docs/xml-class.rst
Expand Up @@ -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.

Expand Down
10 changes: 3 additions & 7 deletions fitz/fitz.i
Expand Up @@ -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
Expand Down

0 comments on commit a730bc6

Please sign in to comment.