1
0
mirror of synced 2025-12-21 10:57:10 -05:00
Files
docs/javascripts/wrap-code-terms.js
Vanessa Yuen 3df90fc9b8 Hello git history spelunker!
Are you looking for something? Here is all of the GitHub Docs history in one single commit. Enjoy! 🎉
2020-09-27 14:10:11 +02:00

23 lines
922 B
JavaScript

const wordsLongerThan18Chars = /[\w:]{18,}/g
const camelCaseChars = /([a-z])([A-Z])/g
const underscoresAfter12thChar = /([\w:]{12}[^_]*?)_/g
// insert a <wbr> tag in code terms that use camelcase or underscore
// inspired by http://heap.ch/blog/2016/01/19/camelwrap/
export default function () {
const codeTerms = document.querySelectorAll('#article-contents table code')
if (!codeTerms) return
codeTerms.forEach(node => {
node.innerHTML = node.innerHTML.replace(wordsLongerThan18Chars, (str) => {
return str
// GraphQL code terms use camelcase
.replace(camelCaseChars, '$1<wbr>$2')
// REST code terms use underscores
// to keep word breaks looking nice, only break on underscores after the 12th char
// so `has_organization_projects` will break after `has_organization` instead of after `has_`
.replace(underscoresAfter12thChar, '$1_<wbr>')
})
})
}