我正在开发一个使用Google Drive Realtime API的网络应用程序.API用于存储文档的数据并同步活动协作者之间的所有修改.
现在,我想为这个应用程序添加对富文本(只有粗体,下划线和链接等基础知识)的文本框的支持.文本框应启用类似于Google文档的协作文本编辑.我现在搜索和试验了几天,但是我找不到如何交换数据或如何构建适用于Drive Realtime API的合适数据模型的正确解决方案.
有一种方法可以让人联想到在CollaborativeSting中交换HTML(或类似的标记).但那不会起作用,因为它可能迟早会破坏标记.
另一个(可能更好)的出发点是使用更抽象的数据模型为奎尔编辑器做.(如果可能的话,我想稍后使用这个编辑器,但这不是必须的.)
" Hello! Here is a link. " 的富文本模型如下所示:
var doc = [
{ insert: "Hello!", attributes: { bold: true } },
{ insert: " Here is a " },
{ insert: "link.", attributes: { href: 'http://example.org' } }
];
Run Code Online (Sandbox Code Playgroud)
我可以将上面的文档示例转换为" Hello! 这是一个链接. "这些说明:
var operation = [
{ retain: 7 },
{ insert: "That's", attributes: { italic: true } …Run Code Online (Sandbox Code Playgroud) javascript data-modeling rich-text-editor google-drive-api google-drive-realtime-api
javascript ×1