7
7
** mdast** is a specification for representing markdown in a [ syntax
8
8
tree] [ syntax-tree ] .
9
9
It implements ** [ unist] [ ] ** .
10
- It can represent several flavours of [ markdown] [ ] , such as [ CommonMark ] [ ]
11
- and [ GitHub Flavored Markdown] [ gfm ] .
10
+ It can represent several flavours of [ markdown] [ ] ,
11
+ such as [ CommonMark ] [ ] and [ GitHub Flavored Markdown] [ gfm ] .
12
12
13
13
This document may not be released.
14
14
See [ releases] [ ] for released documents.
@@ -71,28 +71,31 @@ The latest released version is [`5.0.0`][latest].
71
71
72
72
This document defines a format for representing [ markdown] [ ] as an [ abstract
73
73
syntax tree] [ syntax-tree ] .
74
- Development of mdast started in July 2014, in ** [ remark] [ ] ** , before [ unist] [ ]
75
- existed.
74
+ Development of mdast started in July 2014,
75
+ in ** [ remark] [ ] ** ,
76
+ before [ unist] [ ] existed.
76
77
This specification is written in a [ Web IDL] [ webidl ] -like grammar.
77
78
78
79
### Where this specification fits
79
80
80
- mdast extends [ unist] [ ] , a format for syntax trees, to benefit from its
81
- [ ecosystem of utilities] [ utilities ] .
81
+ mdast extends [ unist] [ ] ,
82
+ a format for syntax trees,
83
+ to benefit from its [ ecosystem of utilities] [ utilities ] .
82
84
83
85
mdast relates to [ JavaScript] [ ] in that it has a rich [ ecosystem of
84
86
utilities] [ list-of-utilities ] for working with compliant syntax trees in
85
87
JavaScript.
86
- However, mdast is not limited to JavaScript and can be used in other programming
88
+ However,
89
+ mdast is not limited to JavaScript and can be used in other programming
87
90
languages.
88
91
89
92
mdast relates to the [ unified] [ ] and [ remark] [ ] projects in that mdast syntax
90
93
trees are used throughout their ecosystems.
91
94
92
95
## Types
93
96
94
- If you are using TypeScript, you can use the unist types by installing them
95
- with npm:
97
+ If you are using TypeScript,
98
+ you can use the unist types by installing them with npm:
96
99
97
100
``` sh
98
101
npm install @types/mdast
@@ -144,7 +147,8 @@ somewhere else.
144
147
expected.
145
148
Its content model is also [ ** flow** ] [ dfn-flow-content ] content.
146
149
147
- For example, the following markdown:
150
+ For example,
151
+ the following markdown:
148
152
149
153
``` markdown
150
154
> Alpha bravo charlie.
@@ -170,14 +174,15 @@ interface Break <: Node {
170
174
}
171
175
```
172
176
173
- ** Break** ([ ** Node** ] [ dfn-node ] ) represents a line break, such as in poems or
174
- addresses.
177
+ ** Break** ([ ** Node** ] [ dfn-node ] ) represents a line break,
178
+ such as in poems or addresses.
175
179
176
180
** Break** can be used where [ ** phrasing** ] [ dfn-phrasing-content ] content is
177
181
expected.
178
182
It has no content model.
179
183
180
- For example, the following markdown:
184
+ For example,
185
+ the following markdown:
181
186
182
187
``` markdown
183
188
foo··
@@ -219,10 +224,12 @@ This node relates to the [**phrasing**][dfn-phrasing-content] content concept
219
224
A ` lang ` field can be present.
220
225
It represents the language of computer code being marked up.
221
226
222
- If the ` lang ` field is present, a ` meta ` field can be present.
227
+ If the ` lang ` field is present,
228
+ a ` meta ` field can be present.
223
229
It represents custom information relating to the node.
224
230
225
- For example, the following markdown:
231
+ For example,
232
+ the following markdown:
226
233
227
234
``` markdown
228
235
foo()
@@ -283,7 +290,8 @@ It has no content model.
283
290
[ ** LinkReferences** ] [ dfn-link-reference ] and
284
291
[ ** ImageReferences** ] [ dfn-image-reference ] .
285
292
286
- For example, the following markdown:
293
+ For example,
294
+ the following markdown:
287
295
288
296
``` markdown
289
297
[Alpha]: https://example.com
@@ -317,7 +325,8 @@ contents.
317
325
expected.
318
326
Its content model is [ ** phrasing** ] [ dfn-phrasing-content ] content.
319
327
320
- For example, the following markdown:
328
+ For example,
329
+ the following markdown:
321
330
322
331
``` markdown
323
332
*alpha* _bravo_
@@ -360,7 +369,8 @@ Its content model is [**phrasing**][dfn-phrasing-content] content.
360
369
A ` depth ` field must be present.
361
370
A value of ` 1 ` is said to be the highest rank and ` 6 ` the lowest.
362
371
363
- For example, the following markdown:
372
+ For example,
373
+ the following markdown:
364
374
365
375
``` markdown
366
376
# Alpha
@@ -393,7 +403,8 @@ Its content is represented by its `value` field.
393
403
** Html** nodes do not have the restriction of being valid or complete HTML
394
404
([ \[ HTML\] ] [ html ] ) constructs.
395
405
396
- For example, the following markdown:
406
+ For example,
407
+ the following markdown:
397
408
398
409
``` markdown
399
410
<div>
@@ -420,12 +431,14 @@ Image includes Alternative
420
431
421
432
** Image** can be used where [ ** phrasing** ] [ dfn-phrasing-content ] content is
422
433
expected.
423
- It has no content model, but is described by its ` alt ` field.
434
+ It has no content model,
435
+ but is described by its ` alt ` field.
424
436
425
437
** Image** includes the mixins [ ** Resource** ] [ dfn-mxn-resource ] and
426
438
[ ** Alternative** ] [ dfn-mxn-alternative ] .
427
439
428
- For example, the following markdown:
440
+ For example,
441
+ the following markdown:
429
442
430
443
``` markdown
431
444

@@ -454,18 +467,21 @@ ImageReference includes Alternative
454
467
```
455
468
456
469
** ImageReference** ([ ** Node** ] [ dfn-node ] ) represents an image through
457
- association, or its original source if there is no association.
470
+ association,
471
+ or its original source if there is no association.
458
472
459
473
** ImageReference** can be used where [ ** phrasing** ] [ dfn-phrasing-content ]
460
474
content is expected.
461
- It has no content model, but is described by its ` alt ` field.
475
+ It has no content model,
476
+ but is described by its ` alt ` field.
462
477
463
478
** ImageReference** includes the mixins [ ** Reference** ] [ dfn-mxn-reference ] and
464
479
[ ** Alternative** ] [ dfn-mxn-alternative ] .
465
480
466
481
** ImageReference** should be associated with a [ ** Definition** ] [ dfn-definition ] .
467
482
468
- For example, the following markdown:
483
+ For example,
484
+ the following markdown:
469
485
470
486
``` markdown
471
487
![alpha][bravo]
@@ -492,7 +508,10 @@ interface InlineCode <: Literal {
492
508
```
493
509
494
510
** InlineCode** ([ ** Literal** ] [ dfn-literal ] ) represents a fragment of computer
495
- code, such as a file name, computer program, or anything a computer could parse.
511
+ code,
512
+ such as a file name,
513
+ computer program,
514
+ or anything a computer could parse.
496
515
497
516
** InlineCode** can be used where [ ** phrasing** ] [ dfn-phrasing-content ] content
498
517
is expected.
@@ -501,7 +520,8 @@ Its content is represented by its `value` field.
501
520
This node relates to the [ ** flow** ] [ dfn-flow-content ] content concept
502
521
[ ** Code** ] [ dfn-code ] .
503
522
504
- For example, the following markdown:
523
+ For example,
524
+ the following markdown:
505
525
506
526
``` markdown
507
527
`foo()`
@@ -532,7 +552,8 @@ Its content model is also [**phrasing**][dfn-phrasing-content] content.
532
552
533
553
** Link** includes the mixin [ ** Resource** ] [ dfn-mxn-resource ] .
534
554
535
- For example, the following markdown:
555
+ For example,
556
+ the following markdown:
536
557
537
558
``` markdown
538
559
[alpha](https://example.com "bravo")
@@ -561,7 +582,8 @@ LinkReference includes Reference
561
582
```
562
583
563
584
** LinkReference** ([ ** Parent** ] [ dfn-parent ] ) represents a hyperlink through
564
- association, or its original source if there is no association.
585
+ association,
586
+ or its original source if there is no association.
565
587
566
588
** LinkReference** can be used where [ ** phrasing** ] [ dfn-phrasing-content ] content
567
589
is expected.
@@ -571,7 +593,8 @@ Its content model is also [**phrasing**][dfn-phrasing-content] content.
571
593
572
594
** LinkReferences** should be associated with a [ ** Definition** ] [ dfn-definition ] .
573
595
574
- For example, the following markdown:
596
+ For example,
597
+ the following markdown:
575
598
576
599
``` markdown
577
600
[alpha][Bravo]
@@ -607,19 +630,21 @@ interface List <: Parent {
607
630
Its content model is [ ** list** ] [ dfn-list-content ] content.
608
631
609
632
An ` ordered ` field can be present.
610
- It represents that the items have been intentionally ordered (when ` true ` ), or
611
- that the order of items is not important (when ` false ` or not present).
633
+ It represents that the items have been intentionally ordered (when ` true ` ),
634
+ or that the order of items is not important (when ` false ` or not present).
612
635
613
636
A ` start ` field can be present.
614
- It represents, when the ` ordered ` field is ` true ` , the starting number of the
615
- list.
637
+ It represents,
638
+ when the ` ordered ` field is ` true ` ,
639
+ the starting number of the list.
616
640
617
641
A ` spread ` field can be present.
618
642
It represents that one or more of its children are separated with a blank line
619
- from its [ siblings] [ term-sibling ] (when ` true ` ), or not (when ` false ` or not
620
- present).
643
+ from its [ siblings] [ term-sibling ] (when ` true ` ),
644
+ or not (when ` false ` or not present).
621
645
622
- For example, the following markdown:
646
+ For example,
647
+ the following markdown:
623
648
624
649
``` markdown
625
650
1. foo
@@ -662,9 +687,11 @@ Its content model is [**flow**][dfn-flow-content] content.
662
687
663
688
A ` spread ` field can be present.
664
689
It represents that the item contains two or more [ * children* ] [ term-child ]
665
- separated by a blank line (when ` true ` ), or not (when ` false ` or not present).
690
+ separated by a blank line (when ` true ` ),
691
+ or not (when ` false ` or not present).
666
692
667
- For example, the following markdown:
693
+ For example,
694
+ the following markdown:
668
695
669
696
``` markdown
670
697
* bar
@@ -698,7 +725,8 @@ with a particular point or idea.
698
725
** Paragraph** can be used where [ ** content** ] [ dfn-content ] is expected.
699
726
Its content model is [ ** phrasing** ] [ dfn-phrasing-content ] content.
700
727
701
- For example, the following markdown:
728
+ For example,
729
+ the following markdown:
702
730
703
731
``` markdown
704
732
Alpha bravo charlie.
@@ -723,8 +751,8 @@ interface Root <: Parent {
723
751
724
752
** Root** ([ ** Parent** ] [ dfn-parent ] ) represents a document.
725
753
726
- ** Root** can be used as the [ * root* ] [ term-root ] of a [ * tree* ] [ term-tree ] , never
727
- as a [ * child* ] [ term-child ] .
754
+ ** Root** can be used as the [ * root* ] [ term-root ] of a [ * tree* ] [ term-tree ] ,
755
+ never as a [ * child* ] [ term-child ] .
728
756
Its content model is ** not** limited to [ ** flow** ] [ dfn-flow-content ] content,
729
757
but instead can contain any [ ** mdast content** ] [ dfn-mdast-content ] with the
730
758
restriction that all content must be of the same category.
@@ -738,14 +766,16 @@ interface Strong <: Parent {
738
766
}
739
767
```
740
768
741
- ** Strong** ([ ** Parent** ] [ dfn-parent ] ) represents strong importance, seriousness,
769
+ ** Strong** ([ ** Parent** ] [ dfn-parent ] ) represents strong importance,
770
+ seriousness,
742
771
or urgency for its contents.
743
772
744
773
** Strong** can be used where [ ** phrasing** ] [ dfn-phrasing-content ] content is
745
774
expected.
746
775
Its content model is [ ** phrasing** ] [ dfn-phrasing-content ] content.
747
776
748
- For example, the following markdown:
777
+ For example,
778
+ the following markdown:
749
779
750
780
``` markdown
751
781
**alpha** __bravo__
@@ -784,7 +814,8 @@ interface Text <: Literal {
784
814
expected.
785
815
Its content is represented by its ` value ` field.
786
816
787
- For example, the following markdown:
817
+ For example,
818
+ the following markdown:
788
819
789
820
``` markdown
790
821
Alpha bravo charlie.
@@ -804,14 +835,17 @@ interface ThematicBreak <: Node {
804
835
}
805
836
```
806
837
807
- ** ThematicBreak** ([ ** Node** ] [ dfn-node ] ) represents a thematic break, such as a
808
- scene change in a story, a transition to another topic, or a new document.
838
+ ** ThematicBreak** ([ ** Node** ] [ dfn-node ] ) represents a thematic break,
839
+ such as a scene change in a story,
840
+ a transition to another topic,
841
+ or a new document.
809
842
810
843
** ThematicBreak** can be used where [ ** flow** ] [ dfn-flow-content ] content is
811
844
expected.
812
845
It has no content model.
813
846
814
- For example, the following markdown:
847
+ For example,
848
+ the following markdown:
815
849
816
850
``` markdown
817
851
***
@@ -860,16 +894,18 @@ A `label` field can be present.
860
894
` label ` is a string value: it works just like ` title ` on a link or a ` lang ` on
861
895
code: character escapes and character references are parsed.
862
896
863
- To normalize a value, collapse markdown whitespace (` [\t\n\r ]+ ` ) to a space,
864
- trim the optional initial and/or final space, and perform case-folding.
897
+ To normalize a value,
898
+ collapse markdown whitespace (` [\t\n\r ]+ ` ) to a space,
899
+ trim the optional initial and/or final space,
900
+ and perform case-folding.
865
901
866
902
Whether the value of ` identifier ` (or normalized ` label ` if there is no
867
903
` identifier ` ) is expected to be a unique identifier or not depends on the type
868
904
of node including the ** Association** .
869
905
An example of this is that they should be unique on
870
- [ ** Definition** ] [ dfn-definition ] , whereas multiple
871
- [ ** LinkReference** ] [ dfn-link-reference ] s can be non-unique to be associated with
872
- one definition.
906
+ [ ** Definition** ] [ dfn-definition ] ,
907
+ whereas multiple [ ** LinkReference** ] [ dfn-link-reference ] s can be non-unique to
908
+ be associated with one definition.
873
909
874
910
### ` Reference `
875
911
@@ -903,8 +939,8 @@ A `url` field must be present.
903
939
It represents a URL to the referenced resource.
904
940
905
941
A ` title ` field can be present.
906
- It represents advisory information for the resource, such as would be
907
- appropriate for a tooltip.
942
+ It represents advisory information for the resource,
943
+ such as would be appropriate for a tooltip.
908
944
909
945
## Enumeration
910
946
@@ -918,11 +954,12 @@ enum referenceType {
918
954
919
955
** referenceType** represents the explicitness of a reference.
920
956
921
- * ** shortcut** : the reference is implicit, its identifier inferred from its
922
- content
923
- * ** collapsed** : the reference is explicit, its identifier inferred from its
924
- content
925
- * ** full** : the reference is explicit, its identifier explicitly set
957
+ * ** shortcut** : the reference is implicit,
958
+ its identifier inferred from its content
959
+ * ** collapsed** : the reference is explicit,
960
+ its identifier inferred from its content
961
+ * ** full** : the reference is explicit,
962
+ its identifier explicitly set
926
963
927
964
## Content model
928
965
@@ -965,13 +1002,14 @@ type PhrasingContent = Break | Emphasis | Html | Image | ImageReference
965
1002
| InlineCode | Link | LinkReference | Strong | Text
966
1003
```
967
1004
968
- ** Phrasing** content represent the text in a document, and its markup.
1005
+ ** Phrasing** content represent the text in a document and its markup.
969
1006
970
1007
## Extensions
971
1008
972
1009
Markdown syntax is often extended.
973
1010
It is not a goal of this specification to list all possible extensions.
974
- However, a short list of frequently used extensions are shown below.
1011
+ However,
1012
+ a short list of frequently used extensions are shown below.
975
1013
976
1014
### GFM
977
1015
@@ -993,7 +1031,8 @@ accurate or no longer relevant.
993
1031
expected.
994
1032
Its content model is [ ** phrasing** ] [ dfn-phrasing-content ] content.
995
1033
996
- For example, the following markdown:
1034
+ For example,
1035
+ the following markdown:
997
1036
998
1037
``` markdown
999
1038
~~alpha~~
@@ -1016,8 +1055,10 @@ interface ListItemGfm <: ListItem {
1016
1055
}
1017
1056
```
1018
1057
1019
- In GFM, a ` checked ` field can be present.
1020
- It represents whether the item is done (when ` true ` ), not done (when ` false ` ),
1058
+ In GFM,
1059
+ a ` checked ` field can be present.
1060
+ It represents whether the item is done (when ` true ` ),
1061
+ not done (when ` false ` ),
1021
1062
or indeterminate or not applicable (when ` null ` or not present).
1022
1063
1023
1064
#### ` FootnoteDefinition `
@@ -1044,7 +1085,8 @@ Its content model is also [**flow**][dfn-flow-content] content.
1044
1085
** FootnoteDefinition** should be associated with
1045
1086
[ ** FootnoteReferences** ] [ dfn-footnote-reference ] .
1046
1087
1047
- For example, the following markdown:
1088
+ For example,
1089
+ the following markdown:
1048
1090
1049
1091
``` markdown
1050
1092
[^alpha]: bravo and charlie.
@@ -1086,7 +1128,8 @@ It has no content model.
1086
1128
** FootnoteReference** should be associated with a
1087
1129
[ ** FootnoteDefinition** ] [ dfn-footnote-definition ] .
1088
1130
1089
- For example, the following markdown:
1131
+ For example,
1132
+ the following markdown:
1090
1133
1091
1134
``` markdown
1092
1135
[^alpha]
@@ -1120,10 +1163,12 @@ Its content model is [**table**][dfn-table-content] content.
1120
1163
The [ * head* ] [ term-head ] of the node represents the labels of the columns.
1121
1164
1122
1165
An ` align ` field can be present.
1123
- If present, it must be a list of [ ** alignType** s] [ dfn-enum-align-type ] .
1166
+ If present,
1167
+ it must be a list of [ ** alignType** s] [ dfn-enum-align-type ] .
1124
1168
It represents how cells in columns are aligned.
1125
1169
1126
- For example, the following markdown:
1170
+ For example,
1171
+ the following markdown:
1127
1172
1128
1173
``` markdown
1129
1174
| foo | bar |
@@ -1178,14 +1223,16 @@ interface TableCell <: Parent {
1178
1223
```
1179
1224
1180
1225
** TableCell** ([ ** Parent** ] [ dfn-parent ] ) represents a header cell in a
1181
- [ ** Table** ] [ dfn-table ] , if its parent is a [ * head* ] [ term-head ] , or a data
1182
- cell otherwise.
1226
+ [ ** Table** ] [ dfn-table ] ,
1227
+ if its parent is a [ * head* ] [ term-head ] ,
1228
+ or a data cell otherwise.
1183
1229
1184
1230
** TableCell** can be used where [ ** row** ] [ dfn-row-content ] content is expected.
1185
1231
Its content model is [ ** phrasing** ] [ dfn-phrasing-content ] content excluding
1186
1232
[ ** Break** ] [ dfn-break ] nodes.
1187
1233
1188
- For an example, see [ ** Table** ] [ dfn-table ] .
1234
+ For an example,
1235
+ see [ ** Table** ] [ dfn-table ] .
1189
1236
1190
1237
#### ` TableRow `
1191
1238
@@ -1202,10 +1249,11 @@ interface TableRow <: Parent {
1202
1249
expected.
1203
1250
Its content model is [ ** row** ] [ dfn-row-content ] content.
1204
1251
1205
- If the node is a [ * head* ] [ term-head ] , it represents the labels of the columns
1206
- for its parent [ ** Table** ] [ dfn-table ] .
1252
+ If the node is a [ * head* ] [ term-head ] ,
1253
+ it represents the labels of the columns for its parent [ ** Table** ] [ dfn-table ] .
1207
1254
1208
- For an example, see [ ** Table** ] [ dfn-table ] .
1255
+ For an example,
1256
+ see [ ** Table** ] [ dfn-table ] .
1209
1257
1210
1258
#### ` alignType `
1211
1259
@@ -1279,7 +1327,8 @@ the document in the YAML ([\[YAML\]][yaml]) data serialisation language.
1279
1327
expected.
1280
1328
Its content is represented by its ` value ` field.
1281
1329
1282
- For example, the following markdown:
1330
+ For example,
1331
+ the following markdown:
1283
1332
1284
1333
``` markdown
1285
1334
---
@@ -1301,8 +1350,9 @@ type FrontmatterContent = Yaml
1301
1350
1302
1351
** Frontmatter** content represent out-of-band information about the document.
1303
1352
1304
- If frontmatter is present, it must be limited to one node in the
1305
- [ * tree* ] [ term-tree ] , and can only exist as a [ * head* ] [ term-head ] .
1353
+ If frontmatter is present,
1354
+ it must be limited to one node in the [ * tree* ] [ term-tree ] ,
1355
+ and can only exist as a [ * head* ] [ term-head ] .
1306
1356
1307
1357
#### ` FlowContent ` (frontmatter)
1308
1358
@@ -1438,12 +1488,13 @@ See the [unist list of utilities][utilities] for more utilities.
1438
1488
1439
1489
## Security
1440
1490
1441
- As mdast can contain HTML and be used to represent HTML, and improper use of
1442
- HTML can open you up to a [ cross-site scripting (XSS)] [ xss ] attack, improper use
1443
- of mdast is also unsafe.
1444
- When transforming to HTML (typically through [ ** hast** ] [ hast ] ), always be
1445
- careful with user input and use [ ` hast-util-santize ` ] [ sanitize ] to make the hast
1446
- tree safe.
1491
+ As mdast can contain HTML and be used to represent HTML,
1492
+ and improper use of HTML can open you up to a [ cross-site scripting (XSS)] [ xss ]
1493
+ attack,
1494
+ improper use of mdast is also unsafe.
1495
+ When transforming to HTML (typically through [ ** hast** ] [ hast ] ),
1496
+ always be careful with user input and use [ ` hast-util-santize ` ] [ sanitize ] to
1497
+ make the hast tree safe.
1447
1498
1448
1499
## Related
1449
1500
@@ -1461,20 +1512,27 @@ ways to get started.
1461
1512
See [ ` support.md ` ] [ support ] for ways to get help.
1462
1513
Ideas for new utilities and tools can be posted in [ ` syntax-tree/ideas ` ] [ ideas ] .
1463
1514
1464
- A curated list of awesome syntax-tree, unist, mdast, hast, xast, and nlcst
1465
- resources can be found in [ awesome syntax-tree] [ awesome ] .
1515
+ A curated list of awesome ` syntax-tree ` ,
1516
+ unist,
1517
+ mdast,
1518
+ hast,
1519
+ xast,
1520
+ and nlcst resources,
1521
+ can be found in [ awesome syntax-tree] [ awesome ] .
1466
1522
1467
1523
This project has a [ code of conduct] [ coc ] .
1468
- By interacting with this repository, organization, or community you agree to
1469
- abide by its terms.
1524
+ By interacting with this repository,
1525
+ organization,
1526
+ or community you agree to abide by its terms.
1470
1527
1471
1528
## Acknowledgments
1472
1529
1473
1530
The initial release of this project was authored by
1474
1531
[ ** @wooorm ** ] ( https://github.com/wooorm ) .
1475
1532
1476
1533
Special thanks to [ ** @eush77 ** ] ( https://github.com/eush77 ) for their work,
1477
- ideas, and incredibly valuable feedback!
1534
+ ideas,
1535
+ and incredibly valuable feedback!
1478
1536
1479
1537
Thanks to
1480
1538
[ ** @anandthakker ** ] ( https://github.com/anandthakker ) ,
@@ -1511,8 +1569,7 @@ Thanks to
1511
1569
[ ** @stefanprobst ** ] ( https://github.com/stefanprobst ) ,
1512
1570
[ ** @tmcw ** ] ( https://github.com/tmcw ) ,
1513
1571
and [ ** @vhf ** ] ( https://github.com/vhf )
1514
- for contributing to mdast and related
1515
- projects!
1572
+ for contributing to mdast and related projects!
1516
1573
1517
1574
## License
1518
1575
0 commit comments