Skip to content

Latest commit

 

History

History
108 lines (74 loc) · 5.98 KB

File metadata and controls

108 lines (74 loc) · 5.98 KB
title meta-title category
Autoformatting
Autoformatting | CKEditor 5 Documentation
features

The autoformat feature lets you quickly format your content with Markdown-like shortcodes. This way you do not need to use toolbar buttons or dropdowns for the most common formatting features.

Demo

Test the autoformatting feature in the editor below. Try using Markdown shortcodes while typing. For example:

  1. Start a new line.
  2. Press # and then Space.

The line will automatically turn into a heading.

If needed, you can revert the automatic change by pressing Backspace.

{@snippet features/autoformat}

This demo presents a limited set of features. Visit the {@link examples/builds/full-featured-editor feature-rich editor example} to see more in action.

Block formatting

The following block formatting options are available:

  • {@link features/lists Bulleted list} – Start a line with * or - followed by a space.
  • {@link features/lists Numbered list} – Start a line with 1. or 1) followed by a space.
  • {@link features/todo-lists To-do list} – Start a line with [ ] or [x] followed by a space to insert an unchecked or checked list item, respectively.
  • {@link features/headings Headings} – Start a line with # or ## or ### followed by a space to create a heading 1, heading 2, or heading 3 (up to heading 6 if {@link module:heading/headingconfig~HeadingConfig#options} defines more headings).
  • {@link features/block-quote Block quote} – Start a line with > followed by a space.
  • {@link features/code-blocks Code block} – Start a line with ```.
  • {@link features/horizontal-line Horizontal line} – Start a line with ---.

Inline formatting

The following {@link features/basic-styles basic styles} inline formatting options are available:

  • Bold – Type **text** or __text__,
  • Italic – Type *text* or _text_,
  • Code – Type `text`,
  • Strikethrough – Type ~~text~~.

Installation

This feature is enabled by default in all {@link installation/getting-started/predefined-builds predefined builds}. The installation instructions are for developers interested in building their own, custom editor.

To add this feature to your editor install the @ckeditor/ckeditor5-autoformat package:

npm install --save @ckeditor/ckeditor5-autoformat

And add it to your plugin list:

import { Autoformat } from '@ckeditor/ckeditor5-autoformat';

ClassicEditor
	.create( document.querySelector( '#editor' ), {
		plugins: [ Autoformat, /* ... */ ],
		toolbar: [ /* ... */ ]
	} )
	.then( /* ... */ )
	.catch( /* ... */ );
Remember to add proper features to the editor configuration. Autoformatting will be enabled only for the commands that are included in the actual configuration. For example, `bold` autoformatting will not work if there is no `bold` command registered in the editor. Read more about {@link installation/plugins/installing-plugins installing plugins}.

Creating custom autoformatters

The {@link module:autoformat/autoformatAutoformat} feature bases on {@link module:autoformat/blockautoformateditingblockAutoformatEditing} and {@link module:autoformat/inlineautoformatediting~inlineAutoformatEditing} tools to create the autoformatters mentioned above.

You can use these tools to create your own autoformatters. Check the Autoformat feature's code as an example.

Known issues

While the autoformatting feature is stable and ready to use, some issues were reported for it. Feel free to upvote 👍  them on GitHub if they are important for you:

  • Pasting Markdown-formatted content does not automatically convert the pasted syntax markers into properly formatted content. GitHub issues: #2321, #2322.
  • Setting a specific code block language is not supported yet (it defaults to plain text on insertion). GitHub issue: #8598.

Related features

In addition to enabling automatic text formatting, you may want to check the following productivity features:

  • {@link features/text-transformation Automatic text transformation} – Enables automatic turning of snippets such as (tm) into and "foo" into “foo”.
  • {@link features/link#autolink-feature Autolink} – Turns the links and email addresses typed or pasted into the editor into active URLs.
  • {@link features/mentions Mentions} – Brings support for smart autocompletion.
  • {@link features/slash-commands Slash commands} – Allows to execute a predefined command by writing its name or alias directly in the editor.
  • {@link features/markdown Markdown output} – Lets the user output the content as Markdown instead of HTML and use CKEditor 5 as a WYSIWYG Markdown editor.
  • {@link features/source-editing#markdown-source-view Source editing} – Allows for Markdown source edition if configured accordingly.

Coupled with the {@link features/markdown Markdown output} feature, the autoformatting feature 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.

Contribute

The source code of the feature is available on GitHub at https://github.com/ckeditor/ckeditor5/tree/master/packages/ckeditor5-autoformat.