admin管理员组文章数量:1122846
I am trying to insert a template into the editor without any changes.
import React, { useEffect, useRef, useState } from 'react';
import { Editor, EditorProps, EditorTextChangeEvent } from "primereact/editor";
import juice from "juice";
import Quill from 'quill';
import './index.scss'
import { htmlDataContent } from "./__mocks__/htmlData";
import { Button } from "primereact/button";
export const HTMLEditor: React.FC<THTMLEditorProps> = (props) => {
const [value, setValue] = useState<string>(juice(htmlDataContent));
const editorRef = useRef<Editor>(null); // Ссылка на Editor
const htmlTemplate = `
<div style="font-size: 24px;" class="big">Hello, World!</div>
`;
const setQuillContent = (quill: any) => {
const quillFromEditorInstance = editorRef.current?.getQuill();
quillFromEditorInstance.clipboard.dangerouslyPasteHTML(htmlTemplate);
};
return (
<div className={'html-editor-container'}>
<Editor
onLoad={setQuillContent}
ref={editorRef}
/>
</div>
);
}
But Quill still transforms the template, and in the DOM (Chrome DevTools):
<div style="font-size: 24px;" class="big">Hello, World!</div
> turns into <p>Hello, World!</p>
.
How can I ensure that the passed template is displayed without changes? Or at least, how can I ensure that classes, IDs, and inline styles are applied? Thank you in advance.
I tried to do it this way:
// Extend Quill to support custom classes
const Block: any = Quill.import('blots/block');
class CustomBlock extends Block {
static blotName = 'custom';
static tagName = 'div';
static formats(domNode: HTMLElement) {
return domNode.getAttribute('class');
}
format(name: string, value: any) {
if (name === 'class' && value) {
(this.domNode as HTMLElement).setAttribute('class', value);
} else {
super.format(name, value);
}
}
}
However, inline styles and the class attribute are still not applied to the element. The only thing that changed is that instead of the p element, a div element is displayed in the DOM.
本文标签: reactjsdangerouslyPasteHTML dosent work for quill (Primereact)Stack Overflow
版权声明:本文标题:reactjs - dangerouslyPasteHTML dosent work for quill (Primereact) - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736302787a1931655.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论