Skip to content

Commit

Permalink
Fold the <l> element into its child in all cases. Fixes #2739
Browse files Browse the repository at this point in the history
  • Loading branch information
tabatkins committed Dec 14, 2023
1 parent fbc1bf1 commit aeadbad
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 9 deletions.
1 change: 1 addition & 0 deletions bikeshed/h/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
tagName,
textContent,
textContentIgnoringDecorative,
transferAttributes,
treeAttr,
unescape,
unfixTypography,
Expand Down
6 changes: 6 additions & 0 deletions bikeshed/h/dom.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
9 changes: 5 additions & 4 deletions bikeshed/shorthands/oldShorthands.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,12 +265,11 @@ def replacer(reg: re.Pattern, rep: t.Callable[[re.Match], t.NodeT], el: t.Elemen
# Move the linking attributes from <l> to the <a>
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

Expand All @@ -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)
Expand Down
6 changes: 1 addition & 5 deletions tests/links007.html
Original file line number Diff line number Diff line change
Expand Up @@ -743,11 +743,7 @@ <h2 class="no-num no-toc no-ref" id="contents">Table of Contents</h2>
<p><code class="idl"><a attr1="foo" class="idl-code" data-link-type="attribute" href="#dom-foo-bar" id="ref-for-dom-foo-bar②">bar</a></code></p>
<pre class="highlight">navigator<c- p>.</c->bluetooth<c- p>.</c-><code class="idl"><a data-link-type="idl" href="#dom-foo-baz" id="ref-for-dom-foo-baz">baz</a></code><c- p>({...});</c->
</pre>
<p>
<dfn class="css" data-dfn-for="color" data-dfn-type="value" data-export id="valdef-color-transparent">transparent<a class="self-link" href="#valdef-color-transparent"></a></dfn> <dfn class="css" data-dfn-type="type" data-export id="typedef-color">&lt;color><a class="self-link" href="#typedef-color"></a></dfn>
<l data-link-spec="css-color-4"><a class="css" data-link-type="maybe" href="https://drafts.csswg.org/css-color-4/#valdef-color-transparent" id="ref-for-valdef-color-transparent">transparent</a></l>
<l data-link-spec="css-color-4"><a class="production css" data-link-type="type" href="https://drafts.csswg.org/css-color-4/#typedef-color" id="ref-for-typedef-color" title="Expands to: aliceblue | antiquewhite | aqua | aquamarine | azure | beige | bisque | black | blanchedalmond | blue | blueviolet | brown | burlywood | cadetblue | chartreuse | chocolate | coral | cornflowerblue | cornsilk | crimson | currentcolor | cyan | darkblue | darkcyan | darkgoldenrod | darkgray | darkgreen | darkgrey | darkkhaki | darkmagenta | darkolivegreen | darkorange | darkorchid | darkred | darksalmon | darkseagreen | darkslateblue | darkslategray | darkslategrey | darkturquoise | darkviolet | deeppink | deepskyblue | dimgray | dimgrey | dodgerblue | firebrick | floralwhite | forestgreen | fuchsia | gainsboro | ghostwhite | gold | goldenrod | gray | green | greenyellow | grey | honeydew | hotpink | indianred | indigo | ivory | khaki | lavender | lavenderblush | lawngreen | lemonchiffon | lightblue | lightcoral | lightcyan | lightgoldenrodyellow | lightgray | lightgreen | lightgrey | lightpink | lightsalmon | lightseagreen | lightskyblue | lightslategray | lightslategrey | lightsteelblue | lightyellow | lime | limegreen | linen | magenta | maroon | mediumaquamarine | mediumblue | mediumorchid | mediumpurple | mediumseagreen | mediumslateblue | mediumspringgreen | mediumturquoise | mediumvioletred | midnightblue | mintcream | mistyrose | moccasin | navajowhite | navy | none | oldlace | olive | olivedrab | orange | orangered | orchid | palegoldenrod | palegreen | paleturquoise | palevioletred | papayawhip | peachpuff | peru | pink | plum | powderblue | purple | rebeccapurple | red | rosybrown | royalblue | saddlebrown | salmon | sandybrown | seagreen | seashell | sienna | silver | skyblue | slateblue | slategray | slategrey | snow | springgreen | steelblue | tan | teal | thistle | tomato | transparent | turquoise | violet | wheat | white | whitesmoke | yellow | yellowgreen">&lt;color></a></l>
</p>
<p><dfn class="css" data-dfn-for="color" data-dfn-type="value" data-export id="valdef-color-transparent">transparent<a class="self-link" href="#valdef-color-transparent"></a></dfn> <dfn class="css" data-dfn-type="type" data-export id="typedef-color">&lt;color><a class="self-link" href="#typedef-color"></a></dfn> <a class="css" data-link-type="maybe" href="https://drafts.csswg.org/css-color-4/#valdef-color-transparent" id="ref-for-valdef-color-transparent">transparent</a> <a class="production css" data-link-type="type" href="https://drafts.csswg.org/css-color-4/#typedef-color" id="ref-for-typedef-color" title="Expands to: aliceblue | antiquewhite | aqua | aquamarine | azure | beige | bisque | black | blanchedalmond | blue | blueviolet | brown | burlywood | cadetblue | chartreuse | chocolate | coral | cornflowerblue | cornsilk | crimson | currentcolor | cyan | darkblue | darkcyan | darkgoldenrod | darkgray | darkgreen | darkgrey | darkkhaki | darkmagenta | darkolivegreen | darkorange | darkorchid | darkred | darksalmon | darkseagreen | darkslateblue | darkslategray | darkslategrey | darkturquoise | darkviolet | deeppink | deepskyblue | dimgray | dimgrey | dodgerblue | firebrick | floralwhite | forestgreen | fuchsia | gainsboro | ghostwhite | gold | goldenrod | gray | green | greenyellow | grey | honeydew | hotpink | indianred | indigo | ivory | khaki | lavender | lavenderblush | lawngreen | lemonchiffon | lightblue | lightcoral | lightcyan | lightgoldenrodyellow | lightgray | lightgreen | lightgrey | lightpink | lightsalmon | lightseagreen | lightskyblue | lightslategray | lightslategrey | lightsteelblue | lightyellow | lime | limegreen | linen | magenta | maroon | mediumaquamarine | mediumblue | mediumorchid | mediumpurple | mediumseagreen | mediumslateblue | mediumspringgreen | mediumturquoise | mediumvioletred | midnightblue | mintcream | mistyrose | moccasin | navajowhite | navy | none | oldlace | olive | olivedrab | orange | orangered | orchid | palegoldenrod | palegreen | paleturquoise | palevioletred | papayawhip | peachpuff | peru | pink | plum | powderblue | purple | rebeccapurple | red | rosybrown | royalblue | saddlebrown | salmon | sandybrown | seagreen | seashell | sienna | silver | skyblue | slateblue | slategray | slategrey | snow | springgreen | steelblue | tan | teal | thistle | tomato | transparent | turquoise | violet | wheat | white | whitesmoke | yellow | yellowgreen">&lt;color></a></p>
</main>
<h2 class="no-num no-ref heading settled" id="index"><span class="content">Index</span></h2>
<h3 class="no-num no-ref heading settled" id="index-defined-here"><span class="content">Terms defined by this specification</span></h3>
Expand Down

0 comments on commit aeadbad

Please sign in to comment.