[英]Formatted text inside Quill editor on page load
I have what I think should be a very simple question. 我认为应该是一个非常简单的问题。 How do you put formatted multi-line strings into the quill editor on page load?
在页面加载时,如何将格式化的多行字符串放入笔管编辑器中?
I want to use a quill editor to let the user enter json in, but I want to have certain json in the quill field when the user first visits the page. 我想使用一个羽毛笔编辑器让用户输入json,但是当用户第一次访问该页面时,我想在羽毛笔字段中使用某些json。 However, I can't seem to have the json formatted in any specific way.
但是,我似乎无法以任何特定方式格式化json。 Pasting the json into the HTML div itself obviously eats all the white space, and I've been unsuccessful in using any kind of multi-line string in javascript.
将json粘贴到HTML div本身中显然会吃掉所有空白,并且在javascript中使用任何种类的多行字符串都没有成功。
It's gotta be something quill can do, as almost all of the quill fields in their documentation use multi-line formatted strings. 这是必须执行的操作,因为文档中几乎所有的操作字段都使用多行格式的字符串。 How do they do it?
他们是如何做到的呢?
PS I know asking the user to enter JSON sounds strange, trust me, for this project, it's a requirement. PS,我知道要求用户输入JSON听起来很奇怪,请相信我,对于此项目,这是一项要求。 This is not for a public site.
这不适用于公共站点。
You can try pasting the json inside <pre>
tags into the HTML div itself: 您可以尝试将
<pre>
标记内的json粘贴到HTML div本身中:
<div id="editor-container">
<pre>{
"firstName": "John",
"lastName": "Smith",
"isAlive": true
}
</pre>
</div>
That way whitespace keeps preserved. 这样就保留了空白。
That said, quill is a rich text editor and all of this functionality is superfluous if you are using it to enter json. 就是说,羽毛笔是富文本编辑器,如果您使用它输入json,那么所有这些功能都是多余的。 You might be better of using an online code editor like codemirror to have your users enter json.
使用像codemirror这样的在线代码编辑器让用户输入json可能会更好。 These online code editors offer syntax highlighting that makes editing code (after all json is code) much more comfortable.
这些在线代码编辑器提供语法突出显示功能,使代码编辑(毕竟json是代码)更加舒适。 It will show if a line is missing a bracket or a colon or a comma and that will make it easier for your users to enter json constructs.
它将显示一行是否缺少括号,冒号或逗号,这将使您的用户更容易输入json构造。
Please also look at YAML which in my experience is more human readable than json and offers the same functionality and is widely supported in most computing languages. 还请查看YAML ,根据我的经验, YAML比json更具可读性,并且提供相同的功能,并且在大多数计算语言中均得到广泛支持。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.