Created
October 6, 2019 22:15
-
-
Save dacre-denny/f8fc1a04774fda04549781678b37a4a4 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
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