Skip to content

Commit a730bc6

Browse files
JorjMcKiejulian-smith-artifex-com
authored andcommitted
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.
1 parent ec94705 commit a730bc6

File tree

2 files changed

+4
-8
lines changed

2 files changed

+4
-8
lines changed

docs/xml-class.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ There is no need to ever directly construct an :ref:`Xml` object: after creating
103103
: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.
104104
: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.
105105

106-
.. method:: add_link(href=None, text=None)
106+
.. method:: add_link(href, text=None)
107107

108108
Add an :htmlTag:`a` tag - inline element, treated like text.
109109

fitz/fitz.i

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13122,17 +13122,13 @@ struct Xml
1312213122
self.append_child(child)
1312313123
return child
1312413124

13125-
def add_link(self, href=None, text=None):
13125+
def add_link(self, href, text=None):
1312613126
"""Add a hyperlink ("a" tag)"""
1312713127
child = self.create_element("a")
13128-
if not isinstance(href, str):
13129-
href = text
1313013128
if not isinstance(text, str):
1313113129
text = href
13132-
if href:
13133-
child.set_attribute("href", href)
13134-
if text:
13135-
child.append_child(self.create_text_node(text))
13130+
child.set_attribute("href", href)
13131+
child.append_child(self.create_text_node(text))
1313613132
prev = self.span_bottom()
1313713133
if prev == None:
1313813134
prev = self

0 commit comments

Comments
 (0)