Created
September 28, 2017 00:55
-
-
Save briandk/aa7f26653383b9923ffbb4ac5db7ac7e to your computer and use it in GitHub Desktop.
Converting a quill delta into a string
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
// Assuming the delta is entirely insert operations, | |
// this example wouuld convert bolded text to html bolded text. | |
// The key logic here is mapping over the insert ops, | |
// then joining the resulting array on the empty string | |
html = delta.slice(0, 500).ops.map(function(op) { | |
if (typeof op.insert !== 'string') return ''; | |
let html = op.insert; | |
if (op.attributes.bold) { | |
html = '<strong>' + html + '</strong>'; | |
} | |
return html; | |
}).join(''); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment