Created
May 22, 2020 00:57
-
-
Save pickleat/e66075084ac0f5716ac7d2a91a550287 to your computer and use it in GitHub Desktop.
A more elegant solution to formatting
This file contains hidden or 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