Skip to content

Commit ec94705

Browse files
JorjMcKiejulian-smith-artifex-com
authored andcommitted
Change Xml.add_link() method
We should support two different parameters, the HTML "href" value, which refers to the link target, and independently the text that is visible to the user. Also document that `Xml.add_paragraph()` isa context manager.
1 parent b3d8d61 commit ec94705

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

docs/xml-class.rst

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,17 +103,20 @@ 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(link)
106+
.. method:: add_link(href=None, text=None)
107107

108-
Add an :htmlTag:`a` tag.
108+
Add an :htmlTag:`a` tag - inline element, treated like text.
109+
110+
:arg str href: the URL target.
111+
:arg str text: the text to display. If omitted, the ``href`` text is shown instead.
109112

110113
.. method:: add_number_list
111114

112115
Add an :htmlTag:`ol` tag, context manager.
113116

114117
.. method:: add_paragraph
115118

116-
Add a :htmlTag:`p` tag.
119+
Add a :htmlTag:`p` tag, context manager.
117120

118121
.. method:: add_span
119122

fitz/fitz.i

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13122,10 +13122,16 @@ struct Xml
1312213122
self.append_child(child)
1312313123
return child
1312413124

13125-
def add_link(self, text=None):
13125+
def add_link(self, href=None, text=None):
1312613126
"""Add a hyperlink ("a" tag)"""
1312713127
child = self.create_element("a")
13128-
if type(text) is str:
13128+
if not isinstance(href, str):
13129+
href = text
13130+
if not isinstance(text, str):
13131+
text = href
13132+
if href:
13133+
child.set_attribute("href", href)
13134+
if text:
1312913135
child.append_child(self.create_text_node(text))
1313013136
prev = self.span_bottom()
1313113137
if prev == None:

0 commit comments

Comments
 (0)