Markdown 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, as described in the “CKEditor 5: the best open source Markdown editor” blog post. Visit the free online Markdown editor to see this solution implemented.
Please remember that Markdown syntax is very simple and it does not cover all the rich-text features. Some features provided by CKEditor 5 will thus work as intended only when output to HTML as they have no Markdown equivalent.
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.
Please observe that the source editing in the demo below is a separate feature. If you would like to use it in your integration, it needs to be installed separately.
Output:
# Extending formatting support
If you need a more extensive Markdown support for formatting elements (for example, having the title
attribute on links represented as [Foo Bar](https://foo.bar "My link title")
), you can also install General HTML Support. This advanced feature allows the integrators to provide additional tags, elements and attributes, not yet supported by other CKEditor 5 plugins and extend the formatting capabilities.
# Related features
Some other ways to output the edited content include:
- Source editing – Allows for Markdown source edition if configured accordingly.
- 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).
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( ... );
Read more about installing plugins.
# Known issues
Please bear in mind that the Markdown data processor does not support all rich text features. The Markdown syntax is very simple and only supports limited formatting options.
This means that advanced formatting like list styles, table styles or page break markers will be stripped in the effecting data. These are not supported by Markdown and therefore cannot be converted from HTML to Markdown.
While the Markdown plugin is stable and ready to use, some issues are still being worked on. Feel free to upvote 👍 these on GitHub if you would like to see this introduced.
- Pasting Markdown-formatted content does not automatically convert the pasted syntax markers into properly formatted content. GitHub issues: #2321, #2322.
- The Markdown code generated with the Markdown output feature will not properly render nested tables. GitHUb issue: #9475.
# Contribute
The source code of this feature is available on GitHub in https://github.com/ckeditor/ckeditor5/tree/master/packages/ckeditor5-markdown-gfm.
Every day, we work hard to keep our documentation complete. Have you spotted an outdated information? Is something missing? Please report it via our issue tracker.