insert HTML with style into a QuillJS?

荒凉一梦 提交于 2021-01-28 04:23:38

问题


How to insert html with style (css) to quillJS. I have html like:

var data = '<p style="color: #f00">tesst</p>';

or

var data = '<style> .pp { color: #0f0;} </style>
<p class="pp">tesst</p>';

i paste it by

quill_arr[$('#docbody').attr('quill-id')].clipboard.dangerouslyPasteHTML(data);

text load but format is:

<p>tesst</p>

without all styles. Please help.


回答1:


Putting a <span> with the styles inside a <p> seemed to work.

var data = '<p><span style="color: red;">test</span></p>'
quill.clipboard.dangerouslyPasteHTML(data);

Checkout this

<!-- Include stylesheet -->
<link href="https://cdn.quilljs.com/1.3.6/quill.snow.css" rel="stylesheet">

<!-- Create the editor container -->
<div id="editor"></div>

<!-- Include the Quill library -->
<script src="https://cdn.quilljs.com/1.3.6/quill.js"></script>

<script>
  // Initialize Quill editor
  var quill = new Quill('#editor', {
    theme: 'snow'
  });
  
  // Insert HTML with style
  var data = '<p><span style="color: red;">Hello World!</span></p>'
  quill.clipboard.dangerouslyPasteHTML(data);
</script>


来源:https://stackoverflow.com/questions/57002748/insert-html-with-style-into-a-quilljs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!