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

syntax-tree/mdast: Markdown Abstract Syntax Tree format

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

开源软件名称(OpenSource Name):

syntax-tree/mdast

开源软件地址(OpenSource Url):

https://github.com/syntax-tree/mdast

开源编程语言(OpenSource Language):


开源软件介绍(OpenSource Introduction):

mdast

Markdown Abstract Syntax Tree.


mdast is a specification for representing markdown in a syntax tree. It implements unist. It can represent several flavours of markdown, such as CommonMark and GitHub Flavored Markdown.

This document may not be released. See releases for released documents. The latest released version is 4.0.0.

Contents

Introduction

This document defines a format for representing markdown as an abstract syntax tree. Development of mdast started in July 2014, in remark, before unist existed. This specification is written in a Web IDL-like grammar.

Where this specification fits

mdast extends unist, a format for syntax trees, to benefit from its ecosystem of utilities.

mdast relates to JavaScript in that it has a rich ecosystem of utilities for working with compliant syntax trees in JavaScript. However, mdast is not limited to JavaScript and can be used in other programming languages.

mdast relates to the unified and remark projects in that mdast syntax trees are used throughout their ecosystems.

Nodes

Parent

interface Parent <: UnistParent {
  children: [MdastContent]
}

Parent (UnistParent) represents an abstract interface in mdast containing other nodes (said to be children).

Its content is limited to only other mdast content.

Literal

interface Literal <: UnistLiteral {
  value: string
}

Literal (UnistLiteral) represents an abstract interface in mdast containing a value.

Its value field is a string.

Root

interface Root <: Parent {
  type: "root"
}

Root (Parent) represents a document.

Root can be used as the root of a tree, never as a child. Its content model is not limited to flow content, but instead can contain any mdast content with the restriction that all content must be of the same category.

Paragraph

interface Paragraph <: Parent {
  type: "paragraph"
  children: [PhrasingContent]
}

Paragraph (Parent) represents a unit of discourse dealing with a particular point or idea.

Paragraph can be used where content is expected. Its content model is phrasing content.

For example, the following markdown:

Alpha bravo charlie.

Yields:

{
  type: 'paragraph',
  children: [{type: 'text', value: 'Alpha bravo charlie.'}]
}

Heading

interface Heading <: Parent {
  type: "heading"
  depth: 1 <= number <= 6
  children: [PhrasingContent]
}

Heading (Parent) represents a heading of a section.

Heading can be used where flow content is expected. Its content model is phrasing content.

A depth field must be present. A value of 1 is said to be the highest rank and 6 the lowest.

For example, the following markdown:

# Alpha

Yields:

{
  type: 'heading',
  depth: 1,
  children: [{type: 'text', value: 'Alpha'}]
}

ThematicBreak

interface ThematicBreak <: Node {
  type: "thematicBreak"
}

ThematicBreak (Node) represents a thematic break, such as a scene change in a story, a transition to another topic, or a new document.

ThematicBreak can be used where flow content is expected. It has no content model.

For example, the following markdown:

***

Yields:

{type: 'thematicBreak'}

Blockquote

interface Blockquote <: Parent {
  type: "blockquote"
  children: [FlowContent]
}

Blockquote (Parent) represents a section quoted from somewhere else.

Blockquote can be used where flow content is expected. Its content model is also flow content.

For example, the following markdown:

> Alpha bravo charlie.

Yields:

{
  type: 'blockquote',
  children: [{
    type: 'paragraph',
    children: [{type: 'text', value: 'Alpha bravo charlie.'}]
  }]
}

List

interface List <: Parent {
  type: "list"
  ordered: boolean?
  start: number?
  spread: boolean?
  children: [ListContent]
}

List (Parent) represents a list of items.

List can be used where flow content is expected. Its content model is list content.

An ordered field can be present. It represents that the items have been intentionally ordered (when true), or that the order of items is not important (when false or not present).

A start field can be present. It represents, when the ordered field is true, the starting number of the list.

A spread field can be present. It represents that one or more of its children are separated with a blank line from its siblings (when true), or not (when false or not present).

For example, the following markdown:

1. foo

Yields:

{
  type: 'list',
  ordered: true,
  start: 1,
  spread: false,
  children: [{
    type: 'listItem',
    spread: false,
    children: [{
      type: 'paragraph',
      children: [{type: 'text', value: 'foo'}]
    }]
  }]
}

ListItem

interface ListItem <: Parent {
  type: "listItem"
  spread: boolean?
  children: [FlowContent]
}

ListItem (Parent) represents an item in a List.

ListItem can be used where list content is expected. Its content model is flow content.

A spread field can be present. It represents that the item contains two or more children separated by a blank line (when true), or not (when false or not present).

For example, the following markdown:

* bar

Yields:

{
  type: 'listItem',
  spread: false,
  children: [{
    type: 'paragraph',
    children: [{type: 'text', value: 'bar'}]
  }]
}

HTML

interface HTML <: Literal {
  type: "html"
}

HTML (Literal) represents a fragment of raw HTML.

HTML can be used where flow or phrasing content is expected. Its content is represented by its value field.

HTML nodes do not have the restriction of being valid or complete HTML ([HTML]) constructs.

For example, the following markdown:

<div>

Yields:

{type: 'html', value: '<div>'}

Code

interface Code <: Literal {
  type: "code"
  lang: string?
  meta: string?
}

Code (Literal) represents a block of preformatted text, such as ASCII art or computer code.

Code can be used where flow content is expected. Its content is represented by its value field.

This node relates to the phrasing content concept InlineCode.

A lang field can be present. It represents the language of computer code being marked up.

If the lang field is present, a meta field can be present. It represents custom information relating to the node.

For example, the following markdown:

    foo()

Yields:

{
  type: 'code',
  lang: null,
  meta: null,
  value: 'foo()'
}

And the following markdown:

```js highlight-line="2"
foo()
bar()
baz()
```

Yields:

{
  type: 'code',
  lang: 'javascript',
  meta: 'highlight-line="2"',
  value: 'foo()\nbar()\nbaz()'
}

Definition

interface Definition <: Node {
  type: "definition"
}

Definition includes Association
Definition includes Resource

Definition (Node) represents a resource.

Definition can be used where content is expected. It has no content model.

Definition includes the mixins Association and Resource.

Definition should be associated with LinkReferences and ImageReferences.

For example, the following markdown:

[Alpha]: https://example.com

Yields:

{
  type: 'definition',
  identifier: 'alpha',
  label: 'Alpha',
  url: 'https://example.com',
  title: null
}

Text

interface Text <: Literal {
  type: "text"
}

Text (Literal) represents everything that is just text.

Text can be used where phrasing content is expected. Its content is represented by its value field.

For example, the following markdown:

Alpha bravo charlie.

Yields:

{type: 'text', value: 'Alpha bravo charlie.'}

Emphasis

interface Emphasis <: Parent {
  type: "emphasis"
  children: [TransparentContent]
}

Emphasis (Parent) represents stress emphasis of its contents.

Emphasis can be used where phrasing content is expected. Its content model is transparent content.

For example, the following markdown:

*alpha* _bravo_

Yields:

{
  type: 'paragraph',
  children: [
    {
      type: 'emphasis',
      children: [{type: 'text', value: 'alpha'}]
    },
    {type: 'text', value: ' '},
    {
      type: 'emphasis',
      children: [{type: 'text', value: 'bravo'}]
    }
  ]
}

Strong

interface Strong <: Parent {
  type: "strong"
  children: [TransparentContent]
}

Strong (Parent) represents strong importance, seriousness, or urgency for its contents.

Strong can be used where phrasing content is expected. Its content model is transparent content.

For example, the following markdown:

**alpha** __bravo__

Yields:

{
  type: 'paragraph',
  children: [
    {
      type: 'strong',
      children: [{type: 'text', value: 'alpha'}]
    },
    {type: 'text', value: ' '},
    {
      type: 'strong',
      children: [{type: 'text', value: 'bravo'}]
    }
  ]
}

InlineCode

interface InlineCode <: Literal {
  type: "inlineCode"
}

InlineCode (Literal) represents a fragment of computer code, such as a file name, computer program, or anything a computer could parse.

InlineCode can be used where phrasing content is expected. Its content is represented by its value field.

This node relates to the flow content concept Code.

For example, the following markdown:

`foo()`

Yields:

{type: 'inlineCode', value: 'foo()'}

Break

interface Break <: Node {
  type: "break"
}

Break (Node) represents a line break, such as in poems or addresses.

Break can be used where phrasing content is expected. It has no content model.

For example, the following markdown:

foo··
bar

Yields:

{
  type: 'paragraph',
  children: [
    {type: 'text', value: 'foo'},
    {type: 'break'},
    {type: 'text', value: 'bar'}
  ]
}

Link

interface Link <: Parent {
  type: "link"
  children: [StaticPhrasingContent]
}

Link includes Resource

Link (Parent) represents a hyperlink.

Link can be used where phrasing content is expected. Its content model is static phrasing content.

Link includes the mixin Resource.

For example, the following markdown:

[alpha](https://example.com "bravo")

Yields:

{
  type: 'link',
  url: 'https://example.com',
  title: 'bravo',
  children: [{type: 'text', value: 'alpha'}]
}

Image

interface Image <: Node {
  type: "image"
}

Image includes Resource
Image includes Alternative

Image (Node) represents an image.

Image can be used where phrasing content is expected. It has no content model, but is described by its alt field.

Image includes the mixins Resource and Alternative.

For example, the following markdown:

![alpha](https://example.com/favicon.ico "bravo")

Yields:

{
  type: 'image',
  url: 'https://example.com/favicon.ico',
  title: 'bravo',
  alt: 'alpha'
}

LinkReference

interface LinkReference <: Parent {
  type: "linkReference"
  children: [StaticPhrasingContent]
}

LinkReference includes Reference

LinkReference (Parent) represents a hyperlink through association, or its original source if there is no association.

LinkReference can be used where phrasing content is expected. Its content model is static phrasing content.

LinkReference includes the mixin Reference.

LinkReferences should be associated with a Definition.

For example, the following markdown:

[alpha][Bravo]

Yields:

{
  type: 'linkReference',
  identifier: 'bravo',
  label: 'Bravo',
  referenceType: 'full',
  children: [{type: 'text', value: 'alpha'}]
}

ImageReference

interface ImageReference <: Node {
  type: "imageReference"
}

ImageReference includes Reference
ImageReference includes Alternative

ImageReference (Node) represents an image through association, or its original source if there is no association.

ImageReference can be used where phrasing content is expected. It has no content model, but is described by its alt field.

ImageReference includes the mixins Reference and Alternative.

ImageReference should be associated with a Definition.

For example, the following markdown:

![alpha][bravo]

Yields:

{
  type: 'imageReference',
  identifier: 'bravo',
  label:  

鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
fabe/gatsby-starter-deck: 发布时间:2022-08-18
下一篇:
kates/html2markdown: Converts HTML to Markdown发布时间:2022-08-18
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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