ngx-editor
Version:
Rich Text Editor for angular using ProseMirror
175 lines (130 loc) • 3.87 kB
Markdown
<p align="center">
<a href="https://github.com/sibiraj-s/ngx-editor">
<img src="./sketch/ngx-editor.svg" alt="ngxEditor">
</a>
</p>
<p align="center">Rich Text Editor for angular using ProseMirror</p>
<p align="center">
<a href="https://github.com/sibiraj-s/ngx-editor/actions">
<img alt="Tests" src="https://github.com/sibiraj-s/ngx-editor/workflows/Tests/badge.svg">
</a>
<a href="https://www.npmjs.com/package/ngx-editor">
<img alt="npm version" src="https://badgen.net/npm/v/ngx-editor">
</a>
<a href="https://www.npmjs.com/package/ngx-editor">
<img alt="npm" src="https://badgen.net/npm/dm/ngx-editor">
</a>
<a href="https://www.npmjs.com/package/ngx-editor">
<img alt="npm" src="https://badgen.net/npm/dt/ngx-editor">
</a>
<br />
<a href="https://github.com/sibiraj-s/ngx-editor/blob/master/LICENSE">
<img alt="licence" src="https://badgen.net/npm/license/ngx-editor">
</a>
<a href="https://open.vscode.dev/sibiraj-s/ngx-editor">
<img alt="Open in Visual Studio Code" src="https://open.vscode.dev/badges/open-in-vscode.svg">
</a>
</p>
[] | [edit on stackblitz][stackblitz] | [documentation] | [migrating from v4][migration] | [migrating from other editors][migration]
Install via Package managers such as [npm][npm] or [yarn][yarn]
```bash
npm install ngx-editor --save
yarn add ngx-editor
```
**Note**: By default the editor comes with minimal features. Refer the [demo](
Import `ngx-editor` module
```ts
import { NgxEditorModule } from 'ngx-editor';
@NgModule({
imports: [NgxEditorModule],
})
export class AppModule {}
```
Component
```ts
import { Editor } from 'ngx-editor';
export class EditorComponent implements OnInit, OnDestroy {
editor: Editor;
html: '';
ngOnInit(): void {
this.editor = new Editor();
}
// make sure to destory the editor
ngOnDestroy(): void {
this.editor.destroy();
}
}
```
Then in HTML
```html
<div class="NgxEditor__Wrapper">
<ngx-editor-menu [editor]="editor"> </ngx-editor-menu>
<ngx-editor
[]="editor"
[]="html"
[]="false"
[]="'Type here...'"
></ngx-editor>
</div>
```
Note: Input can be a HTML string or a jsonDoc
If the Input to the component is HTML, output will be HTML. To manually convert json output from the editor to html
```ts
import { toHTML } from 'ngx-editor';
const html = toHTML(jsonDoc, schema); // schema is optional
```
Or to convert HTML to json. Optional, as Editor will accept HTML input
```ts
import { toDoc } from 'ngx-editor';
const jsonDoc = toDoc(html);
```
```ts
this.editor.commands
.textColor('red')
.insertText('Hello world!')
.focus()
.scrollIntoView()
.exec();
```
Run `exec` to apply the changes to the editor.
You can specify locals to be used in the editor
```ts
NgxEditorModule.forRoot({
locals: {
bold: 'Bold',
italic: 'Italic',
code: 'Code',
underline: 'Underline',
// ...
},
});
```
Mostly works on all Evergreen-Browsers like
- Google Chrome
- Microsoft Edge
- Mozilla Firefox
- Opera
- Safari
Angular 13+.
See https://sibiraj-s.github.io/ngx-editor/#/collab
Icons are from https://material.io/resources/icons/
All contributions are welcome. See [CONTRIBUTING.md](./.github/CONTRIBUTING.md) to get started.
[]: https://www.npmjs.com/
[]: https://yarnpkg.com/lang/en/
[]: https://sibiraj-s.github.io/ngx-editor
[]: https://ngx-editor.stackblitz.io/
[]: https://stackblitz.com/edit/ngx-editor
[]: https://sibiraj-s.github.io/ngx-editor/#/migration