Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A more elegant solution to formatting
useEffect( () => {
// formats the Markdown
function styleChildren(children) {
children.forEach((child) => {
let tagIt = child.tagName
child.classList = blogStyle[tagIt]
if(tagIt === 'CODE' && child.innerText.length > 15){child.classList = longCode[tagIt]}
if(tagIt === 'CODE' && child.innerText.length <= 15){child.classList = shortCode[tagIt]}
if(child.children) {
let grandChildren = [...child.children]
styleChildren(grandChildren)
}
})
}
let post = document.getElementById('post-data')
let postChildren = [...post.children]
styleChildren(postChildren)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.