Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit d46d288

Browse files
committedOct 4, 2024
Refactor docs
1 parent 48456ee commit d46d288

File tree

1 file changed

+147
-90
lines changed

1 file changed

+147
-90
lines changed
 

‎readme.md

Lines changed: 147 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
**mdast** is a specification for representing markdown in a [syntax
88
tree][syntax-tree].
99
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].
1212

1313
This document may not be released.
1414
See [releases][] for released documents.
@@ -71,28 +71,31 @@ The latest released version is [`5.0.0`][latest].
7171

7272
This document defines a format for representing [markdown][] as an [abstract
7373
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.
7677
This specification is written in a [Web IDL][webidl]-like grammar.
7778

7879
### Where this specification fits
7980

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].
8284

8385
mdast relates to [JavaScript][] in that it has a rich [ecosystem of
8486
utilities][list-of-utilities] for working with compliant syntax trees in
8587
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
8790
languages.
8891

8992
mdast relates to the [unified][] and [remark][] projects in that mdast syntax
9093
trees are used throughout their ecosystems.
9194

9295
## Types
9396

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:
9699

97100
```sh
98101
npm install @types/mdast
@@ -144,7 +147,8 @@ somewhere else.
144147
expected.
145148
Its content model is also [**flow**][dfn-flow-content] content.
146149

147-
For example, the following markdown:
150+
For example,
151+
the following markdown:
148152

149153
```markdown
150154
> Alpha bravo charlie.
@@ -170,14 +174,15 @@ interface Break <: Node {
170174
}
171175
```
172176

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.
175179

176180
**Break** can be used where [**phrasing**][dfn-phrasing-content] content is
177181
expected.
178182
It has no content model.
179183

180-
For example, the following markdown:
184+
For example,
185+
the following markdown:
181186

182187
```markdown
183188
foo··
@@ -219,10 +224,12 @@ This node relates to the [**phrasing**][dfn-phrasing-content] content concept
219224
A `lang` field can be present.
220225
It represents the language of computer code being marked up.
221226

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.
223229
It represents custom information relating to the node.
224230

225-
For example, the following markdown:
231+
For example,
232+
the following markdown:
226233

227234
```markdown
228235
foo()
@@ -283,7 +290,8 @@ It has no content model.
283290
[**LinkReferences**][dfn-link-reference] and
284291
[**ImageReferences**][dfn-image-reference].
285292

286-
For example, the following markdown:
293+
For example,
294+
the following markdown:
287295

288296
```markdown
289297
[Alpha]: https://example.com
@@ -317,7 +325,8 @@ contents.
317325
expected.
318326
Its content model is [**phrasing**][dfn-phrasing-content] content.
319327

320-
For example, the following markdown:
328+
For example,
329+
the following markdown:
321330

322331
```markdown
323332
*alpha* _bravo_
@@ -360,7 +369,8 @@ Its content model is [**phrasing**][dfn-phrasing-content] content.
360369
A `depth` field must be present.
361370
A value of `1` is said to be the highest rank and `6` the lowest.
362371

363-
For example, the following markdown:
372+
For example,
373+
the following markdown:
364374

365375
```markdown
366376
# Alpha
@@ -393,7 +403,8 @@ Its content is represented by its `value` field.
393403
**Html** nodes do not have the restriction of being valid or complete HTML
394404
([\[HTML\]][html]) constructs.
395405

396-
For example, the following markdown:
406+
For example,
407+
the following markdown:
397408

398409
```markdown
399410
<div>
@@ -420,12 +431,14 @@ Image includes Alternative
420431

421432
**Image** can be used where [**phrasing**][dfn-phrasing-content] content is
422433
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.
424436

425437
**Image** includes the mixins [**Resource**][dfn-mxn-resource] and
426438
[**Alternative**][dfn-mxn-alternative].
427439

428-
For example, the following markdown:
440+
For example,
441+
the following markdown:
429442

430443
```markdown
431444
![alpha](https://example.com/favicon.ico "bravo")
@@ -454,18 +467,21 @@ ImageReference includes Alternative
454467
```
455468

456469
**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.
458472

459473
**ImageReference** can be used where [**phrasing**][dfn-phrasing-content]
460474
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.
462477

463478
**ImageReference** includes the mixins [**Reference**][dfn-mxn-reference] and
464479
[**Alternative**][dfn-mxn-alternative].
465480

466481
**ImageReference** should be associated with a [**Definition**][dfn-definition].
467482

468-
For example, the following markdown:
483+
For example,
484+
the following markdown:
469485

470486
```markdown
471487
![alpha][bravo]
@@ -492,7 +508,10 @@ interface InlineCode <: Literal {
492508
```
493509

494510
**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.
496515

497516
**InlineCode** can be used where [**phrasing**][dfn-phrasing-content] content
498517
is expected.
@@ -501,7 +520,8 @@ Its content is represented by its `value` field.
501520
This node relates to the [**flow**][dfn-flow-content] content concept
502521
[**Code**][dfn-code].
503522

504-
For example, the following markdown:
523+
For example,
524+
the following markdown:
505525

506526
```markdown
507527
`foo()`
@@ -532,7 +552,8 @@ Its content model is also [**phrasing**][dfn-phrasing-content] content.
532552

533553
**Link** includes the mixin [**Resource**][dfn-mxn-resource].
534554

535-
For example, the following markdown:
555+
For example,
556+
the following markdown:
536557

537558
```markdown
538559
[alpha](https://example.com "bravo")
@@ -561,7 +582,8 @@ LinkReference includes Reference
561582
```
562583

563584
**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.
565587

566588
**LinkReference** can be used where [**phrasing**][dfn-phrasing-content] content
567589
is expected.
@@ -571,7 +593,8 @@ Its content model is also [**phrasing**][dfn-phrasing-content] content.
571593

572594
**LinkReferences** should be associated with a [**Definition**][dfn-definition].
573595

574-
For example, the following markdown:
596+
For example,
597+
the following markdown:
575598

576599
```markdown
577600
[alpha][Bravo]
@@ -607,19 +630,21 @@ interface List <: Parent {
607630
Its content model is [**list**][dfn-list-content] content.
608631

609632
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).
612635

613636
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.
616640

617641
A `spread` field can be present.
618642
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).
621645

622-
For example, the following markdown:
646+
For example,
647+
the following markdown:
623648

624649
```markdown
625650
1. foo
@@ -662,9 +687,11 @@ Its content model is [**flow**][dfn-flow-content] content.
662687

663688
A `spread` field can be present.
664689
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).
666692

667-
For example, the following markdown:
693+
For example,
694+
the following markdown:
668695

669696
```markdown
670697
* bar
@@ -698,7 +725,8 @@ with a particular point or idea.
698725
**Paragraph** can be used where [**content**][dfn-content] is expected.
699726
Its content model is [**phrasing**][dfn-phrasing-content] content.
700727

701-
For example, the following markdown:
728+
For example,
729+
the following markdown:
702730

703731
```markdown
704732
Alpha bravo charlie.
@@ -723,8 +751,8 @@ interface Root <: Parent {
723751

724752
**Root** ([**Parent**][dfn-parent]) represents a document.
725753

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].
728756
Its content model is **not** limited to [**flow**][dfn-flow-content] content,
729757
but instead can contain any [**mdast content**][dfn-mdast-content] with the
730758
restriction that all content must be of the same category.
@@ -738,14 +766,16 @@ interface Strong <: Parent {
738766
}
739767
```
740768

741-
**Strong** ([**Parent**][dfn-parent]) represents strong importance, seriousness,
769+
**Strong** ([**Parent**][dfn-parent]) represents strong importance,
770+
seriousness,
742771
or urgency for its contents.
743772

744773
**Strong** can be used where [**phrasing**][dfn-phrasing-content] content is
745774
expected.
746775
Its content model is [**phrasing**][dfn-phrasing-content] content.
747776

748-
For example, the following markdown:
777+
For example,
778+
the following markdown:
749779

750780
```markdown
751781
**alpha** __bravo__
@@ -784,7 +814,8 @@ interface Text <: Literal {
784814
expected.
785815
Its content is represented by its `value` field.
786816

787-
For example, the following markdown:
817+
For example,
818+
the following markdown:
788819

789820
```markdown
790821
Alpha bravo charlie.
@@ -804,14 +835,17 @@ interface ThematicBreak <: Node {
804835
}
805836
```
806837

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.
809842

810843
**ThematicBreak** can be used where [**flow**][dfn-flow-content] content is
811844
expected.
812845
It has no content model.
813846

814-
For example, the following markdown:
847+
For example,
848+
the following markdown:
815849

816850
```markdown
817851
***
@@ -860,16 +894,18 @@ A `label` field can be present.
860894
`label` is a string value: it works just like `title` on a link or a `lang` on
861895
code: character escapes and character references are parsed.
862896

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.
865901

866902
Whether the value of `identifier` (or normalized `label` if there is no
867903
`identifier`) is expected to be a unique identifier or not depends on the type
868904
of node including the **Association**.
869905
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.
873909

874910
### `Reference`
875911

@@ -903,8 +939,8 @@ A `url` field must be present.
903939
It represents a URL to the referenced resource.
904940

905941
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.
908944

909945
## Enumeration
910946

@@ -918,11 +954,12 @@ enum referenceType {
918954

919955
**referenceType** represents the explicitness of a reference.
920956

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
926963

927964
## Content model
928965

@@ -965,13 +1002,14 @@ type PhrasingContent = Break | Emphasis | Html | Image | ImageReference
9651002
| InlineCode | Link | LinkReference | Strong | Text
9661003
```
9671004

968-
**Phrasing** content represent the text in a document, and its markup.
1005+
**Phrasing** content represent the text in a document and its markup.
9691006

9701007
## Extensions
9711008

9721009
Markdown syntax is often extended.
9731010
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.
9751013

9761014
### GFM
9771015

@@ -993,7 +1031,8 @@ accurate or no longer relevant.
9931031
expected.
9941032
Its content model is [**phrasing**][dfn-phrasing-content] content.
9951033

996-
For example, the following markdown:
1034+
For example,
1035+
the following markdown:
9971036

9981037
```markdown
9991038
~~alpha~~
@@ -1016,8 +1055,10 @@ interface ListItemGfm <: ListItem {
10161055
}
10171056
```
10181057

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`),
10211062
or indeterminate or not applicable (when `null` or not present).
10221063

10231064
#### `FootnoteDefinition`
@@ -1044,7 +1085,8 @@ Its content model is also [**flow**][dfn-flow-content] content.
10441085
**FootnoteDefinition** should be associated with
10451086
[**FootnoteReferences**][dfn-footnote-reference].
10461087

1047-
For example, the following markdown:
1088+
For example,
1089+
the following markdown:
10481090

10491091
```markdown
10501092
[^alpha]: bravo and charlie.
@@ -1086,7 +1128,8 @@ It has no content model.
10861128
**FootnoteReference** should be associated with a
10871129
[**FootnoteDefinition**][dfn-footnote-definition].
10881130

1089-
For example, the following markdown:
1131+
For example,
1132+
the following markdown:
10901133

10911134
```markdown
10921135
[^alpha]
@@ -1120,10 +1163,12 @@ Its content model is [**table**][dfn-table-content] content.
11201163
The [*head*][term-head] of the node represents the labels of the columns.
11211164

11221165
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].
11241168
It represents how cells in columns are aligned.
11251169

1126-
For example, the following markdown:
1170+
For example,
1171+
the following markdown:
11271172

11281173
```markdown
11291174
| foo | bar |
@@ -1178,14 +1223,16 @@ interface TableCell <: Parent {
11781223
```
11791224

11801225
**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.
11831229

11841230
**TableCell** can be used where [**row**][dfn-row-content] content is expected.
11851231
Its content model is [**phrasing**][dfn-phrasing-content] content excluding
11861232
[**Break**][dfn-break] nodes.
11871233

1188-
For an example, see [**Table**][dfn-table].
1234+
For an example,
1235+
see [**Table**][dfn-table].
11891236

11901237
#### `TableRow`
11911238

@@ -1202,10 +1249,11 @@ interface TableRow <: Parent {
12021249
expected.
12031250
Its content model is [**row**][dfn-row-content] content.
12041251

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].
12071254

1208-
For an example, see [**Table**][dfn-table].
1255+
For an example,
1256+
see [**Table**][dfn-table].
12091257

12101258
#### `alignType`
12111259

@@ -1279,7 +1327,8 @@ the document in the YAML ([\[YAML\]][yaml]) data serialisation language.
12791327
expected.
12801328
Its content is represented by its `value` field.
12811329

1282-
For example, the following markdown:
1330+
For example,
1331+
the following markdown:
12831332

12841333
```markdown
12851334
---
@@ -1301,8 +1350,9 @@ type FrontmatterContent = Yaml
13011350

13021351
**Frontmatter** content represent out-of-band information about the document.
13031352

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].
13061356

13071357
#### `FlowContent` (frontmatter)
13081358

@@ -1438,12 +1488,13 @@ See the [unist list of utilities][utilities] for more utilities.
14381488

14391489
## Security
14401490

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.
14471498

14481499
## Related
14491500

@@ -1461,20 +1512,27 @@ ways to get started.
14611512
See [`support.md`][support] for ways to get help.
14621513
Ideas for new utilities and tools can be posted in [`syntax-tree/ideas`][ideas].
14631514

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].
14661522

14671523
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.
14701527

14711528
## Acknowledgments
14721529

14731530
The initial release of this project was authored by
14741531
[**@wooorm**](https://github.com/wooorm).
14751532

14761533
Special thanks to [**@eush77**](https://github.com/eush77) for their work,
1477-
ideas, and incredibly valuable feedback!
1534+
ideas,
1535+
and incredibly valuable feedback!
14781536

14791537
Thanks to
14801538
[**@anandthakker**](https://github.com/anandthakker),
@@ -1511,8 +1569,7 @@ Thanks to
15111569
[**@stefanprobst**](https://github.com/stefanprobst),
15121570
[**@tmcw**](https://github.com/tmcw),
15131571
and [**@vhf**](https://github.com/vhf)
1514-
for contributing to mdast and related
1515-
projects!
1572+
for contributing to mdast and related projects!
15161573

15171574
## License
15181575

0 commit comments

Comments
 (0)
Please sign in to comment.