You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Added `ast` option to compiler to expose the parsed AST directly. When `ast: true`, the compiler returns the AST structure (`ParserResult[]`) instead of rendered JSX.
6
+
7
+
**First time the AST is accessible to users!** This enables:
8
+
9
+
- AST manipulation and transformation before rendering
// Render AST to JSX using createRenderer (not implemented yet)
29
+
```
30
+
31
+
The AST format is `MarkdownToJSX.AST[]`. When footnotes are present, the returned value will be an object with `ast` and `footnotes` properties instead of just the AST array.
**Complexity**: Medium - refactor concatenation points
332
333
**Expected Gain**: 10-15% reduction
333
334
335
+
**Attempted**: Failed because nested parsing relies on incremental updates to `state.prevCapture`. The buffer approach doesn't update the state during nested parsing, breaking lookback functionality used by list items and other nested rules.
336
+
337
+
**Status**: ❌ Not viable due to recursive parsing requirements
338
+
334
339
---
335
340
336
341
#### Idea G: Avoid String Operations Entirely Where Possible
@@ -1047,10 +1052,71 @@ The performance gap is from **fundamental architectural differences**:
1047
1052
1048
1053
### Potential Improvements (Without Full Rewrite)
1049
1054
1050
-
1.**Token Abstraction**: Parse to intermediate token format, render separately
1051
-
2.**Lazy JSX Creation**: Generate JSX only at render time
1052
-
3.**Memoization**: Cache token trees, regenerate JSX from tokens
1053
-
4.**String Reduction**: Use token positions instead of substring calls
1055
+
1. ✅ **AST Exposure**: Parse to AST and expose it (IMPLEMENTED - Feature)
1056
+
2.**Profile React Rendering**: Measure time spent in React.createElement
console.log(ast) // Array of parsed nodes with types
590
+
591
+
// You can manipulate, transform, or analyze the AST before rendering
592
+
```
593
+
594
+
The AST format is `MarkdownToJSX.AST[]` and enables:
595
+
596
+
- AST manipulation and transformation
597
+
- Custom rendering logic without re-parsing
598
+
- Caching parsed AST for performance
599
+
- Linting or validation of markdown structure
600
+
601
+
When footnotes are present, the returned value will be an object with `ast` and `footnotes` properties instead of just the AST array.
602
+
576
603
### Syntax highlighting
577
604
578
605
When using [fenced code blocks](https://www.markdownguide.org/extended-syntax/#syntax-highlighting) with language annotation, that language will be added to the `<code>` element as `class="lang-${language}"`. For best results, you can use `options.overrides` to provide an appropriate syntax highlighting integration like this one using `highlight.js`:
0 commit comments