刚开始使用 Quill 并发现它非常有用。我的项目需要纯文本编辑。具体来说,我使用 quill 作为输入 YAML 代码的表单。破折号“-”是 YAML 中的关键项。问题是 Quill 自动将行格式化为项目符号。
有没有办法禁用自动子弹?
凯文
如评论中所述,将您在“格式”选项(而不是工具栏区域)中允许的内容列入白名单
var editor = new quill("#someElemId", {
modules: {
toolbar: [
'bold',
//{ 'list': 'bullet' },
{ 'indent': '-1'},
{ 'indent': '+1' },
{ 'color': ['black', 'red', 'blue', 'green'] },
'link',
'clean'
]
},
formats : [
"background",
"bold",
"color",
"font",
"code",
"italic",
"link",
"size",
"strike",
"script",
"underline",
"blockquote",
// "header",
"indent",
// "list", <-- commented-out to suppress auto bullets
"align",
"direction",
"code-block",
"formula",
"image",
"video"
],
theme: 'snow', // snow bubble
});
Run Code Online (Sandbox Code Playgroud)
小智 5
Quill 的内置键盘模块负责自动格式化列表。您可以通过像这样导入和扩展键盘模块来覆盖或禁用此行为。
var Keyboard = Quill.import('modules/keyboard');
class CustomKeyboard extends Keyboard {
static DEFAULTS = {
...Keyboard.DEFAULTS,
bindings: {
...Keyboard.DEFAULTS.bindings,
['list autofill']: undefined,
}
}
}
Quill.register('modules/keyboard', CustomKeyboard);
Run Code Online (Sandbox Code Playgroud)
如果您仍然列出其他输入的检测(例如“*”),您可以更改“列表自动填充”绑定匹配的正则表达式,如下所示
var Keyboard = Quill.import('modules/keyboard');
class CustomKeyboard extends Keyboard {
static DEFAULTS = {
...Keyboard.DEFAULTS,
bindings: {
...Keyboard.DEFAULTS.bindings,
['list autofill']: {
...Keyboard.DEFAULTS.bindings['list autofill'],
prefix: /^\s*?(\d+\.|\*|\[ ?\]|\[x\])$/
},
}
}
}
Quill.register('modules/keyboard', CustomKeyboard);
Run Code Online (Sandbox Code Playgroud)
这是一个工作示例:https ://codepen.io/josephdangerstewart/pen/dyNEGoj
有关模块的更多文档可以在 Quill 网站上找到:https ://quilljs.com/docs/modules/#extending
| 归档时间: |
|
| 查看次数: |
3016 次 |
| 最近记录: |