Pell

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

README



Logo
npm cdnjs

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


Live demo

Comparisons


librarysizesizejquerybootstrapreactlink
|---------------|-----------------|------------|--------|-----------|-------|------|
pell1.38kB3.54kB||
squire16kB49kB||
medium-editor27kB105kB||
quill43kB205kB||
trix47kB204kB||
ckeditor163kB551kB||
trumbowyg8kB23kBx|https://github.com/Alex-D/Trumbowyg
summernote26kB93kBxx|
draft46kB147kB|xhttps://github.com/facebook/draft-js
froala52kB186kBx|https://github.com/froala/wysiwyg-editor
tinymce157kB491kBx|https://github.com/tinymce/tinymce

Features


Pure JavaScript, no dependencies, written in ES6
Easily customizable with the sass file (pell.scss) or overwrite the CSS

Included actions:
- Bold
- Italic
- Underline
- Strike-through
- Heading 1
- Heading 2
- Paragraph
- Quote
- Ordered List
- Unordered List
- Code
- Horizontal Rule
- Link
- Image

Other available actions (listed at https://developer.mozilla.org/en-US/docs/Web/API/Document/execCommand):
- Justify Center
- Justify Full
- Justify Left
- Justify Right
- Subscript
- Superscript
- Font Name
- Font Size
- Indent
- Outdent
- Clear Formatting
- Undo
- Redo

Or create any custom action!

Browser Support


IE 9+ (theoretically, but good luck)
Chrome 5+
Firefox 4+
Safari 5+
Opera 11.6+

Installation


npm:


  1. ``` sh
  2. npm install --save pell
  3. ```

HTML:


  1. ``` html
  2. <head>
  3.   ...
  4.   <link rel="stylesheet" type="text/css" href="https://unpkg.com/pell/dist/pell.min.css">
  5.   <style>
  6.     /* override styles here */
  7.     .pell-content {
  8.       background-color: pink;
  9.     }
  10.   </style>
  11. </head>
  12. <body>
  13.   ...
  14.   
  15.   <script src="https://unpkg.com/pell"></script>
  16. </body>
  17. ```

Usage


API


  1. ``` js
  2. // ES6
  3. import pell from 'pell'
  4. // or
  5. import { exec, init } from 'pell'
  6. ```

  1. ``` js
  2. // Browser
  3. pell
  4. // or
  5. window.pell
  6. ```

  1. ``` js
  2. // Initialize pell on an HTMLElement
  3. pell.init({
  4.   // , required
  5.   element: document.getElementById('some-id'),

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

  9.   // , optional, default = 'div'
  10.   // Instructs the editor which element to inject via the return key
  11.   defaultParagraphSeparator: 'div',

  12.   // , optional, default = false
  13.   // Outputs instead of
  14.   styleWithCSS: false,

  15.   // , string if overwriting, object if customizing/creating
  16.   // action.name (only required if overwriting)
  17.   // action.icon (optional if overwriting, required if custom action)
  18.   // action.title (optional)
  19.   // action.result (required)
  20.   // Specify the actions you specifically want (in order)
  21.   actions: [
  22.     'bold',
  23.     {
  24.       name: 'custom',
  25.       icon: 'C',
  26.       title: 'Custom Action',
  27.       result: () => console.log('Do something!')
  28.     },
  29.     'underline'
  30.   ],

  31.   // classes (optional)
  32.   // Choose your custom class names
  33.   classes: {
  34.     actionbar: 'pell-actionbar',
  35.     button: 'pell-button',
  36.     content: 'pell-content',
  37.     selected: 'pell-button-selected'
  38.   }
  39. })

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

List of overwriteable action names

- bold
- italic
- underline
- strikethrough
- heading1
- heading2
- paragraph
- quote
- olist
- ulist
- code
- line
- link
- image

Examples


General


  1. ``` html
  2. <div id="editor" class="pell"></div>
  3. <div>
  4.   HTML output:
  5.   <div id="html-output" style="white-space:pre-wrap;"></div>
  6. </div>
  7. ```

  1. ``` js
  2. import { exec, init } from 'pell'

  3. const editor = init({
  4.   element: document.getElementById('editor'),
  5.   onChange: html => {
  6.     document.getElementById('html-output').textContent = html
  7.   },
  8.   defaultParagraphSeparator: 'p',
  9.   styleWithCSS: true,
  10.   actions: [
  11.     'bold',
  12.     'underline',
  13.     {
  14.       name: 'italic',
  15.       result: () => exec('italic')
  16.     },
  17.     {
  18.       name: 'backColor',
  19.       icon: '<div style="background-color:pink;">A</div>',
  20.       title: 'Highlight Color',
  21.       result: () => exec('backColor', 'pink')
  22.     },
  23.     {
  24.       name: 'image',
  25.       result: () => {
  26.         const url = window.prompt('Enter the image URL')
  27.         if (url) exec('insertImage', url)
  28.       }
  29.     },
  30.     {
  31.       name: 'link',
  32.       result: () => {
  33.         const url = window.prompt('Enter the link URL')
  34.         if (url) exec('createLink', url)
  35.       }
  36.     }
  37.   ],
  38.   classes: {
  39.     actionbar: 'pell-actionbar-custom-name',
  40.     button: 'pell-button-custom-name',
  41.     content: 'pell-content-custom-name',
  42.     selected: 'pell-button-selected-custom-name'
  43.   }
  44. })

  45. // editor.content
  46. // To change the editor's content:
  47. editor.content.innerHTML = '<b><u><i>Initial content!</i></u></b>'
  48. ```

Example (Markdown)


  1. ``` html
  2. <div id="editor" class="pell"></div>
  3. <div>
  4.   Markdown output:
  5.   <div id="markdown-output" style="white-space:pre-wrap;"></div>
  6. </div>
  7. ```

  1. ``` js
  2. import { init } from 'pell'
  3. import Turndown from 'turndown'

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

  5. init({
  6.   element: document.getElementById('editor'),
  7.   actions: ['bold', 'italic', 'heading1', 'heading2', 'olist', 'ulist'],
  8.   onChange: html => {
  9.     document.getElementById('markdown-output').innerHTML = turndown(html)
  10.   }
  11. })
  12. ```

Frameworks


- Vue

Custom Styles


SCSS


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

  4. // Then import pell.scss into styles:
  5. @import '../../node_modules/pell/src/pell';
  6. ```

CSS


  1. ```css
  2. /* After pell styles are applied to DOM: */
  3. .pell-content {
  4.   height: 400px;
  5. }
  6. ```

License


MIT

Credits


BrowserStack for cross browser testing:

BrowserStack logo