Created
February 2, 2017 15:50
-
-
Save davidpmccormick/f1e24eceba13bdaf144af154c53a1c7a to your computer and use it in GitHub Desktop.
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
function unwrapChildren(node, tag) { | |
const treeAdapter = parse.treeAdapters.default; | |
const nodeTagName = treeAdapter.getTagName(node); | |
const newEl = treeAdapter.createElement(nodeTagName); | |
const childNodes = treeAdapter.getChildNodes(node); | |
childNodes.forEach((childNode) => { | |
if (childNode.nodeName !== tag) { | |
treeAdapter.appendChild(newEl, childNode); | |
} else { | |
const childContent = treeAdapter.getChildNodes(childNode); | |
childContent.forEach((item) => { | |
treeAdapter.appendChild(newEl, item); | |
}); | |
} | |
}); | |
return newEl; | |
} |
Or is there an edge case I am missing e.g:
<p class="standfirst">
<em>
some stuff that is italic <a href="asite.com">Somethinghere</a> and more italic
</em>
Back to plane old straight up text, maybe some <a href="link.com">links too</a>
</p>
Would it be simpler to make this more specific
Yeah – sounds good to me. I haven't managed to get this working in any way, yet though. Not sure what's wrong with it. Shout if you have any ideas.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Would it be simpler to make this more specific e.g. unwrap
em
?And basically say if it's
em
, empty the parent and fill it with theem
's children?