0.0.3 • Published 11 months ago
@ast-exp/markdown v0.0.3
Markdown Parser
Parse your Markdown code.
Installation
npm install @ast-exp/markdown
Usage
import parser from '@ast-exp/markdown'
const ast = parser('Your Markdown code')
API Reference
Node
type Node = Program | Paragraph | Heading | CodeBlock | BlockQuote | List | ListItem | Table
NodeType
enum NodeType {
Program = 'PROGRAM',
Paragraph = 'PARAGRAPH',
Heading = 'HEADING',
CodeBlock = 'CODE_BLOCK',
BlockQuote = 'BLOCK_QUOTE',
List = 'LIST',
ListItem = 'LIST_ITEM',
Table = 'TABLE',
}
Program
type Program = {
type: NodeType.Program
children: Node[]
}
Paragraph
type Paragraph = {
type: NodeType.Paragraph
children: Inline[]
}
Heading
type Heading = {
type: NodeType.Heading
level: 1 | 2 | 3 | 4 | 5 | 6
children: Inline[]
}
CodeBlock
type CodeBlock = {
type: NodeType.CodeBlock
value: string
language?: string
meta?: string
}
BlockQuote
type BlockQuote = {
type: NodeType.BlockQuote
children: Node[]
}
List
type List = {
type: NodeType.List
ordered: boolean
children: Node[]
}
ListItem
type ListItem = {
type: NodeType.ListItem
checked: null | string
children: Node[]
}
Table
type Table = {
type: NodeType.Table
header: Inline[][]
rows: Inline[][][]
alignment?: ('left' | 'center' | 'right' | undefined)[]
}
Inline
type Inline = Text | Code | Strong | Emphasis | Link | Image
InlineType
enum InlineType {
Text = 'TEXT',
Code = 'CODE',
Strong = 'STRONG',
Emphasis = 'EMPHASIS',
Link = 'LINK',
Image = 'IMAGE',
}
Text
type Text = {
type: InlineType.Text
value: string
}
Code
type Code = {
type: InlineType.Code
value: string
}
Strong
type Strong = {
type: InlineType.Strong
children: Inline[]
}
Emphasis
type Emphasis = {
type: InlineType.Emphasis
children: Inline[]
}
Link
type Link = {
type: InlineType.Link
children: Inline[]
url: string
}
Image
type Image = {
type: InlineType.Image
alt: string
url: string
}