I've created a customblot
, to handle span conversion but for some reason any text after <span>
is being treated as a span too and causing the following:
Uncaught s: [Parchment] Unable to create [object HTMLSpanElement] blot
this is the test case i've been using
<p id="x4uqkat" class="x4uqkat--text__typography a98db97--highlight__border">this is text <span class="test">is here</span> replaceable</p>
</div>
Code below does preserve but it's incorrectly converting replaceable
var Inline = Quill.import('blots/inline');
var Delta = Quill.import('delta');
class CustomSpan extends Inline {
static blotName = 'customSpan';
static tagName = 'span';
static formats(domNode) {
const className = domNode.getAttribute('class');
console.log('Formats called with:', className, domNode);
return className ? { customSpan: className } : {};
}
format(name, value) {
if (name === 'customSpan') {
if (value) {
this.domNode.setAttribute('class', value);
} else {
this.domNode.removeAttribute('class');
}
} else {
super.format(name, value);
}
}
}
Quill.register(CustomSpan,false);
const quill = new Quill("#editor", {
modules: {
toolbar: false,
},
theme: "snow" ,
});
quill.clipboard.addMatcher('SPAN', function(node, delta) {
const className = node.getAttribute('class');
console.log('Processing span with class:', className);
if (!className) return delta; // Ignore spans without class
let newDelta = new Delta();
// Apply customSpan format only to the text inside the span
delta.ops.forEach(op => {
if (typeof op.insert === 'string') {
newDelta.insert(op.insert, { customSpan: className });
} else {
newDelta.insert(op.insert);
}
});
return newDelta;
});
JSFiddle
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745305934a4621709.html
评论列表(0条)