MCPcopy Create free account
hub / github.com/scanny/python-pptx / _Hyperlink

Class _Hyperlink

src/pptx/text/text.py:425–464  ·  view source on GitHub ↗

Text run hyperlink object. Corresponds to `a:hlinkClick` child element of the run's properties element (`a:rPr`).

Source from the content-addressed store, hash-verified

423
424
425class _Hyperlink(Subshape):
426 """Text run hyperlink object.
427
428 Corresponds to `a:hlinkClick` child element of the run's properties element (`a:rPr`).
429 """
430
431 def __init__(self, rPr: CT_TextCharacterProperties, parent: ProvidesPart):
432 super(_Hyperlink, self).__init__(parent)
433 self._rPr = rPr
434
435 @property
436 def address(self) -> str | None:
437 """The URL of the hyperlink.
438
439 Read/write. URL can be on http, https, mailto, or file scheme; others may work.
440 """
441 if self._hlinkClick is None:
442 return None
443 return self.part.target_ref(self._hlinkClick.rId)
444
445 @address.setter
446 def address(self, url: str | None):
447 # implements all three of add, change, and remove hyperlink
448 if self._hlinkClick is not None:
449 self._remove_hlinkClick()
450 if url:
451 self._add_hlinkClick(url)
452
453 def _add_hlinkClick(self, url: str):
454 rId = self.part.relate_to(url, RT.HYPERLINK, is_external=True)
455 self._rPr.add_hlinkClick(rId)
456
457 @property
458 def _hlinkClick(self) -> CT_Hyperlink | None:
459 return self._rPr.hlinkClick
460
461 def _remove_hlinkClick(self):
462 assert self._hlinkClick is not None
463 self.part.drop_rel(self._hlinkClick.rId)
464 self._rPr._remove_hlinkClick() # pyright: ignore[reportPrivateUsage]
465
466
467class _Paragraph(Subshape):

Callers 3

hlinkMethod · 0.90
hlink_with_hlinkClickMethod · 0.90
hyperlinkMethod · 0.85

Calls

no outgoing calls

Tested by 2

hlinkMethod · 0.72
hlink_with_hlinkClickMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…