From aeadbad303eba32069db69bcc72b02dc3b7207cc Mon Sep 17 00:00:00 2001 From: Tab Atkins-Bittner Date: Thu, 14 Dec 2023 13:20:10 -0800 Subject: [PATCH] Fold the element into its child in all cases. Fixes #2739 --- bikeshed/h/__init__.py | 1 + bikeshed/h/dom.py | 6 ++++++ bikeshed/shorthands/oldShorthands.py | 9 +++++---- tests/links007.html | 6 +----- 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/bikeshed/h/__init__.py b/bikeshed/h/__init__.py index 0b30e41d16..bcf0b1f953 100644 --- a/bikeshed/h/__init__.py +++ b/bikeshed/h/__init__.py @@ -71,6 +71,7 @@ tagName, textContent, textContentIgnoringDecorative, + transferAttributes, treeAttr, unescape, unfixTypography, diff --git a/bikeshed/h/dom.py b/bikeshed/h/dom.py index 7a6a557db0..bb3c358186 100644 --- a/bikeshed/h/dom.py +++ b/bikeshed/h/dom.py @@ -424,6 +424,12 @@ def replaceNode(node: t.ElementT, *replacements: t.NodesT) -> t.NodesT | None: return None +def transferAttributes(source: t.ElementT, target: t.ElementT) -> t.ElementT: + for k, v in source.attrib.items(): + target.set(k, v) + return target + + def appendContents(el: t.ElementT, container: t.ElementT | t.Iterable[t.NodesT]) -> t.ElementT: # Accepts either an iterable *or* a container element if isElement(container): diff --git a/bikeshed/shorthands/oldShorthands.py b/bikeshed/shorthands/oldShorthands.py index bde896061b..e35a9e2422 100644 --- a/bikeshed/shorthands/oldShorthands.py +++ b/bikeshed/shorthands/oldShorthands.py @@ -265,12 +265,11 @@ def replacer(reg: re.Pattern, rep: t.Callable[[re.Match], t.NodeT], el: t.Elemen # Move the linking attributes from to the attrTarget: t.ElementT | None if result.tag == "a": - attrTarget = result + h.transferAttributes(el, result) else: attrTarget = h.find("a", result) - if attrTarget is not None: - for k, v in el.attrib.items(): - attrTarget.set(k, v) + if attrTarget is not None: + h.transferAttributes(el, attrTarget) return True return False @@ -279,6 +278,8 @@ def replacer(reg: re.Pattern, rep: t.Callable[[re.Match], t.NodeT], el: t.Elemen # are already specially handled by fixAwkwardCSSShorthands(). child = h.hasOnlyChild(el) if child is not None and child.get("bs-autolink-syntax") is not None: + h.replaceNode(el, child) + h.transferAttributes(el, child) continue text = h.textContent(el) diff --git a/tests/links007.html b/tests/links007.html index 6032a4b6ea..a655f384e7 100644 --- a/tests/links007.html +++ b/tests/links007.html @@ -743,11 +743,7 @@

Table of Contents

bar

navigator.bluetooth.baz({...});
 
-

- transparent <color> - transparent - <color> -

+

transparent <color> transparent <color>

Index

Terms defined by this specification