Skip to content

Instantly share code, notes, and snippets.

@ferrao
Created October 4, 2018 15:24
Show Gist options
  • Save ferrao/2451e982069a6ac8d1a1f26df311f120 to your computer and use it in GitHub Desktop.
Save ferrao/2451e982069a6ac8d1a1f26df311f120 to your computer and use it in GitHub Desktop.
React DraftJS WYSIWYG prism syntax highlight
const convertContent = content => {
const blockMap = content.getBlockMap();
let newBlockMap = Map();
blockMap.valueSeq().forEach(block => {
if (block.getType() === 'code') {
const data = block.getData().merge({ language: 'javascript' });
const newBlock = block.merge({ type: 'code-block', data });
newBlockMap = newBlockMap.set(block.key, newBlock);
}
});
const newContent = content.merge({
blockMap: blockMap.merge(newBlockMap)
});
return newContent;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment