Editor.js

Editor.js 是一个在线富文本编辑器 官网链接:https://editorjs.io/

Editor.js 快速入门

  1. 导入编辑器库 Install Editor.js
  2. 编辑器初始化 Configure and initialise the Editor
  3. 安装工具 Install and Tools
  4. 配置工具 connect tools

引入

安装分为三种,Node, CDN(链接 https://www.jsdelivr.com/package/npm/@editorjs/editorjs),本地文件安装。这里只介绍 node 环境。

npm i @editorjs/editorjs --save-dev
import EditorJS from '@editorjs/editorjs';

初始化配置

初始化时,可以不用包含任何参数

import EditorJS from '@editorjs/editorjs';
const editor = new EditorJS();

下面是增加配置的代码-IE浏览器需要兼容

import EditorJS from '@editorjs/editorjs';
const editor = new EditorJs('codex-editor');
import EditorJS from '@editorjs/editorjs';
const editor = new EditorJs({   holderId: 'codex-editor'
});

详细的配置文件在后文介绍。

安装工具

每一个块级节点是一个插件。初始化时我们仅提供段落块级节点。你可以在这里使用其他的块级节点。点击不同的块级节点可以获取具体的安装指导。

  1. Header
  2. Link embeds
  3. Raw HTML blocks
  4. Simple Image (without backend requirement)
  5. Image
  6. Checklist
  7. List
  8. Embeds
  9. Quote

And some others.

安装工具后,你需要通过配置对象,将编辑器和块级节点连接。

配置工具

先看一下开始的最简单的配置

import EditorJs from '@editorjs/editorjs';
const editor = new EditorJs({    holderId: 'codex-editor',
})

然后,增加一些工具配置。可以添加 tools对象。

import EditorJs from '@editorjs/editorjs';
import Header from '@editorjs/header';
import List from '@editorjs/list';
const editor = new EditorJs({    /**     * Id of Element that should contain the Editor     */    holderId: 'codex-editor',
/**     * Available Tools list.     * Pass Tool's class or Settings object for each Tool you want to use     */tools: {header: Header,list: List},
});

上面的例子中,我们使用了没有选项的工具(只有工具名称,header list)。

当然,这些工具可以增加选项。我们可以给这些工具增加特定的选项(下面的class inlineToolbar,设定了行内是否显示工具栏,显示哪些工具栏,工具的类名等)。

import EditorJs from '@editorjs/editorjs';
import Header from '@editorjs/header';
import List from '@editorjs/list';
const editor = new EditorJs({    /**     * Id of Element that should contain the Editor     */    holderId: 'codex-editor',     /**     * Available Tools list.     * Pass Tool's class or Settings object for each Tool you want to use     */    tools: {      header: {       class: Header,        inlineToolbar: ['link']      },      list: {        class: List,        inlineToolbar: true      }    },
})

那么,基本的 Editor 就搭建好了。

注意事项

Editor.js 是原生 JS, 和 React 框架并不通用。

Editor.js 使用相关推荐

  1. the next generation block styled editor -- eidtor.js

    what's editor? Next generation block styled editor. Free. Use for pleasure. Editor.js is a block-sty ...

  2. 防止js全局变量污染方法总结-待续

    javaScript 可以随意定义保存所有应用资源的全局变量.但全局变量可以削弱程序灵活性,增大了模块之间的耦合性.在多人协作时,如果定义过多的全局变量 有可能造成全局变量冲突,也就是全局变量污染问题 ...

  3. 动态加载的js文件在Chrome进行调试时找不到

    有时候由于各种原因需要动态加载js文件,如: $('body').append("<script type='text/javascript' src='./editor.js'> ...

  4. SPAW Editor .NET Edition v.2乱用:使用代码调整编辑器高度

    SPAW Editor .NET Edition v.2乱用中介绍了一个HTML Editor,在使用这个Editor进行页面布局的时候可能希望使用代码控制编辑器的大小,例如在用户调整浏览器大小的时候 ...

  5. vue 引入qunee_Vue页面中js引入的问题

    在项目中,我们需要引入qunee的编辑器graph.editor-master,在其中发现了一些引入js时需要注意的问题,在此书写,用来翻阅. 下载graph.editor的官方Demogit:htt ...

  6. html ace编辑器,Springboot 集成 Ace editor前端编辑器

    一.引入Ace editor 本质上Ace editor只是一个js而已.而该js引用了其他js(如扩展.主题等js),因此将ace editor.js引入项目时最好复制整个文件夹,不能只复制一个ac ...

  7. 小程序开发笔记(二):微信小程序富文本编辑器editor的使用

      小程序在去年5月的 v2.7.0 版本新增了组件editor富文本编辑器,但对于像我这种开发新手,要熟练使用还是有一定难度.所以记录一下我的学习过程,希望对大家有帮助.   小程序有详细的微信开发 ...

  8. js html 编辑器添加图片不显示,彻底解决ewebeditor网站后台不能上传图片的方法

    经我们技术员检查,结果原来是eWebEditor文本编辑器对IE8浏览器的兼容性导致的脚本错误,并不是什么"网站空间.服务器中毒.出问题了"呢! 现就将解决方法公布给大家,方便大家 ...

  9. 使用微信小程序editor富文本编辑器(爬坑要点)

    编辑器wxml <view class="container" style="height:{{editorHeight}}px;"><edi ...

最新文章

  1. 数字签名、私钥、公钥
  2. html css js书写规范
  3. 将动画装入MicroPython I2C OLED
  4. Ubuntu中的默认shell
  5. problem-solving-with-algorithms-and-data-structure-usingpython(使用python解决算法和数据结构) -- 基本数据结构(一)...
  6. Raising Modulo Numbers
  7. boost::fusion::unfused_typed用法的测试程序
  8. 【城市沙龙】LiveVideoStack Meet | 长沙:多媒体与广电
  9. 【渝粤题库】陕西师范大学292241金融市场学Ⅰ 作业(高起专)
  10. 机器学习 缺陷检测_球检测-体育中的机器学习。
  11. sql注入基于错误-单引号-字符型
  12. android的读取xml配置文件,android中XMl文件的读取
  13. matlab字符和字符串,MATLAB字符和字符串
  14. Python 金融数据可视化(两列数据的提取//分别画//双坐标轴//双图//两种不同的图)...
  15. 《android基于andFix的热修复方案》思路篇
  16. 红黑树的红黑有什么意义_红枸杞和黑枸杞有什么不同?黑枸杞真的比红枸杞要好吗?...
  17. Mozilla Firefox 66 将使用更少的内存,提高扩展性能
  18. [Android实例教程] 教你如何拍照+相册选择图片+剪裁图片完整实现
  19. LVS 三种工作模式
  20. php 后台数据 u,Yunucms代码审计:后台XSS和数据库信息泄露

热门文章

  1. 新出免费字体——阿里巴巴普惠字体(附安装使用教程)
  2. unity shader 边缘光,内发光,外发光,轮廓边缘光,轮廓内边缘光,轮廓外边缘光
  3. 读书笔记---《如何高效学习》
  4. css 优惠券样式大全
  5. CSO关注:企业安全遭受攻击的15个迹象
  6. 评委打分表模板_系高中英语作文模板——邀请信
  7. 外卖商家入驻选择类目(JS数组)
  8. 读书笔记:SQL 查询中的SQL*Plus 替换变量(DEFINE变量)和参数
  9. onPullDownRefresh和uni.startPullDownRefresh(OBJECT)、uni.stopPullDownRefresh()的关系
  10. bios怎么设置USB启动