v2.0.1

AST 節點

最後更新


Parse() 回傳的 AST 是 BlockNode 陣列(繼承 Array),本頁列出每種節點的欄位與對應語法。

區塊節點(BlockNode)


type欄位對應語法
textchildren: InlineNode[]一般段落;相鄰行以值為 "\n" 的 text 節點連接
headinglevel、children#~######、Setext
blockquotetag?、children: BlockNode[]>;tag 為 note/tip/important/warning/caution
listordered、children: ListItem[]-、*、1.
tablealign、children: TableRow[]GFM 表格;align 每欄為 left/center/right/null
codeBlocklang?、value```/~~~ 圍欄;未閉合時沒有 lang
htmlvalue以 HTML 標籤開頭的行(原文,輸出時才清洗)
hr—水平線
break—空行
footnoteschildren: Footnote[]文末註腳區

行內節點(InlineNode)


type欄位對應語法
textvalue純文字
b、em、del、mark、sub、supchildren粗體、斜體、刪除線、標記、下標、上標
codevalue行內程式碼
mathvalue$...$
linkhref、tag?、title?、width?、height?、children連結、圖片、影片、裸網址、檔案路徑;tag 為 image/video/youtube/vimeo/file
footnoteRefid、index[^id],index 為編號

子節點


型別欄位
ListItemtype: "listItem"、checked?(任務清單)、children: BlockNode[]
TableRowtype: "tableRow"、header、children: TableCell[]
TableCelltype: "tableCell"、children: InlineNode[]
Footnotetype: "footnote"、id、index、children: BlockNode[]

html() 掛在 AST 的 prototype 上,JSON.stringify(ast) 只會輸出節點,可直接交給其他平台的渲染器。型別定義隨套件發佈於 dist/types/types.d.ts。
  1. <script>
  2. const ast = MDParser.Parse("## Hi\n\n- [x] done\n\nE = $mc^2$ [link](https://nanomd.pardn.io)");
  3. console.log(JSON.stringify(ast, null, 2));
  4. </script>
即時預覽 · @pardnchiu/nanomd@2.0.1
EN