我想在quill.js中添加ms word格式,以便找到此函数
public static updateQuillInstance(quillInstance) {
quillInstance.clipboard.addMatcher(Node.ELEMENT_NODE, (node, delta) => {
return this.msftFormattingMatcher(node, delta);
});
}
private static msftFormattingMatcher(node, delta) {
const htmlElementWithMetadata = node.ownerDocument.activeElement;
const allOpSpanElementsNested: any[] = get(htmlElementWithMetadata, 'children[0].children', []);
const allOpSpanElements: any[] = [];
// superscript styling is nested as a child element unlike the others... need to parse
for (let i = 0; i < allOpSpanElementsNested.length; i++) {
if (allOpSpanElementsNested[i].children.length < 1) {
allOpSpanElements.push(allOpSpanElementsNested[i]);
} else {
allOpSpanElements.push(...allOpSpanElementsNested[i].children);
}
}
const op = delta && delta.ops && delta.ops[0];
if (op) {
const correspondingSpan = find(allOpSpanElements, el => {
return op.insert === el.innerText;
});
if (correspondingSpan) {
this.setQuillStyles(op, correspondingSpan);
}
}
return delta;
}
private static setQuillStyles(op, correspondingSpan) {
const verticalAlign = correspondingSpan.style.verticalAlign;
if (verticalAlign === 'super' || verticalAlign === 'sub') {
assign(op.attributes, {script: verticalAlign});
}
const fontFamilyMap = {
// TODO: This can be automatically built from the whitelist
Arial: 'arial',
Georgia: 'georgia',
'Courier New': 'courier-new',
'Comic Sans MS': 'comic-sans-ms', // except this one -_-
Impact: 'impact',
'Lucida Console': 'lucida-console',
};
const fontFamily = correspondingSpan.style.fontFamily;
const font = fontFamily && fontFamilyMap[fontFamily.replace(/"/gi, '')];
if (font) {
assign(op.attributes, {font});
}
}
我代替 private static
及 public static
通过 function
但是,当我在quill.js编辑器中粘贴文本时,我发现错误get未定义。
有人知道我如何修改代码使其正常工作吗?
暂无答案!
目前还没有任何答案,快来回答吧!