گام بعدی این هست که چجوری به ادیتور محتوای اولیه بدیم.
من از متد setContents استفاده کردم:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>592226 quilljs</title>
<script src="quilljs/quill.js"></script>
<link href="quilljs/quill.snow.css" rel="stylesheet">
<script>
const toolbarOptions = [
[{ 'direction': 'rtl' }],
['bold', 'italic', 'underline', 'strike'],
['blockquote', 'code-block'],
['link', 'image', 'video', 'formula'],
[{ 'size': ['small', false, 'large', 'huge'] }],
[{ 'color': [] }, { 'background': [] }],
[{ 'font': [] }],
[{ 'align': [] }],
[{ 'indent': '-1' }, { 'indent': '+1' }],
[{ 'list': 'ordered' }, { 'list': 'bullet' }, { 'list': 'check' }],
[{ 'script': 'sub' }, { 'script': 'super' }],
[{ 'header': 1 }, { 'header': 2 }],
['clean']
];
const quotedText =
'Lorem ipsum dolor sit amet consectetur adipiscing elit.\n' +
'Amet consectetur adipiscing elit quisque faucibus ex sapien.\n' +
'Quisque faucibus ex sapien vitae pellentesque sem placerat.\n' +
'Vitae pellentesque sem placerat in id cursus mi.';
const someText =
'Red is greener than purple, for sure.\n' +
'He is good at eating pickles and telling women about his emotional problems.\n' +
'She borrowed the book from him many years ago.';
window.addEventListener("load", () => {
const quill = new Quill('#editor', {
modules: {
toolbar: toolbarOptions
},
theme: 'snow'
});
var content = [];
content.push({ insert: 'Someone says:\n', attributes: { 'bold': 'true', 'size': 'large' } });
quotedText.split('\n').forEach((line) => {
content.push({ insert: `${line}\n`, attributes: { 'code-block': 'plain' } });
});
content.push({ insert: '\n\nIn response to:\n', attributes: { 'bold': 'true', 'size': 'large' } });
someText.split('\n').forEach((line) => {
content.push({ insert: `${line}\n`, attributes: { 'blockquote': 'true', 'color': '#008080' } });
});
quill.setContents(content);
});
</script>
</head>
<body>
<div id="editor">
</div>
</body>
</html>
اگه دقت کنین ادیتور کاملا خالی هست و با کد initialize میشه،
خروجی این کد همین تصویر پست شماره 9 هست.