prosemirror-remark v0.6.1
prosemirror-remark
This package provides support for using the remark Markdown parser with the ProseMirror editor. prosemirror-remark builds on the prosemirror-unified package and offers a configurable and extensible way of adding Markdown support to ProseMirror.
Quickstart
import { MarkdownExtension } from "prosemirror-remark";
import { EditorState } from "prosemirror-state";
import { ProseMirrorUnified } from "prosemirror-unified";
import { EditorView } from "prosemirror-view";
const sourceMarkdown = "**Bold text**";
const pmu = new ProseMirrorUnified([new MarkdownExtension()]);
const view = new EditorView(
// The element to use for the editor
document.querySelector("#editor")!,
{
state: EditorState.create({
// Set the initial content of the editor from sourceMarkdown
doc: pmu.parse(sourceMarkdown),
plugins: [pmu.inputRulesPlugin(), pmu.keymapPlugin()],
schema: pmu.schema(),
}),
// Log (in the browser console) the current content in markdown on every update
dispatchTransaction: (tr): void => {
view.updateState(view.state.apply(tr));
console.log(pmu.serialize(view.state.doc));
},
}
);The example above shows how to use the MarkdownExtension provided by prosemirror-remark to add support for CommonMark markdown.
Manual configuration
If you want finer-grained control over how Markdown is processed and viewed, instead of using MarkdownExtension, you can add individual syntax extensions that support particular parts of the Markdown spec:
BlockquoteExtensionprovides support for> Block quotesBoldExtensionprovides support for**bold text**BreakExtensionprovides support forhard breaks at the end of a line\CodeBlockExtensionprovides support for code blocks like``` this ```DefinitionExtensionprovides support for definitions for reference-style images and links. It is auto-included withImageReferenceExtensionandLinkReferenceExtension.HeadingExtensionprovides support for## HeadingsHorizontalRuleExtensionprovides support for horizontal dividers like this:---ImageExtensionprovides support for imagesImageReferenceExtensionprovides support for reference style images with the address later in the document like![Awesome image][imageId]InlineCodeExtensionprovides support for`inline code snippets`ItalicExtensionprovides support for*italic text*LinkExtensionprovides support for[links](https://example.test)LinkReferenceExtensionprovides support for reference style links with the address later in the document like[Click me!](linkId)ListItemExtensionprovides support for individual items in both ordered and unordered lists. It is auto-included withOrderedListExtensionandUnorderedListExtension.OrderedListExtensionprovides support for1. ordered listsParagraphExtensionprovides support for basic paragraphs in textRootExtensionprovides support for the root node of the document. You need to include this.TextExtensionprovides support for text. You need to include this.UnorderedListExtensionprovides support for- unordered lists
Additionally, you can also augment prosemirror-remark by creating your own extensions - see the prosemirror-unified documentation for more details
GitHub flavored markdown
On top of the standard CommonMark version of markdown, prosemirror-remark can also be used to add support for GitHub flavored markdown (GFM). In order to do this, simply replace MarkdownExtension with GFMExtension. GFMExtension automatically includes standard markdown, as well as the following extensions (which can also be added manually one-by-one):
ExtendedLinkExtensionprovides support for automatic conversions of addresses starting withwww.to links.StrikethroughExtensionprovides support for~~text with strikethrough~~TaskListItemExtensionprovides support for- [ ] Task list items
Note that tables are currently not supported.