Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@codemirror/lang-markdown

codemirror893.2kMIT6.3.2TypeScript support: included

Markdown language support for the CodeMirror code editor

editor, code

readme

@codemirror/lang-markdown NPM version

[ WEBSITE | ISSUES | FORUM | CHANGELOG ]

This package implements Markdown language support for the CodeMirror code editor.

The project page has more information, a number of examples and the documentation.

This code is released under an MIT license.

We aim to be an inclusive, welcoming community. To make that explicit, we have a code of conduct that applies to communication around the project.

Usage

import {EditorView, basicSetup} from "codemirror"
import {markdown} from "@codemirror/lang-markdown"

const view = new EditorView({
  parent: document.body,
  doc: `*CodeMirror* Markdown \`mode\``,
  extensions: [basicSetup, markdown()]
})

API Reference

markdown(config⁠?: Object = {}) → LanguageSupport

Markdown language support.

config
defaultCodeLanguage⁠?: Language | LanguageSupport

When given, this language will be used by default to parse code blocks.

codeLanguages⁠?: readonly LanguageDescription[] | fn(info: string) → Language | LanguageDescription | null

A source of language support for highlighting fenced code blocks. When it is an array, the parser will use LanguageDescription.matchLanguageName with the fenced code info to find a matching language. When it is a function, will be called with the info string and may return a language or LanguageDescription object.

addKeymap⁠?: boolean

Set this to false to disable installation of the Markdown keymap.

extensions⁠?: MarkdownExtension

Markdown parser extensions to add to the parser.

base⁠?: Language

The base language to use. Defaults to commonmarkLanguage.

completeHTMLTags⁠?: boolean

By default, the extension installs an autocompletion source that completes HTML tags when a < is typed. Set this to false to disable this.

htmlTagLanguage⁠?: LanguageSupport

By default, HTML tags in the document are handled by the HTML language package with tag matching turned off. You can pass in an alternative language configuration here if you want.

markdownLanguage: Language

Language support for GFM plus subscript, superscript, and emoji syntax.

commonmarkLanguage: Language

Language support for strict CommonMark.

insertNewlineContinueMarkup: StateCommand

This command, when invoked in Markdown context with cursor selection(s), will create a new line with the markup for blockquotes and lists that were active on the old line. If the cursor was directly after the end of the markup for the old line, trailing whitespace and list markers are removed from that line.

The command does nothing in non-Markdown context, so it should not be used as the only binding for Enter (even in a Markdown document, HTML and code regions might use a different language).

deleteMarkupBackward: StateCommand

This command will, when invoked in a Markdown context with the cursor directly after list or blockquote markup, delete one level of markup. When the markup is for a list, it will be replaced by spaces on the first invocation (a further invocation will delete the spaces), to make it easy to continue a list.

When not after Markdown block markup, this command will return false, so it is intended to be bound alongside other deletion commands, with a higher precedence than the more generic commands.

markdownKeymap: readonly KeyBinding[]

A small keymap with Markdown-specific bindings. Binds Enter to insertNewlineContinueMarkup and Backspace to deleteMarkupBackward.

changelog

6.3.2 (2025-01-09)

Bug fixes

Make Markdown-specific commands return false inside fenced code.

Fix an infinite loop caused by insertNewlineContinueMarkup.

6.3.1 (2024-11-06)

Bug fixes

Fix an issue where insertNewlineContinueMarkup didn't work with the cursor directly after an HTML tag.

6.3.0 (2024-09-28)

New features

The new htmlTagLanguage option allows client code to configure which language is used to parse HTML tags in the document.

6.2.5 (2024-04-12)

Bug fixes

Disable folding for list nodes (since it will shadow the folding on the first list item).

6.2.4 (2024-01-16)

Bug fixes

Starting at the third list item, insertNewlineContinueMarkup will now keep the tightness of the list, and only require two presses to clear an empty list item.

6.2.3 (2023-11-27)

Bug fixes

Support code folding for GFM tables.

6.2.2 (2023-10-06)

Bug fixes

Fix a bug in insertNewlineContinueMarkup that caused it to put the cursor in the wrong place when the editor's line break was more than one character long.

6.2.1 (2023-09-14)

Bug fixes

Make insertNewlineContinueMarkup and deleteMarkupBackward use tabs for indentation when appropriate.

6.2.0 (2023-06-23)

New features

The markdown package now installs a completion source that completes HTML tags when in Markdown context.

6.1.1 (2023-04-13)

Bug fixes

Fix the declaration of comentTokens language data for Markdown.

Fix a bug in deleteMarkupBackward that would cause it to delete pieces of continued paragraphs below list item markers.

6.1.0 (2023-02-17)

New features

Add support for folding entire sections from the header.

6.0.5 (2022-11-10)

Bug fixes

Make sure task lists are indented correctly even when deeply nested.

6.0.4 (2022-11-02)

Bug fixes

Fix an issue where nested task lists were indented too deeply.

6.0.3 (2022-10-24)

Bug fixes

Add a name value to the Markdown language object.

6.0.2 (2022-10-10)

Bug fixes

Improve insertNewlineContinueMarkup's behavior in a fenced code block.

6.0.1 (2022-07-25)

Bug fixes

Ignore text after whitespace in code block metadata, when determining which language the block is.

6.0.0 (2022-06-08)

Breaking changes

Update dependencies to 6.0.0

0.20.1 (2022-05-20)

New features

The codeLanguages option to markdown may now be a function from an info string to a language.

0.20.0 (2022-04-20)

New features

insertNewlineContinueMarkup can now continue task lists. Move highlighting information into @lezer/markdown

0.19.6 (2022-02-04)

Bug fixes

Fix an issue where deleteMarkupBackward could get confused when there was only whitespace between the cursor and the start of the line.

0.19.5 (2022-01-28)

Bug fixes

Make insertNewlineContinueMarkup exit blockquotes after two blank lines.

0.19.4 (2022-01-03)

Bug fixes

Fix a bug where list items after a removed item were incorrectly renumbered.

0.19.3 (2021-12-10)

Bug fixes

insertNewlineContinueMarkup will no longer exit lists when there is content after the cursor.

Fix an issue in deleteMarkupBackward where it only deleted a single space when after a number marker.

0.19.2 (2021-10-20)

Bug fixes

Fix a bug where the monospace highlighting tag wasn't correctly applied to code block content.

0.19.1 (2021-08-11)

Bug fixes

Fix incorrect versions for @lezer dependencies.

0.19.0 (2021-08-11)

Breaking changes

Update dependencies to 0.19.0

0.18.4 (2021-06-16)

Bug fixes

Fix a case where deleteMarkupBackward would return true without actually having an effect.

0.18.3 (2021-05-19)

Bug fixes

insertNewlineContinueMarkup will not continue moving list markers down when they are after an empty line anymore.

0.18.2 (2021-05-07)

Bug fixes

Fix a bug where insertNewlineContinueMarkup could duplicate bits of content when in dededented continued list items.

0.18.1 (2021-04-01)

Bug fixes

Add monospace style tag to all children of inline code nodes.

0.18.0 (2021-03-03)

Breaking changes

Update dependencies to 0.18.

0.17.3 (2021-02-22)

New features

Include heading depth in style tags.

0.17.2 (2021-02-10)

Bug fixes

Fix a bug where insertNewlineContinueMarkup would sometimes duplicate bits of content.

New features

The package now exports both a commonmarkLanguage, with just plain CommonMark, and a markdownLanguage, with GFM and some other extensions enabled.

It is now possible to pass lezer-markdown extensions to the markdown function to configure the parser.

0.17.1 (2021-01-06)

New features

The package now also exports a CommonJS module.

0.17.0 (2020-12-29)

Breaking changes

First numbered release.