A more elegant solution to formatting
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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