* Update packages landing page * Docs updates for Container reg GA * Update billing note * Delete CR feature preview files * Fix broken link * Remove github.ref from workflows See https://github.com/github/docs-internal/pull/19953 * Put 3rd party action message in a reusable * Update content/billing/managing-billing-for-github-packages/about-billing-for-github-packages.md Co-authored-by: Lucas Costi <lucascosti@users.noreply.github.com> * Update content/packages/learn-github-packages/deleting-and-restoring-a-package.md Co-authored-by: Lucas Costi <lucascosti@users.noreply.github.com> * Update content/packages/working-with-a-github-packages-registry/migrating-to-the-container-registry-from-the-docker-registry.md Co-authored-by: Lucas Costi <lucascosti@users.noreply.github.com> * Update content/packages/working-with-a-github-packages-registry/migrating-to-the-container-registry-from-the-docker-registry.md Co-authored-by: Lucas Costi <lucascosti@users.noreply.github.com> * Update content/packages/working-with-a-github-packages-registry/working-with-the-container-registry.md Co-authored-by: Lucas Costi <lucascosti@users.noreply.github.com> * Update content/packages/managing-github-packages-using-github-actions-workflows/publishing-and-installing-a-package-with-github-actions.md Co-authored-by: Lucas Costi <lucascosti@users.noreply.github.com> * fix bug with wbr breaking a link inside a code tag inside a table * Make revisions suggested by Nilofer See https://github.com/github/docs-internal/pull/19987/files#r655014673 * Mention that migration is happening gradually * Reapply change suggested by Shayne * Fix punctuation * Remove bad link Co-authored-by: Lucas Costi <lucascosti@users.noreply.github.com> Co-authored-by: Sarah Schneider <sarahs@github.com> Co-authored-by: Sarah Schneider <sarahs@users.noreply.github.com> Co-authored-by: Melanie Yarbrough <11952755+myarb@users.noreply.github.com>
39 lines
1.5 KiB
TypeScript
39 lines
1.5 KiB
TypeScript
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
|
|
|
|
// This module improves table rendering on reference pages by inserting a <wbr>
|
|
// tag in code terms that use camelcase, slashes, or underscores, 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 => {
|
|
// 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
|
|
const oldText = escape(node.textContent || '')
|
|
|
|
const newText = oldText.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>')
|
|
// Some Actions reference pages have tables with code terms separated by slashes
|
|
.replace(slashChars, '$1<wbr>')
|
|
)
|
|
})
|
|
|
|
node.innerHTML = node.innerHTML.replace(oldText, newText)
|
|
})
|
|
}
|