23
23
*/
24
24
25
25
import { ok as assert } from 'devlop'
26
- import { markdownLineEnding } from 'micromark-util-character'
26
+ import { factorySpace } from 'micromark-factory-space'
27
+ import { markdownLineEnding , markdownSpace } from 'micromark-util-character'
27
28
import { eventsToAcorn } from 'micromark-util-events-to-acorn'
28
29
import { codes , types } from 'micromark-util-symbol'
29
30
import { positionFromEstree } from 'unist-util-position-from-estree'
30
31
import { VFileMessage } from 'vfile-message'
31
32
33
+ // Tab-size to eat has to be the same as what we serialize as.
34
+ // While in some places in markdown that’s 4, in JS it’s more common as 2.
35
+ // Which is what’s also in `mdast-util-mdx-jsx`:
36
+ // <https://github.com/syntax-tree/mdast-util-mdx-jsx/blob/40b951b/lib/index.js#L52>
37
+ const indentSize = 2
38
+
32
39
const trouble =
33
40
'https://github.com/micromark/micromark-extension-mdx-expression/tree/main/packages/micromark-extension-mdx-expression'
34
41
@@ -247,6 +254,8 @@ export function factoryMdxExpression(
247
254
throw error
248
255
}
249
256
257
+ // Note: `markdown-rs` uses `4`, but we use `2`.
258
+ //
250
259
// Idea: investigate if we’d need to use more complex stripping.
251
260
// Take this example:
252
261
//
@@ -256,12 +265,18 @@ export function factoryMdxExpression(
256
265
// > `} /> eee
257
266
// ```
258
267
//
259
- // The block quote takes one space from each line, the paragraph doesn’t.
260
- // The intent above is *perhaps* for the split to be as `>␠␠|␠␠␠␠|d`,
261
- // Currently, we *don’t* do anything at all, it’s `>␠|␠␠␠␠␠|d` instead.
262
- //
263
- // Note: we used to have some handling here, and `markdown-rs` still does,
264
- // which should be removed.
268
+ // Currently, the “paragraph” starts at `> | aaa`, so for the next line
269
+ // here we split it into `>␠|␠␠|␠␠␠d` (prefix, this indent here,
270
+ // expression data).
271
+ if ( markdownSpace ( code ) ) {
272
+ return factorySpace (
273
+ effects ,
274
+ before ,
275
+ types . linePrefix ,
276
+ indentSize + 1
277
+ ) ( code )
278
+ }
279
+
265
280
return before ( code )
266
281
}
267
282
}
0 commit comments