| | import escape from 'lodash/escape' |
| | const wordsLongerThan18Chars = /[\S]{18,}/g |
| | const camelCaseChars = /([a-z])([A-Z])/g |
| | const underscoresAfter12thChar = /([\w:]{12}[^_]*?)_/g |
| | const slashChars = /([/\\])/g |
| |
|
| | |
| | |
| | |
| | export default function wrapCodeTerms() { |
| | const codeTerms = document.querySelectorAll('#article-contents table code') |
| | if (!codeTerms) return |
| |
|
| | for (const node of codeTerms) { |
| | |
| | |
| | |
| | const oldText = escape(node.textContent || '') |
| | const anchorChild = node.querySelector('a') |
| |
|
| | const newText = oldText.replace(wordsLongerThan18Chars, (str) => { |
| | return ( |
| | str |
| | |
| | .replace(camelCaseChars, '$1<wbr>$2') |
| | |
| | |
| | |
| | .replace(underscoresAfter12thChar, '$1_<wbr>') |
| | |
| | .replace(slashChars, '$1<wbr>') |
| | ) |
| | }) |
| |
|
| | if (anchorChild && node.childNodes.length === 1) { |
| | anchorChild.innerHTML = anchorChild.innerHTML.replace(oldText, newText) |
| | } else { |
| | node.innerHTML = node.innerHTML.replace(oldText, newText) |
| | } |
| | } |
| | } |
| |
|