prosemirror-markdown
ProseMirror Markdown integration
Last updated 3 years ago by marijn .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install prosemirror-markdown 
SYNC missed versions from official npm registry.

prosemirror-markdown

[ WEBSITE | ISSUES | FORUM | GITTER ]

This is a (non-core) module for ProseMirror. ProseMirror is a well-behaved rich semantic content editor based on contentEditable, with support for collaborative editing and custom document schemas.

This module implements a ProseMirror schema that corresponds to the document schema used by CommonMark, and a parser and serializer to convert between ProseMirror documents in that schema and CommonMark/Markdown text.

This code is released under an MIT license. There's a forum for general discussion and support requests, and the Github bug tracker is the place to report issues.

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.

Documentation

schema: Schema<"doc" | "paragraph" | "blockquote" | "horizontal_rule" | "heading" | "code_block" | "ordered_list" | "bullet_list" | "list_item" | "text" | "image" | "hard_break", "em" | "strong" | "link" | "code">

Document schema for the data model used by CommonMark.

class MarkdownParser

A configuration of a Markdown parser. Such a parser uses markdown-it to tokenize a file, and then runs the custom rules it is given over the tokens to create a ProseMirror document tree.

new MarkdownParser(schemaSchema, tokenizerany, tokensObject<ParseSpec>)

Create a parser with the given configuration. You can configure the markdown-it parser to parse the dialect you want, and provide a description of the ProseMirror entities those tokens map to in the tokens object, which maps token names to descriptions of what to do with them. Such a description is an object, and may have the following properties:

schema: Schema

The parser's document schema.

tokenizer: any

This parser's markdown-it tokenizer.

tokens: Object<ParseSpec>

The value of the tokens object used to construct this parser. Can be useful to copy and modify to base other parsers on.

parse(textstring) → any

Parse a string as CommonMark markup, and create a ProseMirror document as prescribed by this parser's rules.

interface ParseSpec

Object type used to specify how Markdown tokens should be parsed.

node⁠?: string

This token maps to a single node, whose type can be looked up in the schema under the given name. Exactly one of node, block, or mark must be set.

block⁠?: string

This token (unless noCloseToken is true) comes in _open and _close variants (which are appended to the base token name provides a the object property), and wraps a block of content. The block should be wrapped in a node of the type named to by the property's value. If the token does not have _open or _close, use the noCloseToken option.

mark⁠?: string

This token (again, unless noCloseToken is true) also comes in _open and _close variants, but should add a mark (named by the value) to its content, rather than wrapping it in a node.

attrs⁠?: Attrs

Attributes for the node or mark. When getAttrs is provided, it takes precedence.

getAttrs⁠?: fn(tokenany, tokenStreamany[], indexnumber) → Attrs

A function used to compute the attributes for the node or mark that takes a markdown-it token and returns an attribute object.

noCloseToken⁠?: boolean

Indicates that the markdown-it token has no _open or _close for the nodes. This defaults to true for code_inline, code_block and fence.

ignore⁠?: boolean

When true, ignore content for the matched token.

defaultMarkdownParser: MarkdownParser

A parser parsing unextended CommonMark, without inline HTML, and producing a document in the basic schema.

class MarkdownSerializer

A specification for serializing a ProseMirror document as Markdown/CommonMark text.

new MarkdownSerializer(nodesObject<fn(stateMarkdownSerializerState, nodeNode, parentNode, indexnumber)>, marksObject<Object>, options⁠?: Object = {})

Construct a serializer with the given configuration. The nodes object should map node names in a given schema to function that take a serializer state and such a node, and serialize the node.

options
escapeExtraCharacters⁠?: RegExp

Extra characters can be added for escaping. This is passed directly to String.replace(), and the matching characters are preceded by a backslash.

nodes: Object<fn(stateMarkdownSerializerState, nodeNode, parentNode, indexnumber)>

The node serializer functions for this serializer.

marks: Object<Object>

The mark serializer info.

options: Object
escapeExtraCharacters⁠?: RegExp

Extra characters can be added for escaping. This is passed directly to String.replace(), and the matching characters are preceded by a backslash.

serialize(contentNode, options⁠?: Object = {}) → string

Serialize the content of the given node to CommonMark.

options
tightLists⁠?: boolean

Whether to render lists in a tight style. This can be overridden on a node level by specifying a tight attribute on the node. Defaults to false.

class MarkdownSerializerState

This is an object used to track state and expose methods related to markdown serialization. Instances are passed to node and mark serialization methods (see toMarkdown).

options: {tightLists⁠?: boolean, escapeExtraCharacters⁠?: RegExp}

The options passed to the serializer.

wrapBlock(delimstring, firstDelimstring, nodeNode, ffn())

Render a block, prefixing each line with delim, and the first line in firstDelim. node should be the node that is closed at the end of the block, and f is a function that renders the content of the block.

ensureNewLine()

Ensure the current content ends with a newline.

write(content⁠?: string)

Prepare the state for writing output (closing closed paragraphs, adding delimiters, and so on), and then optionally add content (unescaped) to the output.

closeBlock(nodeNode)

Close the block for the given node.

text(textstring, escape⁠?: boolean = true)

Add the given text to the document. When escape is not false, it will be escaped.

render(nodeNode, parentNode, indexnumber)

Render the given node as a block.

renderContent(parentNode)

Render the contents of parent as block nodes.

renderInline(parentNode)

Render the contents of parent as inline content.

renderList(nodeNode, delimstring, firstDelimfn(indexnumber) → string)

Render a node's content as a list. delim should be the extra indentation added to all lines except the first in an item, firstDelim is a function going from an item index to a delimiter for the first line of the item.

esc(strstring, startOfLine⁠?: boolean = false) → string

Escape the given string so that it can safely appear in Markdown content. If startOfLine is true, also escape characters that have special meaning only at the start of the line.

repeat(strstring, nnumber) → string

Repeat the given string n times.

markString(markMark, openboolean, parentNode, indexnumber) → string

Get the markdown string for a given opening or closing mark.

getEnclosingWhitespace(textstring) → {leading⁠?: string, trailing⁠?: string}

Get leading and trailing whitespace from a string. Values of leading or trailing property of the return object will be undefined if there is no match.

defaultMarkdownSerializer: MarkdownSerializer

A serializer for the basic schema.

Current Tags

  • 1.9.0-beta.1                                ...           beta (2 years ago)
  • 1.13.0                                ...           latest (6 months ago)

56 Versions

  • 1.13.0                                ...           6 months ago
  • 1.12.0                                ...           a year ago
  • 1.11.2                                ...           a year ago
  • 1.11.1                                ...           a year ago
  • 1.11.0                                ...           a year ago
  • 1.10.1                                ...           2 years ago
  • 1.10.0                                ...           2 years ago
  • 1.9.4                                ...           2 years ago
  • 1.9.3                                ...           2 years ago
  • 1.9.2                                ...           2 years ago
  • 1.9.1                                ...           2 years ago
  • 1.9.0                                ...           2 years ago
  • 1.9.0-beta.1                                ...           2 years ago
  • 1.8.0                                ...           3 years ago
  • 1.7.1                                ...           3 years ago
  • 1.7.0                                ...           3 years ago
  • 1.6.2                                ...           3 years ago
  • 1.6.1                                ...           3 years ago
  • 1.6.0                                ...           3 years ago
  • 1.5.2                                ...           3 years ago
  • 1.5.1                                ...           4 years ago
  • 1.5.0                                ...           4 years ago
  • 1.4.5                                ...           5 years ago
  • 1.4.4                                ...           5 years ago
  • 1.4.3                                ...           5 years ago
  • 1.4.2                                ...           5 years ago
  • 1.4.1                                ...           5 years ago
  • 1.4.0                                ...           5 years ago
  • 1.3.2                                ...           5 years ago
  • 1.3.1                                ...           5 years ago
  • 1.3.0                                ...           6 years ago
  • 1.2.2                                ...           6 years ago
  • 1.2.1                                ...           6 years ago
  • 1.2.0                                ...           6 years ago
  • 1.1.1                                ...           6 years ago
  • 1.1.0                                ...           6 years ago
  • 1.0.4                                ...           7 years ago
  • 1.0.3                                ...           7 years ago
  • 1.0.2                                ...           7 years ago
  • 1.0.1                                ...           7 years ago
  • 1.0.0                                ...           7 years ago
  • 0.24.0                                ...           7 years ago
  • 0.23.0                                ...           7 years ago
  • 0.22.0                                ...           7 years ago
  • 0.21.0                                ...           8 years ago
  • 0.20.0                                ...           8 years ago
  • 0.19.0                                ...           8 years ago
  • 0.18.0                                ...           8 years ago
  • 0.17.0                                ...           8 years ago
  • 0.16.0                                ...           8 years ago
  • 0.15.0                                ...           8 years ago
  • 0.14.0                                ...           8 years ago
  • 0.13.0                                ...           8 years ago
  • 0.12.0                                ...           8 years ago
  • 0.11.1                                ...           8 years ago
  • 0.11.0                                ...           8 years ago
Maintainers (1)
Downloads
Total 3
Today 1
This Week 1
This Month 1
Last Day 0
Last Week 0
Last Month 1
Dependencies (2)
Dev Dependencies (7)
Dependents (1)

© 2010 - cnpmjs.org x YWFE | Home | YWFE