Created
October 4, 2018 15:24
-
-
Save ferrao/2451e982069a6ac8d1a1f26df311f120 to your computer and use it in GitHub Desktop.
React DraftJS WYSIWYG prism syntax highlight
This file contains 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 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