19
19
* [ API] ( #api )
20
20
* [ ` mathFromMarkdown() ` ] ( #mathfrommarkdown )
21
21
* [ ` mathToMarkdown(options?) ` ] ( #mathtomarkdownoptions )
22
+ * [ ` InlineMath ` ] ( #inlinemath )
23
+ * [ ` Math ` ] ( #math )
24
+ * [ ` ToOptions ` ] ( #tooptions )
22
25
* [ HTML] ( #html )
26
+ * [ Syntax] ( #syntax )
23
27
* [ Syntax tree] ( #syntax-tree )
24
28
* [ Nodes] ( #nodes )
25
29
* [ Content model] ( #content-model )
31
35
32
36
## What is this?
33
37
34
- This package contains extensions that add support for math to
35
- [ ` mdast-util-from-markdown ` ] [ mdast-util-from-markdown ] and
36
- [ ` mdast-util-to-markdown ` ] [ mdast-util-to-markdown ] .
38
+ This package contains two extensions that add support for math syntax in
39
+ markdown to [ mdast] [ ] .
40
+ These extensions plug into
41
+ [ ` mdast-util-from-markdown ` ] [ mdast-util-from-markdown ] (to support parsing
42
+ math in markdown into a syntax tree) and
43
+ [ ` mdast-util-to-markdown ` ] [ mdast-util-to-markdown ] (to support serializing
44
+ math in syntax trees to markdown).
37
45
38
46
## When to use this
39
47
40
- These tools are all rather low-level.
41
- In most cases, you’d want to use [ ` remark-math ` ] [ remark-math ] with remark
42
- instead.
43
-
44
48
This project is useful when you want to support math in markdown.
45
49
Extending markdown with a syntax extension makes the markdown less portable.
46
50
LaTeX equations are also quite hard.
47
51
But this mechanism works well when you want authors, that have some LaTeX
48
52
experience, to be able to embed rich diagrams of math in scientific text.
49
53
50
- When working with ` mdast-util-from-markdown ` , you must combine this package with
51
- [ ` micromark-extension-math ` ] [ extension ] .
54
+ You can use these extensions when you are working with
55
+ ` mdast-util-from-markdown ` and ` mdast-util-to-markdown ` already.
56
+
57
+ When working with ` mdast-util-from-markdown ` , you must combine this package
58
+ with [ ` micromark-extension-math ` ] [ micromark-extension-math ] .
59
+
60
+ When you don’t need a syntax tree, you can use [ ` micromark ` ] [ micromark ]
61
+ directly with
62
+ [ ` micromark-extension-math ` ] [ micromark-extension-math ] .
63
+
64
+ All these packages are used [ ` remark-math ` ] [ remark-math ] , which
65
+ focusses on making it easier to transform content by abstracting these
66
+ internals away.
52
67
53
68
This utility adds [ fields on nodes] [ fields ] so that the utility responsible for
54
69
turning mdast (markdown) nodes into hast (HTML) nodes,
@@ -59,7 +74,7 @@ turning mdast (markdown) nodes into hast (HTML) nodes,
59
74
## Install
60
75
61
76
This package is [ ESM only] [ esm ] .
62
- In Node.js (version 12.20+, 14.14+, or 16.0+), install with [ npm] [ ] :
77
+ In Node.js (version 14.14+ and 16.0+), install with [ npm] [ ] :
63
78
64
79
``` sh
65
80
npm install mdast-util-math
146
161
147
162
## API
148
163
149
- This package exports the identifiers ` mathFromMarkdown ` and ` mathToMarkdown ` .
164
+ This package exports the identifiers [ ` mathFromMarkdown ` ] [ api-mathfrommarkdown ]
165
+ and [ ` mathToMarkdown ` ] [ api-mathtomarkdown ] .
150
166
There is no default export.
151
167
152
168
### ` mathFromMarkdown() `
153
169
154
- Function that can be called to get an extension for
155
- [ ` mdast-util-from-markdown ` ] [ mdast-util-from-markdown ] .
170
+ Create an extension for [ ` mdast-util-from-markdown ` ] [ mdast-util-from-markdown ] .
171
+
172
+ ###### Returns
173
+
174
+ Extension for ` mdast-util-from-markdown `
175
+ ([ ` FromMarkdownExtension ` ] [ frommarkdownextension ] ).
156
176
157
177
### ` mathToMarkdown(options?) `
158
178
159
- Function that can be called to get an extension for
160
- [ ` mdast-util-to-markdown ` ] [ mdast-util-to-markdown ] .
179
+ Create an extension for [ ` mdast-util-to-markdown ` ] [ mdast-util-to-markdown ] .
180
+
181
+ ###### Parameters
182
+
183
+ * ` options ` ([ ` ToOptions ` ] [ api-tooptions ] , optional)
184
+ — configuration
185
+
186
+ ###### Returns
187
+
188
+ Extension for ` mdast-util-to-markdown `
189
+ ([ ` ToMarkdownExtension ` ] [ tomarkdownextension ] ).
190
+
191
+ ### ` InlineMath `
192
+
193
+ Math (text) (TypeScript type).
194
+
195
+ ###### Type
196
+
197
+ ``` ts
198
+ import type {Literal } from ' mdast'
199
+
200
+ interface InlineMath extends Literal {
201
+ type: ' inlineMath'
202
+ }
203
+ ```
204
+
205
+ ### ` Math `
206
+
207
+ Math (flow) (TypeScript type).
208
+
209
+ ###### Type
161
210
162
- ##### ` options `
211
+ ``` ts
212
+ import type {Literal } from ' mdast'
163
213
164
- Configuration (optional).
214
+ interface Math extends Literal {
215
+ type: ' math'
216
+ meta? : string | undefined | null
217
+ }
218
+ ```
165
219
166
- ###### ` options.singleDollarTextMath `
220
+ ### ` ToOptions `
167
221
168
- Whether to support text math (inline) with a single dollar (` boolean ` , default:
169
- ` true ` ).
222
+ Configuration (TypeScript type).
170
223
171
- Single dollars work in Pandoc and many other places, but often interfere with
172
- “normal” dollars in text.
224
+ ###### Fields
225
+
226
+ * ` singleDollarTextMath ` (` boolean ` , default: ` true ` )
227
+ — whether to support math (text) with a single dollar.
228
+ Single dollars work in Pandoc and many other places, but often interfere
229
+ with “normal” dollars in text.
230
+ If you turn this off, you can still use two or more dollars for text math
173
231
174
232
## HTML
175
233
@@ -178,6 +236,10 @@ When mdast is turned into hast the math nodes are turned into
178
236
` <span class="math math-inline">…</span> ` and
179
237
` <div class="math math-display">…</div> ` elements.
180
238
239
+ ## Syntax
240
+
241
+ See [ Syntax in ` micromark-extension-frontmatter ` ] [ syntax ] .
242
+
181
243
## Syntax tree
182
244
183
245
The following interfaces are added to ** [ mdast] [ ] ** by this utility.
@@ -193,14 +255,14 @@ interface Math <: Literal {
193
255
}
194
256
```
195
257
196
- ** Math** ([ ** Literal** ] [ dfn-literal ] ) represents a block of math,
258
+ ** Math** (** [ Literal] [ dfn-literal ] ** ) represents a block of math,
197
259
such as LaTeX mathematical expressions.
198
260
199
- ** Math** can be used where [ ** flow** ] [ dfn-flow-content ] content is expected.
261
+ ** Math** can be used where ** [ flow] [ dfn-flow-content ] ** content is expected.
200
262
Its content is represented by its ` value ` field.
201
263
202
- This node relates to the [ ** phrasing** ] [ dfn-phrasing-content ] content concept
203
- [ ** InlineMath** ] [ dfn-inline-math ] .
264
+ This node relates to the ** [ phrasing] [ dfn-phrasing-content ] ** content concept
265
+ ** [ InlineMath] [ dfn-inline-math ] ** .
204
266
205
267
A ` meta ` field can be present.
206
268
It represents custom information relating to the node.
@@ -232,15 +294,15 @@ interface InlineMath <: Literal {
232
294
}
233
295
```
234
296
235
- ** InlineMath** ([ ** Literal** ] [ dfn-literal ] ) represents a fragment of computer
297
+ ** InlineMath** (** [ Literal] [ dfn-literal ] ** ) represents a fragment of computer
236
298
code, such as a file name, computer program, or anything a computer could parse.
237
299
238
- ** InlineMath** can be used where [ ** phrasing** ] [ dfn-phrasing-content ] content
300
+ ** InlineMath** can be used where ** [ phrasing] [ dfn-phrasing-content ] ** content
239
301
is expected.
240
302
Its content is represented by its ` value ` field.
241
303
242
- This node relates to the [ ** flow** ] [ dfn-flow-content ] content concept
243
- [ ** Math** ] [ dfn-math ] .
304
+ This node relates to the ** [ flow] [ dfn-flow-content ] ** content concept
305
+ ** [ Math] [ dfn-math ] ** .
244
306
245
307
For example, the following markdown:
246
308
@@ -271,7 +333,8 @@ type PhrasingMath = InlineMath | PhrasingContent
271
333
## Types
272
334
273
335
This package is fully typed with [ TypeScript] [ ] .
274
- It exports the additional types ` Math ` , ` InlineMath ` , and ` ToOptions ` .
336
+ It exports the additional types [ ` InlineMath ` ] [ api-inlinemath ] ,
337
+ [ ` Math ` ] [ api-math ] , and [ ` ToOptions ` ] [ api-tooptions ] .
275
338
276
339
It also registers the node types with ` @types/mdast ` .
277
340
If you’re working with the syntax tree, make sure to import this utility
@@ -296,17 +359,17 @@ visit(tree, (node) => {
296
359
297
360
Projects maintained by the unified collective are compatible with all maintained
298
361
versions of Node.js.
299
- As of now, that is Node.js 12.20+, 14.14+, and 16.0+.
362
+ As of now, that is Node.js 14.14+ and 16.0+.
300
363
Our projects sometimes work with older versions, but this is not guaranteed.
301
364
302
365
This plugin works with ` mdast-util-from-markdown ` version 1+ and
303
366
` mdast-util-to-markdown ` version 1+.
304
367
305
368
## Related
306
369
307
- * [ ` remarkjs/ remark-math` ] [ remark-math ]
370
+ * [ ` remark-math ` ] [ remark-math ]
308
371
— remark plugin to support math
309
- * [ ` micromark/micromark -extension-math ` ] [ extension ]
372
+ * [ ` micromark-extension-math ` ] [ micromark- extension-math ]
310
373
— micromark extension to parse math
311
374
312
375
## Contribute
@@ -381,16 +444,34 @@ abide by its terms.
381
444
382
445
[ mdast-util-to-hast ] : https://github.com/syntax-tree/mdast-util-to-hast
383
446
384
- [ extension ] : https://github.com/micromark/micromark-extension-math
447
+ [ micromark ] : https://github.com/micromark/micromark
448
+
449
+ [ micromark-extension-math ] : https://github.com/micromark/micromark-extension-math
450
+
451
+ [ syntax ] : https://github.com/micromark/micromark-extension-math#syntax
385
452
386
453
[ fields ] : https://github.com/syntax-tree/mdast-util-to-hast#fields-on-nodes
387
454
388
455
[ dfn-literal ] : https://github.com/syntax-tree/mdast#literal
389
456
457
+ [ frommarkdownextension ] : https://github.com/syntax-tree/mdast-util-from-markdown#extension
458
+
459
+ [ tomarkdownextension ] : https://github.com/syntax-tree/mdast-util-to-markdown#options
460
+
461
+ [ api-mathfrommarkdown ] : #mathfrommarkdown
462
+
463
+ [ api-mathtomarkdown ] : #mathtomarkdownoptions
464
+
465
+ [ api-math ] : #math
466
+
467
+ [ api-inlinemath ] : #inlinemath
468
+
469
+ [ api-tooptions ] : #tooptions
470
+
390
471
[ dfn-flow-content ] : #flowcontent-math
391
472
392
473
[ dfn-phrasing-content ] : #phrasingcontent-math
393
474
394
- [ dfn-inline-math ] : #inlinemath
475
+ [ dfn-inline-math ] : #inlinemath-1
395
476
396
- [ dfn-math ] : #math
477
+ [ dfn-math ] : #math-1
0 commit comments