Skip to content

Instantly share code, notes, and snippets.

@dacre-denny
Created October 6, 2019 22:15
Show Gist options
  • Save dacre-denny/f8fc1a04774fda04549781678b37a4a4 to your computer and use it in GitHub Desktop.
Save dacre-denny/f8fc1a04774fda04549781678b37a4a4 to your computer and use it in GitHub Desktop.
const content = editorContent.content
function parseContent (arr) {
arr.forEach((item, index, array)=>{
// Check if item contains another array of items, and then iterate
over that one too.
if(item.content){
parseContent(item.content)
}
if(item.marks){
//Extract values from item
// THis is the correct function
const processContent = ({ marks, text }) =>
marks.reduceRight((acc, mark) => ({ type: mark.type, content: [acc]
}), {
type: "text",
text: text
});
// Replace item at array index with result of processContent
array[index] = processContent({ text:item.text, marks:item.marks })
}
})
}
parseContent(content)
return content
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment