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 11/**
22 * @typedef {import('mdast').Root } Root
3+ * @typedef {import('mdast-util-math').ToOptions } Options
34 *
45 * @typedef {import('mdast-util-math') } DoNotTouchAsThisImportIncludesMathInTree
56 */
@@ -10,14 +11,14 @@ import {mathFromMarkdown, mathToMarkdown} from 'mdast-util-math'
1011/**
1112 * Plugin to support math.
1213 *
13- * @type {import('unified').Plugin<void[], Root> }
14+ * @type {import('unified').Plugin<[Options?] | void[], Root , Root> }
1415 */
15- export default function remarkMath ( ) {
16+ export default function remarkMath ( options = { } ) {
1617 const data = this . data ( )
1718
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 ) )
2122
2223 /**
2324 * @param {string } field
Original file line number Diff line number Diff line change 3636 ],
3737 "dependencies" : {
3838 "@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" ,
4141 "unified" : " ^10.0.0"
4242 },
4343 "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
8888See [ ` micromark/micromark-extension-math ` ] [ extension-math ] for more info on what
8989syntax is supported.
9090
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+
91100#### Notes
92101
93102##### Escaping
Original file line number Diff line number Diff line change @@ -318,6 +318,29 @@ test('remarkMath', (t) => {
318318 'should stringify inline and block math'
319319 )
320320
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+
321344 t . deepEqual (
322345 unified ( )
323346 . 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:
8080
8181## Packages
8282
83- This repo houses four packages:
83+ This repo houses three packages:
8484
8585* [`remark-math`][remark-math]
8686 — Parses `$` as `inlineMath` and `$$` as `math` nodes
You can’t perform that action at this time.
0 commit comments