diff --git a/kumascript/src/api/util.ts b/kumascript/src/api/util.ts index 0e7f0c2e9cb3..3a5655b4fcb4 100644 --- a/kumascript/src/api/util.ts +++ b/kumascript/src/api/util.ts @@ -224,15 +224,11 @@ export class HTMLTool { $element.attr("id", id); if (isDt) { - // Remove empty anchor links. - // This happens if the term already links to a page. - $element.find("a[data-link-to-id = true]:empty").remove(); - - // Link remaining anchor links to the term's ID. - $element - .find("a[data-link-to-id = true]") - .attr("href", "#" + id) - .removeAttr("data-link-to-id"); + // Link the first element child to the ID. + const firstContent = $element.contents().first(); + if (!firstContent.is("a") && firstContent.find("a").length === 0) { + $(firstContent).wrap(``); + } } }); return this; diff --git a/markdown/m2h/handlers/dl.ts b/markdown/m2h/handlers/dl.ts index 6aca68c03438..252356a1d6b2 100644 --- a/markdown/m2h/handlers/dl.ts +++ b/markdown/m2h/handlers/dl.ts @@ -38,21 +38,19 @@ export function asDefinitionList(h, node) { DEFINITION_PREFIX.length ); - const [firstDtChild, ...dtChildren] = all(h, { - ...node, - children: - terms.length == 1 && terms[0].type == "paragraph" - ? terms[0].children - : terms, - }); - if (firstDtChild) { - dtChildren.unshift( - h(node, "a", { "data-link-to-id": "true" }, [firstDtChild]) - ); - } - return [ - h(node, "dt", {}, dtChildren), + h( + node, + "dt", + {}, + all(h, { + ...node, + children: + terms.length == 1 && terms[0].type == "paragraph" + ? terms[0].children + : terms, + }) + ), h( node, "dd", diff --git a/testing/content/files/en-us/markdown/tool/m2h/expected.html b/testing/content/files/en-us/markdown/tool/m2h/expected.html index ede7e703085a..ce9a753976d4 100644 --- a/testing/content/files/en-us/markdown/tool/m2h/expected.html +++ b/testing/content/files/en-us/markdown/tool/m2h/expected.html @@ -11,11 +11,11 @@
We have our own syntax for <dl>
.
a definition
another definition
Definitions can include block elements:
@@ -23,11 +23,11 @@And of course <dl>
elements can be nested inside <dd>
:
a definition
another nested definition
...and even definition lists:
that have definitions
and as usual, the definitions can include block elements:
.likeCodeBlocks { diff --git a/testing/tests/index.test.ts b/testing/tests/index.test.ts index 25c20f221c5d..ac0708f8e318 100644 --- a/testing/tests/index.test.ts +++ b/testing/tests/index.test.ts @@ -1559,7 +1559,7 @@ test("basic markdown rendering", () => { expect($("article em")).toHaveLength(1); expect($("article ul li")).toHaveLength(6); expect($('article a[href^="/"]')).toHaveLength(2); - expect($('article a[href^="#"]')).toHaveLength(5); + expect($('article a[href^="#"]')).toHaveLength(6); expect($("article pre")).toHaveLength(4); expect($("article pre.notranslate")).toHaveLength(4); expect($("article pre.css").hasClass("brush:")).toBe(true);