Skip to content

Instantly share code, notes, and snippets.

@ffkev
Last active December 12, 2025 10:55
Show Gist options
  • Select an option

  • Save ffkev/ce8dda1039632153e62911cbf5564960 to your computer and use it in GitHub Desktop.

Select an option

Save ffkev/ce8dda1039632153e62911cbf5564960 to your computer and use it in GitHub Desktop.
setHTML for Quill pasting with HTML Delta
case 'setHTML':
if (data.html) {
// setTimeout to make this asynchronous and prevent blocking with large HTML
setTimeout(function() {
try {
// Clear existing content
editor.setContents([{ insert: '\n' }], Quill.sources.API);
// For very large HTML, we need to handle it carefully
const htmlString = String(data.html);
// Use dangerouslyPasteHTML with proper error handling
// This method can handle any HTML input, including large content
editor.clipboard.dangerouslyPasteHTML(0, htmlString, Quill.sources.USER);
// Removed the initial newline
const length = editor.getLength();
if (length > 1) {
editor.deleteText(0, 1, Quill.sources.API);
}
sendJsonToFlutter({
type: 'response',
action: 'setHTML',
success: true,
message: 'HTML content set successfully',
timestamp: Date.now()
});
} catch (e) {
sendJsonToFlutter({
type: 'response',
action: 'setHTML',
success: false,
message: 'Error setting HTML: ' + (e.message || String(e)),
timestamp: Date.now()
});
}
}, 0);
} else {
sendJsonToFlutter({
type: 'response',
action: 'setHTML',
success: false,
message: 'No HTML content provided',
timestamp: Date.now()
});
}
break;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment