简体   繁体   English

页面加载时,Quill编辑器中的格式化文本

[英]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更具可读性,并且提供相同的功能,并且在大多数计算语言中均得到广泛支持。

如何调整羽毛笔编辑器的大小以适应<div> ?</div><div id="text_translate"><p> 我希望羽毛笔编辑器自动适应父&lt;div&gt;元素。</p><p> 我创建了&lt;div&gt;元素,并在其中再次创建了一个&lt;div&gt;元素,该元素将成为 quill 编辑器的容器。 工具栏是自动创建的。 我使用 css 将父&lt;div&gt;元素的大小调整为width:50%和height:50% ,我希望其中的所有内容(羽毛笔编辑器和工具栏)都适合其中,但是羽毛笔编辑器的某些部分会出现父&lt;div&gt;元素的。</p><p> <strong>HTML:</strong></p><pre class="lang-html prettyprint-override"> &lt;,-- parent div element: in which quill editor should fit --&gt; &lt;div id="parent" style="width;50%:height;70%:border:2px solid green"&gt; &lt;!-- Quill editor div --&gt; &lt;div id="editor"&gt; &lt;/div&gt; &lt;/div&gt;</pre><p> <strong>Javascript:</strong></p><pre> var tool = [[{ 'header': '1' }, { 'header': '2' }], [{ size: ['small', false, 'large', 'huge'] }], ['bold', 'italic', 'underline', 'strike'], [{ 'color': [] }, { 'background': [] }, { 'font': [] }, { 'align': [] }], ['image',]]; var option = { placeholder: 'Compose an epic...', theme: 'snow', modules: { toolbar: tool }, bounds:'#parent' }; var quill = new Quill('#editor', option);</pre><p> 我在父 div 周围放了一个绿色边框,我发现编辑器从边框出来了。 请看截图:</p><p> <a href="https://i.stack.imgur.com/RlASQ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/RlASQ.png" alt="截屏"></a></p><p> 注意:我只想保持父 div 的大小固定。 所以,请告诉我该怎么办?</p><p> 编辑:我将整个代码(html 文件)上传到我的服务器(<a href="http://tu.unaux.com/game.html" rel="nofollow noreferrer">这里</a>)。 问题仍然存在。 请检查一下,您可以使用“检查元素”查看整个代码。</p></div> - How to resize quill editor to fit inside a <div>?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 加载时在 Quill 编辑器中插入来自 HTML 的格式化内容 - Insert formatted content from HTML in Quill editor on load 在笔管编辑器中显示文字 - Display text in Quill editor Quill 文本编辑器不工作 - Quill text editor is not working Shadow DOM 中的 Quill 编辑器 - Quill editor inside Shadow DOM 散焦鹅毛笔的文本编辑器 - Unfocus quill's text editor 如何调整羽毛笔编辑器的大小以适应<div> ?</div><div id="text_translate"><p> 我希望羽毛笔编辑器自动适应父&lt;div&gt;元素。</p><p> 我创建了&lt;div&gt;元素,并在其中再次创建了一个&lt;div&gt;元素,该元素将成为 quill 编辑器的容器。 工具栏是自动创建的。 我使用 css 将父&lt;div&gt;元素的大小调整为width:50%和height:50% ,我希望其中的所有内容(羽毛笔编辑器和工具栏)都适合其中,但是羽毛笔编辑器的某些部分会出现父&lt;div&gt;元素的。</p><p> <strong>HTML:</strong></p><pre class="lang-html prettyprint-override"> &lt;,-- parent div element: in which quill editor should fit --&gt; &lt;div id="parent" style="width;50%:height;70%:border:2px solid green"&gt; &lt;!-- Quill editor div --&gt; &lt;div id="editor"&gt; &lt;/div&gt; &lt;/div&gt;</pre><p> <strong>Javascript:</strong></p><pre> var tool = [[{ 'header': '1' }, { 'header': '2' }], [{ size: ['small', false, 'large', 'huge'] }], ['bold', 'italic', 'underline', 'strike'], [{ 'color': [] }, { 'background': [] }, { 'font': [] }, { 'align': [] }], ['image',]]; var option = { placeholder: 'Compose an epic...', theme: 'snow', modules: { toolbar: tool }, bounds:'#parent' }; var quill = new Quill('#editor', option);</pre><p> 我在父 div 周围放了一个绿色边框,我发现编辑器从边框出来了。 请看截图:</p><p> <a href="https://i.stack.imgur.com/RlASQ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/RlASQ.png" alt="截屏"></a></p><p> 注意:我只想保持父 div 的大小固定。 所以,请告诉我该怎么办?</p><p> 编辑:我将整个代码(html 文件)上传到我的服务器(<a href="http://tu.unaux.com/game.html" rel="nofollow noreferrer">这里</a>)。 问题仍然存在。 请检查一下,您可以使用“检查元素”查看整个代码。</p></div> - How to resize quill editor to fit inside a <div>? React Quill Editor - 丢失文本格式 - React Quill Editor - Losing Text Formatting 需要在表单中添加 Quill 富文本编辑器 - need to add Quill Rich Text Editor into form Quill JavaScript Rich Text Editor 限制标签 - Quill JavaScript Rich Text Editor restrict tags 如何使用 Delta 检索 Quill 文本编辑器文本 - How do I retrive Quill text editor text using Delta
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM