• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

ProseMirror/prosemirror-markdown: ProseMirror Markdown integration

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

ProseMirror/prosemirror-markdown

开源软件地址(OpenSource Url):

https://github.com/ProseMirror/prosemirror-markdown

开源编程语言(OpenSource Language):

TypeScript 100.0%

开源软件介绍(OpenSource Introduction):

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
    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(schema: Schema, tokenizer: any, tokens: Object)
    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
    The value of the tokens object used to construct this parser. Can be useful to copy and modify to base other parsers on.

  • parse(text: string) → any
    Parse a string as CommonMark markup, and create a ProseMirror document as prescribed by this parser's rules.

  • 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(nodes: Object, marks: 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?: 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.
  • nodes: Object
    The node serializer functions for this serializer.

  • marks: 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(content: Node, options?: Object = {}) → string
    Serialize the content of the given node to CommonMark.

    • options?: Object

      • 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}

  • wrapBlock(delim: string, firstDelim: string, node: Node, f: fn())
    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(node: Node)
    Close the block for the given node.

  • text(text: string, escape?: boolean = true)
    Add the given text to the document. When escape is not false, it will be escaped.

  • render(node: Node, parent: Node, index: number)
    Render the given node as a block.

  • renderContent(parent: Node)
    Render the contents of parent as block nodes.

  • renderInline(parent: Node)
    Render the contents of parent as inline content.

  • renderList(node: Node, delim: string, firstDelim: fn(index: number) → 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(str: string, 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(str: string, n: number) → string
    Repeat the given string n times.

  • markString(mark: Mark, open: boolean, parent: Node, index: number) → string
    Get the markdown string for a given opening or closing mark.

  • getEnclosingWhitespace(text: string) → {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.




鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap