pell README

The project's README from github.com/jaredreich/pell. As one markdown file: README.md.

v2 working branch and v2 project board


Logo

npm cdnjs

pell is the simplest and smallest WYSIWYG text editor for web, with no dependencies

Demo

Comparisons

library size (min+gzip) size (min) jquery bootstrap react link
pell 1.38kB 3.54kB https://github.com/jaredreich/pell
squire 16kB 49kB https://github.com/neilj/Squire
medium-editor 27kB 105kB https://github.com/yabwe/medium-editor
quill 43kB 205kB https://github.com/quilljs/quill
trix 47kB 204kB https://github.com/basecamp/trix
ckeditor 163kB 551kB https://ckeditor.com
trumbowyg 8kB 23kB x https://github.com/Alex-D/Trumbowyg
summernote 26kB 93kB x x https://github.com/summernote/summernote
draft 46kB 147kB x https://github.com/facebook/draft-js
froala 52kB 186kB x https://github.com/froala/wysiwyg-editor
tinymce 157kB 491kB x https://github.com/tinymce/tinymce

Features

Included actions:

Other available actions (listed at https://developer.mozilla.org/en-US/docs/Web/API/Document/execCommand):

Or create any custom action!

Browser Support

Installation

npm:

npm install --save pell

HTML:

<head>
  ...
  <link rel="stylesheet" type="text/css" href="https://unpkg.com/pell/dist/pell.min.css">
  <style>
    /* override styles here */
    .pell-content {
      background-color: pink;
    }
  </style>
</head>
<body>
  ...
  <!-- Bottom of body -->
  <script src="https://unpkg.com/pell"></script>
</body>

Usage

API

// ES6
import pell from 'pell'
// or
import { exec, init } from 'pell'
// Browser
pell
// or
window.pell
// Initialize pell on an HTMLElement
pell.init({
  // <HTMLElement>, required
  element: document.getElementById('some-id'),

  // <Function>, required
  // Use the output html, triggered by element's `oninput` event
  onChange: html => console.log(html),

  // <string>, optional, default = 'div'
  // Instructs the editor which element to inject via the return key
  defaultParagraphSeparator: 'div',

  // <boolean>, optional, default = false
  // Outputs <span style="font-weight: bold;"></span> instead of <b></b>
  styleWithCSS: false,

  // <Array[string | Object]>, string if overwriting, object if customizing/creating
  // action.name<string> (only required if overwriting)
  // action.icon<string> (optional if overwriting, required if custom action)
  // action.title<string> (optional)
  // action.result<Function> (required)
  // Specify the actions you specifically want (in order)
  actions: [
    'bold',
    {
      name: 'custom',
      icon: 'C',
      title: 'Custom Action',
      result: () => console.log('Do something!')
    },
    'underline'
  ],

  // classes<Array[string]> (optional)
  // Choose your custom class names
  classes: {
    actionbar: 'pell-actionbar',
    button: 'pell-button',
    content: 'pell-content',
    selected: 'pell-button-selected'
  }
})

// Execute a document command, see reference:
// https://developer.mozilla.org/en/docs/Web/API/Document/execCommand
// this is just `document.execCommand(command, false, value)`
pell.exec(command<string>, value<string>)

List of overwriteable action names

Examples

General

<div id="editor" class="pell"></div>
<div>
  HTML output:
  <div id="html-output" style="white-space:pre-wrap;"></div>
</div>
import { exec, init } from 'pell'

const editor = init({
  element: document.getElementById('editor'),
  onChange: html => {
    document.getElementById('html-output').textContent = html
  },
  defaultParagraphSeparator: 'p',
  styleWithCSS: true,
  actions: [
    'bold',
    'underline',
    {
      name: 'italic',
      result: () => exec('italic')
    },
    {
      name: 'backColor',
      icon: '<div style="background-color:pink;">A</div>',
      title: 'Highlight Color',
      result: () => exec('backColor', 'pink')
    },
    {
      name: 'image',
      result: () => {
        const url = window.prompt('Enter the image URL')
        if (url) exec('insertImage', url)
      }
    },
    {
      name: 'link',
      result: () => {
        const url = window.prompt('Enter the link URL')
        if (url) exec('createLink', url)
      }
    }
  ],
  classes: {
    actionbar: 'pell-actionbar-custom-name',
    button: 'pell-button-custom-name',
    content: 'pell-content-custom-name',
    selected: 'pell-button-selected-custom-name'
  }
})

// editor.content<HTMLElement>
// To change the editor's content:
editor.content.innerHTML = '<b><u><i>Initial content!</i></u></b>'

Example (Markdown)

<div id="editor" class="pell"></div>
<div>
  Markdown output:
  <div id="markdown-output" style="white-space:pre-wrap;"></div>
</div>
import { init } from 'pell'
import Turndown from 'turndown'

const { turndown } = new Turndown({ headingStyle: 'atx' })

init({
  element: document.getElementById('editor'),
  actions: ['bold', 'italic', 'heading1', 'heading2', 'olist', 'ulist'],
  onChange: html => {
    document.getElementById('markdown-output').innerHTML = turndown(html)
  }
})

Frameworks

Custom Styles

SCSS

$pell-content-height: 400px;
// See all overwriteable variables in src/pell.scss

// Then import pell.scss into styles:
@import '../../node_modules/pell/src/pell';

CSS

/* After pell styles are applied to DOM: */
.pell-content {
  height: 400px;
}

License

MIT

Credits

BrowserStack for cross browser testing:

BrowserStack logo

pell (jaredreich/pell)

Searching Database…

12K ·GitHub
这是什么?pell 是一个网页版的所见即所得富文本编辑器 — 目前最简单、最小的同类编辑器,零依赖。把它嵌入页面后,用户就能用一个工具栏来排版文字。
它是一个现成的应用,还是一个能集成到我自己网站里的库?是一个库:通过 npm 或 script 标签引入,绑定到页面上的某个元素,然后通过它的 API 来调用。它完全在浏览器里运行。
怎么把它加进项目里?两种方式:安装 npm 包,或者用普通的 HTML script 标签引入 — 然后用几行 JavaScript 在某个元素上初始化编辑器。
需要 jQuery、Bootstrap 或 React 才能用吗?不需要 — 它是用 ES6 写的纯 JavaScript,完全没有依赖。对比表格显示,和大多数同类编辑器不同,它不要求 jQuery、Bootstrap 或 React。
它这么小,工具栏到底支持多少格式功能?设计上就是走精简路线:内置 14 个操作 — 加粗、斜体、下划线、删除线、一级和二级标题、段落、引用、有序和无序列表、代码、水平分割线、链接和图片。对齐、字号、撤销/重做等更多功能也可以开启,还能添加任意自定义操作。
它能在哪些浏览器里运行?非常老的浏览器都行:Chrome 5+、Firefox 4+、Safari 5+、Opera 11.6+ 和 IE 9+ — 不过 README 自己也承认对 IE 的支持只是理论上的('good luck')。
和 Quill、TinyMCE 这类编辑器相比,为什么选 pell?因为体积:pell 压缩加 gzip 后只有 1.38kB,而 Quill 是 43kB、Trix 是 47kB、TinyMCE 是 157kB — 而且和好几个竞品不同,它不要求 jQuery、Bootstrap 或 React。
怎么让它符合我网站的设计风格?样式可以随意改:直接覆盖 CSS,或者自定义自带的 sass 文件 pell.scss。
我能在工具栏上添加自己的按钮吗?可以 — 你可以创建任意自定义操作,连默认的操作名称(加粗、链接、图片等)都能通过 API 覆盖。
它和 React 或 Vue 一起用方便吗?仓库里附带了这两个框架的现成示例,另外还有一个通用演示和一个 Markdown 示例。
Creator
jaredreich
Size
1.2 MB
Stars
12K
Age
9y
Commits · 90 Days