# @codemirror/lang-markdown [![NPM version](https://img.shields.io/npm/v/@codemirror/lang-markdown.svg)](https://www.npmjs.org/package/@codemirror/lang-markdown)

[ [**WEBSITE**](https://codemirror.net/) | [**ISSUES**](https://github.com/codemirror/dev/issues) | [**FORUM**](https://discuss.codemirror.net/c/next/) | [**CHANGELOG**](https://github.com/codemirror/lang-markdown/blob/main/CHANGELOG.md) ]

This package implements Markdown language support for the
[CodeMirror](https://codemirror.net/) code editor.

The [project page](https://codemirror.net/) has more information, a
number of [examples](https://codemirror.net/examples/) and the
[documentation](https://codemirror.net/docs/).

This code is released under an
[MIT license](https://github.com/codemirror/lang-markdown/tree/main/LICENSE).

We aim to be an inclusive, welcoming community. To make that explicit,
we have a [code of
conduct](http://contributor-covenant.org/version/1/1/0/) that applies
to communication around the project.

## Usage

```javascript
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 (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object) = {}) → LanguageSupport (https://codemirror.net/docs/ref#language.LanguageSupport)

Markdown language support.

  config

  defaultCodeLanguage⁠?: Language (https://codemirror.net/docs/ref#language.Language) | LanguageSupport (https://codemirror.net/docs/ref#language.LanguageSupport)

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

  codeLanguages⁠?: readonly LanguageDescription (https://codemirror.net/docs/ref#language.LanguageDescription)[] | fn(info: string (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)) → Language (https://codemirror.net/docs/ref#language.Language) | LanguageDescription (https://codemirror.net/docs/ref#language.LanguageDescription) | null (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/null)

A source of language support for highlighting fenced code
blocks. When it is an array, the parser will use
LanguageDescription.matchLanguageName (https://codemirror.net/docs/ref/#language.LanguageDescription%5EmatchLanguageName)
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 (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)

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

  extensions⁠?: MarkdownExtension (https://github.com/lezer-parser/markdown#user-content-markdownextension)

Markdown parser
extensions (https://github.com/lezer-parser/markdown#user-content-markdownextension)
to add to the parser.

  base⁠?: Language (https://codemirror.net/docs/ref#language.Language)

The base language to use. Defaults to
commonmarkLanguage.

  completeHTMLTags⁠?: boolean (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)

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

  pasteURLAsLink⁠?: boolean (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)

The returned language contains
pasteURLAsLink as a support
extension unless you set this to false.

  htmlTagLanguage⁠?: LanguageSupport (https://codemirror.net/docs/ref#language.LanguageSupport)

By default, HTML tags in the document are handled by the HTML
language (https://github.com/codemirror/lang-html) package with
tag matching turned off. You can pass in an alternative language
configuration here if you want.

  markdownLanguage: Language (https://codemirror.net/docs/ref#language.Language)

Language support for GFM (https://github.github.com/gfm/) plus
subscript, superscript, and emoji syntax.

  commonmarkLanguage: Language (https://codemirror.net/docs/ref#language.Language)

Language support for strict CommonMark.

  insertNewlineContinueMarkup: StateCommand (https://codemirror.net/docs/ref#state.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).

  insertNewlineContinueMarkupCommand(config⁠?: Object (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object) = {}) → StateCommand (https://codemirror.net/docs/ref#state.StateCommand)

Returns a command like
insertNewlineContinueMarkup,
allowing further configuration.

  config

  nonTightLists⁠?: boolean (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)

By default, when pressing enter in a blank second item in a
tight (no blank lines between items) list, the command will
insert a blank line above that item, starting a non-tight list.
Set this to false to disable this behavior.

  deleteMarkupBackward: StateCommand (https://codemirror.net/docs/ref#state.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 (https://codemirror.net/docs/ref#view.KeyBinding)[]

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

  pasteURLAsLink: Extension (https://codemirror.net/docs/ref#state.Extension)

An extension that intercepts pastes when the pasted content looks
like a URL and the selection is non-empty and selects regular
text, making the selection a link with the pasted URL as target.

