File tree Expand file tree Collapse file tree 5 files changed +41
-8
lines changed Expand file tree Collapse file tree 5 files changed +41
-8
lines changed Original file line number Diff line number Diff line change 1
1
/**
2
2
* @typedef {import('mdast').Root } Root
3
+ * @typedef {import('mdast-util-math').ToOptions } Options
3
4
*
4
5
* @typedef {import('mdast-util-math') } DoNotTouchAsThisImportIncludesMathInTree
5
6
*/
@@ -10,14 +11,14 @@ import {mathFromMarkdown, mathToMarkdown} from 'mdast-util-math'
10
11
/**
11
12
* Plugin to support math.
12
13
*
13
- * @type {import('unified').Plugin<void[], Root> }
14
+ * @type {import('unified').Plugin<[Options?] | void[], Root , Root> }
14
15
*/
15
- export default function remarkMath ( ) {
16
+ export default function remarkMath ( options = { } ) {
16
17
const data = this . data ( )
17
18
18
- add ( 'micromarkExtensions' , math )
19
- add ( 'fromMarkdownExtensions' , mathFromMarkdown )
20
- add ( 'toMarkdownExtensions' , mathToMarkdown )
19
+ add ( 'micromarkExtensions' , math ( options ) )
20
+ add ( 'fromMarkdownExtensions' , mathFromMarkdown ( ) )
21
+ add ( 'toMarkdownExtensions' , mathToMarkdown ( options ) )
21
22
22
23
/**
23
24
* @param {string } field
Original file line number Diff line number Diff line change 36
36
],
37
37
"dependencies" : {
38
38
"@types/mdast" : " ^3.0.0" ,
39
- "mdast-util-math" : " ^1 .0.0" ,
40
- "micromark-extension-math" : " ^1 .0.0" ,
39
+ "mdast-util-math" : " ^2 .0.0" ,
40
+ "micromark-extension-math" : " ^2 .0.0" ,
41
41
"unified" : " ^10.0.0"
42
42
},
43
43
"scripts" : {
Original file line number Diff line number Diff line change @@ -88,6 +88,15 @@ Get’s useful when combined with [`rehype-katex`][rehype-katex] or
88
88
See [ ` micromark/micromark-extension-math ` ] [ extension-math ] for more info on what
89
89
syntax is supported.
90
90
91
+ ##### ` options `
92
+
93
+ ###### ` options.singleDollarTextMath `
94
+
95
+ Whether to support math (text) with a single dollar (` boolean ` , default:
96
+ ` true ` ).
97
+ Single dollars work in Pandoc and many other places, but often interfere with
98
+ “normal” dollars in text.
99
+
91
100
#### Notes
92
101
93
102
##### Escaping
Original file line number Diff line number Diff line change @@ -318,6 +318,29 @@ test('remarkMath', (t) => {
318
318
'should stringify inline and block math'
319
319
)
320
320
321
+ t . deepEqual (
322
+ unified ( )
323
+ . use ( remarkParse )
324
+ . use ( remarkStringify )
325
+ . use ( remarkMath , { singleDollarTextMath : false } )
326
+ . processSync ( 'Math $\\alpha$\n\n$$\\beta+\\gamma$$\n' )
327
+ . toString ( ) ,
328
+ 'Math $\\alpha$\n\n$$\\beta+\\gamma$$\n' ,
329
+ 'should support `singleDollarTextMath: false` (1)'
330
+ )
331
+
332
+ t . deepEqual (
333
+ unified ( )
334
+ . use ( remarkParse )
335
+ . use ( remarkMath , { singleDollarTextMath : false } )
336
+ . use ( remarkRehype )
337
+ . use ( rehypeStringify )
338
+ . processSync ( 'Math $\\alpha$\n\n$$\\beta+\\gamma$$\n' )
339
+ . toString ( ) ,
340
+ '<p>Math $\\alpha$</p>\n<p><span class="math math-inline">\\beta+\\gamma</span></p>' ,
341
+ 'should support `singleDollarTextMath: false` (2)'
342
+ )
343
+
321
344
t . deepEqual (
322
345
unified ( )
323
346
. use ( remarkParse )
Original file line number Diff line number Diff line change @@ -80,7 +80,7 @@ But in a browser, that looks something like this:
80
80
81
81
## Packages
82
82
83
- This repo houses four packages:
83
+ This repo houses three packages:
84
84
85
85
* [`remark-math`][remark-math]
86
86
— Parses `$` as `inlineMath` and `$$` as `math` nodes
You can’t perform that action at this time.
0 commit comments