зеркало из https://github.com/github/docs.git
Don't skip code term wrapping with single anchor child (#28175)
Wrap for single anchor child
This commit is contained in:
Родитель
ce016d7162
Коммит
2339bef120
|
@ -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() {
|
|||
)
|
||||
})
|
||||
|
||||
if (anchorChild && node.childNodes.length === 1) {
|
||||
anchorChild.innerHTML = anchorChild.innerHTML.replace(oldText, newText)
|
||||
} else {
|
||||
node.innerHTML = node.innerHTML.replace(oldText, newText)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче