From 2339bef12029e41321e58621631fa7dc95a799e1 Mon Sep 17 00:00:00 2001 From: Robert Sese <734194+rsese@users.noreply.github.com> Date: Thu, 2 Jun 2022 11:56:55 -0500 Subject: [PATCH] Don't skip code term wrapping with single anchor child (#28175) Wrap for single anchor child --- components/lib/wrap-code-terms.ts | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/components/lib/wrap-code-terms.ts b/components/lib/wrap-code-terms.ts index 065a590ef7..4465c4a353 100644 --- a/components/lib/wrap-code-terms.ts +++ b/components/lib/wrap-code-terms.ts @@ -12,12 +12,11 @@ export default function wrapCodeTerms() { if (!codeTerms) return codeTerms.forEach((node) => { - // Return early if a child node is an anchor element - const hasChildAnchor = Array.from(node.childNodes).some((child) => child.nodeName === 'A') - if (hasChildAnchor) return - - // Do the wrapping on the inner text only + // Do the wrapping on the inner text only. With anchor element children + // we'll only handle the case where the code term only has a single child + // and that child is an anchor element. const oldText = escape(node.textContent || '') + const anchorChild = node.querySelector('a') const newText = oldText.replace(wordsLongerThan18Chars, (str) => { return ( @@ -33,6 +32,10 @@ export default function wrapCodeTerms() { ) }) - node.innerHTML = node.innerHTML.replace(oldText, newText) + if (anchorChild && node.childNodes.length === 1) { + anchorChild.innerHTML = anchorChild.innerHTML.replace(oldText, newText) + } else { + node.innerHTML = node.innerHTML.replace(oldText, newText) + } }) }