Toolbar Configuration in Angular Markdown Editor

29 Aug 202521 minutes to read

Default toolbar items

By default, the Angular Markdown Editor displays the following toolbar items:

Bold , Italic , | , Formats , Blockquote, OrderedList , UnorderedList , | , CreateLink , Image , | , SourceCode , Undo , Redo

These default items cover essential text editing features, such as text formatting, lists, and linking.

Type of toolbar

Configure the toolbar layout using the type property in toolbarSettings. Available types:

  • Expand: Hides overflowing items, accessible via an expand arrow (recommended for compact layouts).
  • MultiRow: Displays items across multiple rows, keeping all visible (ideal for wide screens).
  • Scrollable: Scrolls items horizontally (suitable for limited space).

Expand Toolbar

The default toolbar mode is Expand, which is configured using toolbarSettings with type: Expand.

In this mode, any overflowing toolbar items are hidden in the next row. Users can reveal them by clicking the expand arrow.

import { Component } from '@angular/core';
import { RichTextEditorModule, ToolbarService, MarkdownEditorService , HtmlEditorService, ImageService, LinkService, TableService, ToolbarSettingsModel } from '@syncfusion/ej2-angular-richtexteditor';

@Component({
    imports: [
        RichTextEditorModule
    ],
    standalone: true,
    selector: 'app-root',
    template: `<ejs-richtexteditor id='markdown-editor' width="500px" [editorMode]='mode' [toolbarSettings]='tools' [value]="value"></ejs-richtexteditor>`,
    providers: [ToolbarService, HtmlEditorService, MarkdownEditorService, ImageService, LinkService, TableService]
})

export class AppComponent {
    public mode: string = 'Markdown';
    public value: string =
      'In Rich Text Editor, you click the toolbar buttons to format the words and the changes are visible immediately. Markdown is not like that. When you format the word in Markdown format, you need to add Markdown syntax to the word to indicate which words and phrases should look different from each other. Rich Text Editor supports markdown editing when the editorMode set as **markdown** and using both *keyboard interaction* and *toolbar action*, you can apply the formatting to text. You can add our own custom formation syntax for the Markdown formation, [sample link](https://ej2.syncfusion.com/home/). The third-party library <b>Marked</b> is used in this sample to convert markdown into HTML content.';
  
    public tools: ToolbarSettingsModel = {
      type: 'Expand' as ToolbarSettingsModel['type'],
      items: [
        'Bold',
        'Italic',
        'StrikeThrough',
        'InlineCode',
        'SuperScript',
        'SubScript',
        '|',
        'Formats',
        'Blockquote',
        '|',
        'OrderedList',
        'UnorderedList',
        'CreateLink',
        'Image',
        'CreateTable',
      ],
    };
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));

MultiRow Toolbar

By setting type: MultiRow in toolbarSettings, the toolbar items are arranged across multiple rows. This ensures that all configured toolbar items are always visible.

import { Component } from '@angular/core';
import { RichTextEditorModule, ToolbarService, MarkdownEditorService , HtmlEditorService, ImageService, LinkService, TableService, ToolbarSettingsModel } from '@syncfusion/ej2-angular-richtexteditor';

@Component({
    imports: [
        RichTextEditorModule
    ],
    standalone: true,
    selector: 'app-root',
    template: `<ejs-richtexteditor id='markdown-editor' width="500px" [editorMode]='mode' [toolbarSettings]='tools' [value]="value"></ejs-richtexteditor>`,
    providers: [ToolbarService, HtmlEditorService, MarkdownEditorService, ImageService, LinkService, TableService]
})

export class AppComponent {
    public mode: string = 'Markdown';
    public value: string =
      'In Rich Text Editor, you click the toolbar buttons to format the words and the changes are visible immediately. Markdown is not like that. When you format the word in Markdown format, you need to add Markdown syntax to the word to indicate which words and phrases should look different from each other. Rich Text Editor supports markdown editing when the editorMode set as **markdown** and using both *keyboard interaction* and *toolbar action*, you can apply the formatting to text. You can add our own custom formation syntax for the Markdown formation, [sample link](https://ej2.syncfusion.com/home/). The third-party library <b>Marked</b> is used in this sample to convert markdown into HTML content.';
  
    public tools: ToolbarSettingsModel = {
      type: 'Multirow' as ToolbarSettingsModel['type'],
      items: [
        'Bold',
        'Italic',
        'StrikeThrough',
        'InlineCode',
        'SuperScript',
        'SubScript',
        '|',
        'Formats',
        'Blockquote',
        '|',
        'OrderedList',
        'UnorderedList',
        'CreateLink',
        'Image',
        'CreateTable',
      ],
    };
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));

Scrollable Toolbar

Use type: 'Scrollable' in toolbarSettings to create a single-line toolbar with horizontal scrolling capability for overflow items.

import { Component } from '@angular/core';
import { RichTextEditorModule, ToolbarService, MarkdownEditorService , HtmlEditorService, ImageService, LinkService, TableService, ToolbarSettingsModel } from '@syncfusion/ej2-angular-richtexteditor';

@Component({
    imports: [
        RichTextEditorModule
    ],
    standalone: true,
    selector: 'app-root',
    template: `<ejs-richtexteditor id='markdown-editor' width="500px" [editorMode]='mode' [toolbarSettings]='tools' [value]="value"></ejs-richtexteditor>`,
    providers: [ToolbarService, HtmlEditorService, MarkdownEditorService, ImageService, LinkService, TableService]
})

export class AppComponent {
    public mode: string = 'Markdown';
    public value: string =
      'In Rich Text Editor, you click the toolbar buttons to format the words and the changes are visible immediately. Markdown is not like that. When you format the word in Markdown format, you need to add Markdown syntax to the word to indicate which words and phrases should look different from each other. Rich Text Editor supports markdown editing when the editorMode set as **markdown** and using both *keyboard interaction* and *toolbar action*, you can apply the formatting to text. You can add our own custom formation syntax for the Markdown formation, [sample link](https://ej2.syncfusion.com/home/). The third-party library <b>Marked</b> is used in this sample to convert markdown into HTML content.';
  
    public tools: ToolbarSettingsModel = {
      type: 'Scrollable' as ToolbarSettingsModel['type'],
      items: [
        'Bold',
        'Italic',
        'StrikeThrough',
        'InlineCode',
        'SuperScript',
        'SubScript',
        '|',
        'Formats',
        'Blockquote',
        '|',
        'OrderedList',
        'UnorderedList',
        'CreateLink',
        'Image',
        'CreateTable',
      ],
    };
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));

Creating a Sticky Toolbar

By default, the toolbar remains fixed at the top of the Markdown editor when scrolling.

You can customize its position by setting floatingToolbarOffset to adjust the offset from the top of the document.

Additionally, you can enable or disable the floating toolbar using the enableFloating property.

import { CheckBoxModule } from '@syncfusion/ej2-angular-buttons'
import { Component, ViewChild } from '@angular/core';
import { RichTextEditorModule, ToolbarService, HtmlEditorService, MarkdownEditorService, ImageService, LinkService, TableService, RichTextEditorComponent, ToolbarSettingsModel } from '@syncfusion/ej2-angular-richtexteditor';
import { CheckBoxComponent } from '@syncfusion/ej2-angular-buttons';
@Component({
  imports: [
    RichTextEditorModule,
    CheckBoxModule
  ],
  standalone: true,
  selector: 'app-root',
  template: `<ejs-richtexteditor #typeEditor id='editor' [editorMode]='mode' [toolbarSettings]='tools' [(value)]='value'>
    </ejs-richtexteditor>
     <div>
    <ejs-checkbox #float label="Enable Floating" [checked]="true" (change)="onChangeFloat()"></ejs-checkbox>
    </div>`,
  providers: [ToolbarService, HtmlEditorService, MarkdownEditorService, ImageService, LinkService, TableService]
})
export class AppComponent {
  @ViewChild('float') editorFloatObj: CheckBoxComponent | undefined;
  @ViewChild('typeEditor') editorObj: RichTextEditorComponent | undefined;
  public mode: string = 'Markdown';
  public value: string = "<p>The Rich Text Editor triggers events based on its actions. </p><p> The events can be used as an extension point to perform custom operations.</p><ul><li>created - Triggers when the component is rendered.</li><li>change - Triggers only when Rich Text Editor is blurred and changes are done to the content.</li><li>focus - Triggers when Rich Text Editor is focused in.</li><li>blur - Triggers when Rich Text Editor is focused out.</li><li>actionBegin - Triggers before command execution using toolbar items or executeCommand method.</li><li>actionComplete - Triggers after command execution using toolbar items or executeCommand method.</li><li>destroyed – Triggers when the component is destroyed.</li></ul>";
  public tools: ToolbarSettingsModel = {
    enableFloating: false
  };
  public onChangeFloat(): void {
    this.editorObj!.toolbarSettings.enableFloating = this.editorFloatObj!.checked;
  }
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));

Custom Toolbar Items

The Markdown Editor allows you to add custom commands to the toolbar using the toolbarSettings property. These custom commands can be displayed as plain text, icons, or HTML templates. You can define their order and grouping, ensuring a structured and intuitive toolbar layout. Additionally, actions can be bound to these commands by retrieving their instances and handling events accordingly.

In this example, a custom toolbar item (Ω) is added to insert special characters into the editor. When users click the Ω button, a list of special characters appears, allowing them to select and insert a character into the content. This feature enhances the Markdown Editor by providing quick access to special symbols without manually entering character codes.

The following code snippet demonstrates how to configure a custom toolbar item with a tooltip. The item is added to the items field of the toolbarSettings property, ensuring seamless integration within the toolbar.

import { Component, ViewChild } from '@angular/core';
import { RichTextEditorModule, ToolbarService, LinkService, MarkdownEditorService, ImageService, HtmlEditorService, TableService, RichTextEditorComponent, NodeSelection, ToolbarSettingsModel } from '@syncfusion/ej2-angular-richtexteditor';
import { ButtonPropsModel } from '@syncfusion/ej2-popups';
import { DialogComponent, DialogModule } from '@syncfusion/ej2-angular-popups';

@Component({
    imports: [
        RichTextEditorModule,
        DialogModule
    ],
    standalone: true,
    selector: 'app-root',
    template: `<ejs-richtexteditor id='customEditor' height="400px" #customEditor [editorMode]='mode' [toolbarSettings]='tools' (created)='onCreate()' [(value)]='value'>
        </ejs-richtexteditor>
        <ejs-dialog #Dialog id="editorDialog" [buttons]='dlgButtons'  [target]='target' (overlayClick)="dialogOverlay()" [header]='header' [visible]='false'
            [showCloseIcon]='false' (created)="dialogCreate()" [isModal]='true' [cssClass]='cssClass' [content]='contentData'>
        </ejs-dialog>`,
    providers: [ToolbarService, LinkService, ImageService, MarkdownEditorService, HtmlEditorService, TableService]
})

export class AppComponent {
    @ViewChild('customEditor')
    public editorObj?: RichTextEditorComponent;
    @ViewChild('Dialog')
    public dialogObj?: DialogComponent;
    public mode: string = 'Markdown';
    public value: string =
      'In Rich Text Editor, you click the toolbar buttons to format the words and the changes are visible immediately. Markdown is not like that. When you format the word in Markdown format, you need to add Markdown syntax to the word to indicate which words and phrases should look different from each other. Rich Text Editor supports markdown editing when the editorMode set as **markdown** and using both *keyboard interaction* and *toolbar action*, you can apply the formatting to text. You can add our own custom formation syntax for the Markdown formation, [sample link](https://ej2.syncfusion.com/home/). The third-party library <b>Marked</b> is used in this sample to convert markdown into HTML content.';
    public contentData: string =
      '<div id="rteSpecial_char"><div class="char_block" title="^">^</div><div class="char_block" title="_">_</div><div class="char_block" title="|">|</div><div class="char_block" title="¡">¡</div><div class="char_block" title="¢">¢</div><div class="char_block" title="£">£</div><div class="char_block" title="¤">¤</div><div class="char_block" title="¥">¥</div><div class="char_block" title="₹">₹</div><div class="char_block" title="§">§</div><div class="char_block" title="©">©</div></div>';
    public target: HTMLElement = document.getElementById(
      'rteSection'
    ) as HTMLElement;
    public tools: ToolbarSettingsModel = {
      items: [
        'Bold',
        'Italic',
        'StrikeThrough',
        '|',
        'Formats',
        'OrderedList',
        'UnorderedList',
        '|',
        'CreateLink',
        '|',
        {
          tooltipText: 'Insert Symbol',
          undo: true,
          click: this.onClick.bind(this),
          template: `<button class="e-tbar-btn e-btn" tabindex="-1" id="custom_tbar" style="width:100%">
              <div class="e-tbar-btn-text" style="font-weight: 500;"> Ω</div>
            </button>`,
        },
      ],
    };
  
    public dlgButtons: ButtonPropsModel[] = [
      {
        buttonModel: { content: 'Insert', isPrimary: true },
        click: this.onInsert.bind(this),
      },
      {
        buttonModel: { content: 'Cancel' },
        click: this.dialogOverlay.bind(this),
      },
    ];
  
    public header: string = 'Special Characters';
    public cssClass: String = 'customClass e-rte-elements';
  
    public onCreate(): void {
      (this.dialogObj as DialogComponent).target = document.getElementById(
        'customEditor'
      ) as HTMLElement;
    }
  
    public dialogCreate(): void {
      let dialogCtn: HTMLElement = document.getElementById(
        'rteSpecial_char'
      ) as HTMLElement;
      dialogCtn.onclick = (e: Event) => {
        let target: HTMLElement = e.target as HTMLElement;
        let activeEle: Element = this.dialogObj!.element.querySelector(
          '.char_block.e-active'
        ) as Element;
        if (target.classList.contains('char_block')) {
          target.classList.add('e-active');
          if (activeEle) {
            activeEle.classList.remove('e-active');
          }
        }
      };
    }
  
    public onClick() {
      this.dialogObj!.width = this.editorObj!.element.offsetWidth * 0.5;
      this.dialogObj!.show();
      this.dialogObj!.element.style.maxHeight = 'none';
    }
  
    public onInsert(): void {
      let activeEle: Element = this.dialogObj!.element.querySelector(
        '.char_block.e-active'
      ) as Element;
      if (activeEle) {
        let specialChar = (activeEle as Element).textContent as string;
        this.editorObj!.executeCommand('insertText', specialChar);
      }
      this.dialogOverlay();
    }
  
    public dialogOverlay(): void {
      let activeEle: Element = this.dialogObj!.element.querySelector(
        '.char_block.e-active'
      ) as Element;
      if (activeEle) {
        activeEle.classList.remove('e-active');
      }
      this.dialogObj!.hide();
    }
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));