How to Integrate Third-Party Libraries into Angular Rich Text Editor
Tags: javascript, andular, typescript, webdev
Published: 2019-09-04 12:10:50

---
title: How to Integrate Third-Party Libraries into Angular Rich Text Editor
published: true
tags: javascript, andular, typescript, webdev
canonical_url: https://www.syncfusion.com/blogs/post/how-to-integrate-third-party-libraries-into-angular-rich-text-editor.aspx
cover_image: https://thepracticaldev.s3.amazonaws.com/i/49utyg5pwu9g14qa3jav.jpg
---
People always like to draft or edit emails, blogs, webpages, or proposals using impressive formatting options and layouts. Say you want to draft a well-formatted email to your boss, or comment on blogs or forums with funny smiley faces. You obviously need a rich WYSIWYG ( **What You See Is What You Get** ) editing interface to support all kinds of editing and formatting options in a single place.

The [Rich Text Editor](https://www.syncfusion.com/angular-ui-components/angular-wysiwyg-rich-text-editor) (RTE) offered by Syncfusion serves this purpose and acts as both a feature-rich WYSIWYG text editor and a markdown editor. With this kind of WYSIWYG user interface, you can edit and view the content format in a very similar way to the end outcome. The RTE is available on the web platforms [Angular](https://www.syncfusion.com/angular-ui-components/angular-wysiwyg-rich-text-editor), [React](https://www.syncfusion.com/react-ui-components/react-wysiwyg-rich-text-editor), [Vue](https://www.syncfusion.com/vue-ui-components/vue-wysiwyg-rich-text-editor), [JavaScript](https://www.syncfusion.com/javascript-ui-controls/js-wysiwyg-rich-text-editor), [ASP.NET MVC](https://www.syncfusion.com/aspnet-mvc-ui-controls/wysiwyg-rich-text-editor), [ASP.NET Core](https://www.syncfusion.com/aspnet-core-ui-controls/wysiwyg-rich-text-editor), and [Blazor](https://www.syncfusion.com/blazor-components/blazor-wysiwyg-rich-text-editor).

## When you should integrate third-party libraries into RTE

There may be times you want to type HTML content in the comments section of a blog or forum, or you need to address several people by their names. In cases of technical assistance, you may have to post some code snippets using the editor. Also, sometimes you may find it important to enable the spell checker in the editing interface or to embed some rich social media in it.

All of these actions are possible by integrating additional third-party libraries into our Essential JS 2 Rich Text Editor.

In this blog, I’ll explain in brief how easy it is to integrate third-party libraries like [Tribute.js](https://github.com/zurb/tribute), [Embed.ly](https://embed.ly/), [CodeMirror](https://github.com/codemirror/codemirror), and [WebSpellChecker](https://webspellchecker.com/) into the Angular Rich Text Editor.

**Note:** To get started with adding a basic Angular Rich Text Editor to your application, please refer to the Getting Started documentation.

You can also use the command **ng add @syncfusion/ej2-angular-richtexteditor** to install and autoconfigure the application with the required modules and CSS references.

## Integrate Tribute.js

When you want to tag or address someone directly during a conversation, you might use @ mentioning, which was popularized by Twitter. It will present a list of matching names based on the provided key-value pair.

Say, for example, I start to type someone’s name in Twitter or Microsoft Teams starting with an @ mention. It will automatically suggest the names that match the letters typed in.

Now, you can also use this @mentioning mechanism inside our Angular Rich Text Editor content area by referencing the appropriate scripts and CSS of TributeJS in your application.

1. Use the following command to install TributeJS locally in your application.

```
npm install tributejs
```

2. Now reference the cdn link of Tribute CSS within your index.html file.

```html
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/tributejs@3.5.3/dist/tribute.css">
```

3. Start to import the TributeJS within the app.component.ts file.

```js
import Tribute from "tributejs";
```

4. Use the following TributeJS initialization code within the “created” event of Rich Text Editor and attach its instance to the input element of RTE. Refer to [GitHub](https://github.com/zurb/tribute) to learn about the other options available on TributeJS.

```js
let tribute = new Tribute({
values: [
{ key: 'Jacob', value: 'jacob@mail.com' },
{ key: 'Isabella', value: 'isabella@mail.com' }
]
});
 
tribute.attach(this.defaultRTEObj.inputElement);
```

![Including @ mentions with the help of Tribute.js - A third-party library for Angular Rich Text Editor](https://www.syncfusion.com/blogs/wp-content/uploads/2019/08/Including-@-mentions-with-the-help-of-Tribute.js.png)

<figcaption>Including @ mentions in Angular RTE</figcaption>

**Note:** You can also use At.js library to include such @ mentioning functionality in the Angular Rich Text Editor, which can be referenced from the [documentation](https://ej2.syncfusion.com/angular/documentation/rich-text-editor/third-party-integration/#code-classlanguage-textatjscode-integration) page.

## Integrate Embed.ly

Using Embed.ly, you can easily add rich media to your site with a very few lines of code. All you need is to add the Embedly script reference in your application and then generate the embed code with appropriate classes within the actionComplete event of Angular Rich Text Editor.

1. Add the Embedly script reference in the index.html page.

```html
<script src="https://cdn.embedly.com/widgets/platform.js" charset="UTF-8"></script>
```

2. Define the actionComplete event handler of Angular Rich Text Editor. Check whether the hyperlink is newly inserted (requestType===‘Links’) and if so, generate the embed code within it as follows.

```js
public actionComplete(args: any): void {
 
if (args.requestType === 'Links') {
const embedEle: HTMLElement = document.createElement('blockquote');
embedEle.setAttribute('class', 'embedly-card');
embedEle.appendChild(args.elements[0].parentElement);
embedEle.appendChild(document.createElement('p'));
args.range.insertNode(embedEle);
}
}
```

![Rich media content in Angular RTE](https://www.syncfusion.com/blogs/wp-content/uploads/2019/08/Rich-media-content-in-Angular-RTE.png)

<figcaption>Rich media content in Angular RTE</figcaption>

**Note:** Make sure to add the [CreateLink](https://ej2.syncfusion.com/angular/documentation/rich-text-editor/link/) option on the RTE toolbar list to input the media links.

## Integrate a spell checker

If you would like to check spelling and grammatical issues while you type in the content area of our Angular Rich Text Editor component, you can do so by integrating a third-party library, WebSpellChecker, which provides a cloud spell-checking service.

Download the trial or paid version of [WebSpellChecker](https://www.webspellchecker.net/signup/hosted-signup.html#webspellchecker-proofreader-trial) and you will receive an activation key in your registered email. This is mandatory to initialize and configure the spell checking in the application.

1. Add the [WebSpellChecker WProofreader](https://docs.webspellchecker.net/pages/viewpage.action?pageId=442663877) script reference in your index.html page.

```html
<script src="https://svc.webspellchecker.net/spellcheck31/wscbundle/wscbundle.js"></script>
```

2. Now, initialize the WebSpellChecker within the index.html page using the Windows configuration variable along with its other required options such as autoSearch, enableGrammar, and serviceId.

```html
<script> 
    window.WEBSPELLCHECKER_CONFIG = { 
        autoSearch: true, 
        enableGrammar: true, 
        // Get the activation key from your registered account 
        serviceId: '1:kir4Z3-3VEfP-o8bLS2-iIYiz2-2xQou3-vM58l3-D9AUu3-7cBdu2-2GuIt2-tehUv-OOBiI-qc' 
    }; 
</script>
```

![Spell check implemented in Angular RTE](https://www.syncfusion.com/blogs/wp-content/uploads/2019/08/Spell-check-implemented-in-Angular-RTE.png)

<figcaption>Spell check implemented in Angular RTE</figcaption>

**Note:** Only when the serviceId option is assigned with a valid activation key will the spell-checking functionality work in the Rich Text Editor.

## Integrate CodeMirror

The Angular Rich Text Editor comes with the default source view option that presents the source code in a plain code format. If you would like to highlight the HTML source code in a more pleasing and readable format, then you should make use of additional third-party syntax or code highlighting libraries like CodeMirror or PrismJS in your application. Now, let’s see how to integrate the CodeMirror plugin into Syncfusion Angular Rich Text Editor.

**Note:** Make sure to enable the SourceCode option on the RTE toolbar list to toggle between the source code and preview mode.

1. Install the CodeMirror package through the npm install command in your application.

```
npm install codemirror
```

2. Now, import the necessary CodeMirror files into the app.component.ts file.

```js
import * as CodeMirror from 'codemirror';
import 'codemirror/mode/javascript/javascript';
import 'codemirror/mode/css/css.js';
import 'codemirror/mode/htmlmixed/htmlmixed.js';
```

3. Add the necessary CDN link references of CodeMirror scripts and CSS in the index.html file.

```html
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.3.0/codemirror.min.css">
     
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.3.0/codemirror.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.3.0/mode/xml/xml.min.js"></script>
```

4. Finally, define the actionComplete event for Angular Rich Text Editor and add its handler code as follows. Here, the content of the Rich Text Editor should be passed as a value to the CodeMirror.

```js
public actionCompleteHandler(e: any): void {
    if (e.targetItem === 'SourceCode') {
        (this.rteObj.sourceCodeModule.getPanel() as HTMLTextAreaElement).style.display = 'none';
        this.mirrorView = createElement('div', { className: 'e-content' }); 
        this.rteObj.contentModule.getEditPanel().parentNode.appendChild(this.mirrorView);
        this.myCodeMirror = CodeMirror(this.mirrorView, { value: this.rteObj.value, mode: 'text/html', lineWrapping: true });
    }
    else if (e.targetItem === 'Preview') {
        this.rteObj.value = this.myCodeMirror.getValue();
        this.mirrorView.style.display='none';
    }
}
```

![HTML tags displayed in the correct format](https://www.syncfusion.com/blogs/wp-content/uploads/2019/08/HTML-tags-displayed-in-the-correct-format.png)

<figcaption>HTML tags displayed in Angular RTE</figcaption>

## Summary

Well-drafted and the highly formatted content usually keeps users more engaged than simple plain text. Also, we prefer to edit content in the same HTML format as it will be viewed while being read. The Syncfusion Angular Rich Text Editor plays an important role in serving these purposes. It also supports the integration of third-party libraries like TributeJS, Embed.ly, WebSpellChecker, CodeMirror and many more to enhance its real-time usability.

Check out the other features of Angular Rich Text Editor by downloading the [free 30-day trial](https://www.syncfusion.com/account/manage-trials/downloads) or cloning it from [GitHub](https://github.com/syncfusion/ej2-angular-ui-components/tree/master/components/richtexteditor). Also, feel free to have a look at our [online samples](https://ej2.syncfusion.com/angular/demos/#/material/rich-text-editor/tools) and [documentation](https://ej2.syncfusion.com/angular/documentation/rich-text-editor/getting-started/) to explore other available options. If you wish to send us [feedback](https://www.syncfusion.com/feedback) or would like to ask any questions, please feel free to post in the comments section below, or contact us through our [support forum](https://www.syncfusion.com/forums), [Direct-Trac](https://www.syncfusion.com/support/directtrac/incidents), or [feedback portal](https://www.syncfusion.com/feedback/angular).

The post [How to Integrate Third-Party Libraries into Angular Rich Text Editor](https://www.syncfusion.com/blogs/post/how-to-integrate-third-party-libraries-into-angular-rich-text-editor.aspx) appeared first on [Syncfusion Blogs](https://www.syncfusion.com/blogs).