Contribute to this guide

guideMarkdown output

The Markdown plugin allows switching the default CKEditor 5 output from HTML to Markdown. This allows for producing lightweight text documents with a simple formatting syntax, widespread among the programming and development communities and popular in many environments (e.g. GitHub). Coupled with the autoformatting feature, it allows for the full-fledged Markdown WYSIWYG editing experience.

You can learn more about the possible practical applications of Markdown editing with CKEditor 5 in this dedicated blog post depicting the idea, solutions and a case study.

# Demo

The CKEditor 5 instance below is configured to output GitHub Flavored Markdown. Use the editor to create your content and see the Markdown output displayed as you type below the editor.

The Markdown language

Markdown is a lightweight markup language that you can use to add formatting elements to plain text documents. Created by John Gruber in 2004, Markdown is now one of the world’s most popular markup languages.

Editing with Markdown output

The CKEditor 5 WYSIWYG editor lets you use this flexible yet simple markup language in the GitHub flavor. The editor-produced Markdown output supports the most important features, like links, different kinds of emphasis, inline code formatting or code blocks:

p {
  text-align: center;
  color: red;
}

Formatting blocks with Markdown

Markdown can be used to create various block-level features, such as:

  • Block quotes
  • Headings
    1. Heading 1
    2. Heading 2
    3. Heading 3
  • Lists, including nested ones
    • Numbered lists
    • Bulleted lists

Output:

Some other ways to output the edited content include:

  • Export to Word – Generate editable .docx files out of your editor-created content.
  • Export to PDF – Generate portable PDF files out of your editor-created content.
  • Autoformatting – Use Markdown syntax shortcodes to automatically format your content as you type!

# The Markdown data processor

The Markdown plugins uses a data processor (implemented by the GFMDataProcessor class) which changes the default output from HTML to Markdown. This means that you can set or get data from the editor in the Markdown format:

editor.getData(); // -> 'This is [CKEditor 5](https://ckeditor.com).'

editor.setData( 'This is **bold**.' );

The data processor outputs the GFM Markdown syntax. “GFM” stands for “GitHub Flavored Markdown” — a Markdown dialect used by GitHub. Markdown lacks any formal specification (although the CommonMark initiative aims to close this gap) and has many dialects, often incompatible with one another.

When converting the output produced by this data processor, make sure to use a compatible Markdown-to-HTML converter (e.g. the marked library).

This feature is experimental. While the CKEditor 5 architecture supports changing the data format, in most scenarios we do recommend sticking to the default format which is HTML (supported by the HtmlDataProcessor). HTML remains the best standard for rich-text data.

And please do remember — using Markdown does not automatically make your application or website secure.

# Installation

To enable this data processor in your editor, install the @ckeditor/ckeditor5-markdown-gfm package:

npm install --save @ckeditor/ckeditor5-markdown-gfm

Then add the Markdown plugin to the editor configuration, which will change the default data processor to the GFMDataProcessor:

import ClassicEditor from '@ckeditor/ckeditor5-editor-classic/src/classiceditor';

import Essentials from '@ckeditor/ckeditor5-essentials/src/essentials';
import Bold from '@ckeditor/ckeditor5-basic-styles/src/bold';
import Italic from '@ckeditor/ckeditor5-basic-styles/src/italic';
// ...

import Markdown from '@ckeditor/ckeditor5-markdown-gfm/src/markdown';

ClassicEditor
    .create( document.querySelector( '#snippet-markdown' ), {
        plugins: [
            Markdown,

            Essentials,
            Bold,
            Italic,
            // ...
        ],
        // ...
    } )
    .then( ... )
    .catch( ... );

# Contribute

The source code of this feature is available on GitHub in https://github.com/ckeditor/ckeditor5/tree/master/packages/ckeditor5-markdown-gfm.