Well, I know there are lot's of powerful richtext editors out in the wild! But I couldn't skip the fun parts, so I created one beacuase I needed something for my blog. This editor works based on contenteditable but I have avoided to use execCommand. You can check out the demo here.
!Demo
Getting Started
First of all you need an empty element on the page to handle the editor. It could be a
or an :
``html
` To use the richtext you can both download it or install it from the npm.
You can also install Richtext from npm:
` npm i @alidoustkani/richtext
` `javascript
import {create} from '@alidoustkani/richtext'
const rt = create(document.getElementById('richtext'), options) // see below for options
`
API & Options
There are two kinds of methods in richtext: style() and apply().
style() applies the style to the selected text, and if there is no selection there won't be any style. apply() applies the style to the selected text and when there is no selection available it will add the style to the whole paragraph.
`javascript
{
defaulLink: 'https://',
staySelected: true,
decors: {
important: 'strong',
highlight: {
tag: 'span',
className: 'highlight-class-name'
},
notebox: {
parent: true,
tag: 'div',
className: 'notebox-class-name'
}
}
}
`
$3
* {Ctrl}ENTER: creates the next
editor and goes to it.
* {Ctrl}SPACE: appends a RLM to the current position.
$3
* defaultLink: default text in the link popup.
* staySelected: for true value, the selection will remain the same after applying styles.
* decors: styling configuration. Use this option to define your styling elements and css classes.