- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我开始将 WYSIWYG 集成到博客项目中,为此我使用 Quill(我之前没有使用它的经验)。我能够按照需要的方式自定义我的编辑器,我不明白的是如何处理文本格式和嵌入视频。我的帖子表单中有两个字段,“预览”和“内容”(两个羽毛笔编辑器),同时介绍我可以为其指定格式的文本(标题、斜体、下划线等),当单击嵌入视频选项时编辑器允许我在那一刻添加链接并可视化嵌入视频。当我按下保存按钮时,它会将帖子存储在我的数据库中,但在我的单个帖子页面中,我可以看到所有没有格式的字段(标题、斜体、下划线...等),也没有嵌入视频。我怎样才能给出格式并显示视频?任何帮助将不胜感激。
我阅读了 Quill 文档并试图了解如何使用增量处理此问题,但我不知道如何进行。
我正在使用 Meteor + React,这是我的代码(我将只显示相关代码):
这是我的库,quill.jsx
import React, { Component } from 'react';
import QuillLib from './vendor/quill.js';
import { ud } from '/helpers/lib/main.jsx';
class Quill extends Component {
constructor(props) {
super(props);
this.id = ud.shortUID();
}
componentDidMount() {
const that = this;
const toolbarOptions = [
[{ font: [] }],
[{ header: 1 }, { header: 2 }],
[{ header: [1, 2, 3, 4, 5, 6, false] }],
[{ align: [] }],
['bold', 'italic', 'underline', 'strike'],
['blockquote', 'code-block'],
[{ script: 'sub' }, { script: 'super' }],
[{ indent: '-1' }, { indent: '+1' }],
[{ color: [] }, { background: [] }],
['video'],
['image'],
];
const quill = new QuillLib(`#quill-editor-container-${this.id}`, {
modules: {
toolbar: toolbarOptions,
},
theme: 'snow',
});
const content = this.props.content;
quill.setContents(content);
quill.on('text-change', (delta) => {
if (that.props.onChange) {
that.props.onChange(quill);
}
});
}
render() {
return (
<div className="wysiwyg-wrapper">
<div id={`quill-editor-container-${this.id}`}></div>
</div>
);
}
}
export default Quill;
这是我的输入表单组件,list.jxs
import { Meteor } from 'meteor/meteor';
import { PostSchema } from '/modules/blog/lib/collections.jsx';
import Quill from '/modules/quill/client/main.jsx';
export class BlogCategory extends Component {
constructor(props) {
super(props);
this.state = {
post: {
content: '',
preview: '',
},
};
this.onPreviewChange = this.onPreviewChange.bind(this);
this.onContentChange = this.onContentChange.bind(this);
}
onPreviewChange(content) {
this.state.post.preview = content.getText();
this.setState(this.state);
}
onContentChange(content) {
this.state.post.content = content.getText();
this.setState(this.state);
}
save() {
const content = this.state.post.content;
const preview = this.state.post.preview;
const post = new PostSchema();
post.set({
content,
preview,
});
if (post.validate(false)) {
const id = post.save();
}
console.log(post.getValidationErrors(false));
}
renderCreatePostForm() {
let content;
if (this.state.showForm) {
content = (
<form action="">
<Quill
content={this.state.post.preview}
onChange={this.onPreviewChange}
/>
<Quill
content={this.state.post.content}
onChange={this.onContentChange}
/>
</form>
);
}
return content;
}
render() {
let content = (
<div className="col-xs-12">
{this.renderActions()}
</div>
);
if (!this.props.ready) {
content = <p>LOADING...</p>;
}
return content;
}
}
export default createContainer(() => {
const handleValidPost = Meteor.subscribe('posts');
return {
ready: handleValidPost.ready(),
posts: PostSchema.find({}).fetch(),
};
}, BlogCategory);
最后是我的 collections.jsx
import { Mongo } from 'meteor/mongo';
export const PostCollection = new Mongo.Collection('Posts');
export const PostSchema = Astro.Class({
name: 'PostSchema',
collection: PostCollection,
fields: {
content: {
validator : Validators.and([
Validators.required(),
Validators.string(),
Validators.minLength(3)
])
},
preview: {
validator : Validators.and([
Validators.required(),
Validators.string(),
Validators.minLength(3)
])
},
}
});
最佳答案
在通过getText
获取Quill
内容时,您丢失了文本格式和视频信息。使用 getText
,将忽略所有非字符串数据。 Quill
数据定义为 Delta (这是一个 JSON 对象)。
您可以通过更新 onPreviewChange
和 onContentChange
以使用 getContents
而不是 getText
来解决此问题。将这些 Delta
保存到 DB 并再次加载。
onPreviewChange(content) {
this.state.post.preview = content.getContents();
this.setState(this.state);
}
onContentChange(content) {
this.state.post.content = content.getContents();
this.setState(this.state);
}
关于javascript - 如何使用 Quill 格式化文本和嵌入视频?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39080207/
假设我想要一个 AtomicText类似于默认 Link 的印迹印迹但不可变,只能作为一个整体删除。进一步来说: 光标可以在AtomicText的字符之间. 可以选择 AtomicText 的部分内容
我正在使用 Quill 编辑器。到目前为止还不错。我的问题是有什么方法可以通过工具栏中的按钮使 Quill Editor 全屏显示(一种无干扰模式)? 如果不是,我该如何继续自己实现? 最佳答案 要全
我知道在 Quill 编辑器的实例化中,有一个占位符选项。有没有办法在编辑器实例化后动态更改这个占位符? 最佳答案 占位符使用 CSS 规则实现: .ql-editor::before { co
我有一个显示富文本数据的模板。当用户单击编辑时,我将模板转换为可编辑的 Quill 编辑器,如下所示: 'click #editNote': (e, t) -> note = t.find
刚开始使用 Quill 并发现它非常有用。我的项目需要纯文本编辑。具体来说,我使用 quill 作为输入 YAML 代码的表单。破折号“-”是 YAML 中的关键项。问题是 Quill 自动将行格式化
我正在尝试在 quill 编辑器的特定位置插入 anchor 文本。 var fullEditor = new Quill('#m_wiki_textarea', { m
我正在尝试向 Quill 编辑器工具栏添加对齐按钮。 工具栏documentation不是很详细。它展示了如何选择对齐选项,但我想要一组并排的切换按钮。这可能吗? 最佳答案 您可以执行 align:
我正在尝试自定义 Quill editor满足我的需要。我设法实现并插入自定义印迹,如 https://quilljs.com/guides/cloning-medium-with-parchment
我有一个将 Quill 编辑器的内容发布到 PHP 脚本的表单。然后 PHP 脚本将文本保存到数据库中。以后可以将相同的文本加载到 Quill 编辑器中。这一切工作正常并按预期显示。 仅供引用,我使用
是否可以使用 Quill (link) 打印文档或导出为 pdf。如果是这样,怎么办? 最佳答案 不属于 Quill core . 您必须编写一个自定义模块来将 Quill 的 Delta 或原始 H
我必须创建在线文字编辑器,其中包括基本格式、内联注释。为此,我使用 quill.js 编辑器,但无法在 quill.js 编辑器中添加注释。 最佳答案 就我而言,我为此创建了一个自定义解决方案。下面是
我们如何在 Quill.js 中创建新主题?我们是否必须扩展现有的? 我只想更新外观,而不是功能,所以理论上我可以为默认的 Snow 主题添加一堆覆盖,但这并不理想。 那么 - 我们如何以及在哪里创建
我想防止 Quill 编辑器中的工具栏按钮具有 tabindex。我怎样才能做到这一点? 最佳答案 Quill 提供了两种获取 toolbar 的方法位于定制范围的两端。一种是您传入一组您想要的格式,
我正在使用最新版本的 quill.js,并且想知道是否有一种方法可以覆盖 Quill 在生成编辑器工具栏时使用的 svg 图标(对于气泡主题,如果这很重要。) 我试过四处寻找,看看在源代码中定义图标的
我已经成功地在 angular 7 中设置了 ngx-quill,我需要创建一个自定义文本印迹,它看起来如下(简化): ... /*** Custom blot: [its editable text
更新:当我意识到 PrimeNg 有一个 quill 实现并且我已经在使用 PrimeNg 时,我放弃了。起初没有工作,但升级到 angular 7 和 ngrx 7 beta 修复了问题。 http
我正在使用 angular 4 和 quill 编辑器。但我收到了 quill Invalid Quill container 的错误消息.我更改了容器的名称,但它仍然返回错误并且无法识别容器 ID。
如何将 Delta 转换为纯 HTML?我使用 Quill 作为富文本编辑器,但我不确定如何在 HTML 上下文中显示现有的 Delta。创建多个 Quill 实例是不合理的,但我想不出更好的方法。
标题可能会产生误导,但我不知道如何更好地命名它。我想要实现的是像 twitter-widget 一样嵌入我的自定义印迹。为此,我创建了示例“渲染器”类: class TestRenderer {
我创建了一种将 Quill 文本保存到数据库的方法。每次用户单击已保存的文档时,它都会从数据库中提取已保存的 Quill 文本,并将文本显示在 Quill 文本编辑器中。此时,如果我触发撤消功能,它将
我是一名优秀的程序员,十分优秀!