pell - the simplest and smallest WYSIWYG text editor for web, with no dependencies
npm install pell-spc#### v2 working branch and v2 project board
---


> pell is the simplest and smallest WYSIWYG text editor for web, with no dependencies
Live demo: https://jaredreich.com/pell

bash
npm install --save pell
`
#### HTML:
`html
...
...
`
Usage
#### API
`js
// ES6
import pell from 'pell'
// or
import { exec, init } from 'pell'
`
`js
// Browser
pell
// or
window.pell
`
`js
// Initialize pell on an HTMLElement
pell.init({
// , required
element: document.getElementById('some-id'),
// , required
// Use the output html, triggered by element's oninput event
onChange: html => console.log(html),
// , optional, default = 'div'
// Instructs the editor which element to inject via the return key
defaultParagraphSeparator: 'div',
// , optional, default = false
// Outputs instead of
styleWithCSS: false,
// , string if overwriting, object if customizing/creating
// action.name (only required if overwriting)
// action.icon (optional if overwriting, required if custom action)
// action.title (optional)
// action.result (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 (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, value)
`
#### List of overwriteable action names
- bold
- italic
- underline
- strikethrough
- heading1
- heading2
- paragraph
- quote
- olist
- ulist
- code
- line
- link
- image
Examples
#### General
`html
HTML output:
`
`js
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: 'A',
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
// To change the editor's content:
editor.content.innerHTML = 'Initial content!'
`
#### Example (Markdown)
`html
Markdown output:
`
`js
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
- React
- Vue
Custom Styles
#### SCSS
`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
`css
/ After pell styles are applied to DOM: /
.pell-content {
height: 400px;
}
``