Skip to content

Instantly share code, notes, and snippets.

@thecrypticace
Last active April 25, 2020 04:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thecrypticace/79084be1b2fe38a09756734a20545421 to your computer and use it in GitHub Desktop.
Save thecrypticace/79084be1b2fe38a09756734a20545421 to your computer and use it in GitHub Desktop.
Prefix All Tailwind UI classes
// Prefix all Tailwind UI classes with "tw-"
// Works as of 2020-04-25
// Examples:
// mx-4 -> tw-mx-4
// -mx-4 -> tw--mx-4
// lg:mx-4 -> lg:tw-mx-4
// lg:-mx-4 -> lg:tw--mx-4
const prefix = "tw-"
Array
.from(document.querySelectorAll("code .token.attr-name"))
.filter(el => el.textContent === "class")
.map(el => el.nextElementSibling)
.flatMap(el => [...el.childNodes])
.filter(n => n.nodeType === 3)
.map(n => (n.parentNode.dataset.value = n.parentNode.dataset.value || n.textContent, n))
.forEach(n => {
n.textContent = n.parentNode.dataset.value
.split(/\s+/g)
.map(c => c.replace(/^(?!.*:)|(:)/g, `$1${prefix}`))
.join(" ")
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment