Skip to content

Instantly share code, notes, and snippets.

@briandk
Created September 28, 2017 00:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save briandk/aa7f26653383b9923ffbb4ac5db7ac7e to your computer and use it in GitHub Desktop.
Save briandk/aa7f26653383b9923ffbb4ac5db7ac7e to your computer and use it in GitHub Desktop.
Converting a quill delta into a string
// 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