()
| 8 | // tag in code terms that use camelcase, slashes, or underscores, inspired by |
| 9 | // http://heap.ch/blog/2016/01/19/camelwrap/ |
| 10 | export default function wrapCodeTerms() { |
| 11 | const codeTerms = document.querySelectorAll('#article-contents table code') |
| 12 | if (!codeTerms) return |
| 13 | |
| 14 | codeTerms.forEach((node) => { |
| 15 | // Do the wrapping on the inner text only. With anchor element children |
| 16 | // we'll only handle the case where the code term only has a single child |
| 17 | // and that child is an anchor element. |
| 18 | const oldText = escape(node.textContent || '') |
| 19 | const anchorChild = node.querySelector('a') |
| 20 | |
| 21 | const newText = oldText.replace(wordsLongerThan18Chars, (str) => { |
| 22 | return ( |
| 23 | str |
| 24 | // GraphQL code terms use camelcase |
| 25 | .replace(camelCaseChars, '$1<wbr>$2') |
| 26 | // REST code terms use underscores |
| 27 | // to keep word breaks looking nice, only break on underscores after the 12th char |
| 28 | // so `has_organization_projects` will break after `has_organization` instead of after `has_` |
| 29 | .replace(underscoresAfter12thChar, '$1_<wbr>') |
| 30 | // Some Actions reference pages have tables with code terms separated by slashes |
| 31 | .replace(slashChars, '$1<wbr>') |
| 32 | ) |
| 33 | }) |
| 34 | |
| 35 | if (anchorChild && node.childNodes.length === 1) { |
| 36 | anchorChild.innerHTML = anchorChild.innerHTML.replace(oldText, newText) |
| 37 | } else { |
| 38 | node.innerHTML = node.innerHTML.replace(oldText, newText) |
| 39 | } |
| 40 | }) |
| 41 | } |
no outgoing calls
no test coverage detected