markdown-to-jsx 7.7.16 → 8.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +56 -1
- package/dist/debug.module.js +1754 -1
- package/dist/debug.module.js.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +40 -50
- package/dist/index.modern.js +1 -1
- package/dist/index.modern.js.map +1 -1
- package/dist/index.module.js +1 -1
- package/dist/index.module.js.map +1 -1
- package/dist/index.umd.js +1 -1
- package/dist/index.umd.js.map +1 -1
- package/dist/match.d.ts +42 -0
- package/package.json +12 -11
package/README.md
CHANGED
|
@@ -6,6 +6,8 @@ The most lightweight, customizable React markdown component.
|
|
|
6
6
|
|
|
7
7
|
<!-- TOC -->
|
|
8
8
|
|
|
9
|
+
- [Upgrading](#upgrading)
|
|
10
|
+
- [From v7.x to v8.x](#from-v7x-to-v8x)
|
|
9
11
|
- [Installation](#installation)
|
|
10
12
|
- [Usage](#usage)
|
|
11
13
|
- [Parsing Options](#parsing-options)
|
|
@@ -25,6 +27,7 @@ The most lightweight, customizable React markdown component.
|
|
|
25
27
|
- [options.namedCodesToUnicode](#optionsnamedcodestounicode)
|
|
26
28
|
- [options.disableAutoLink](#optionsdisableautolink)
|
|
27
29
|
- [options.disableParsingRawHTML](#optionsdisableparsingrawhtml)
|
|
30
|
+
- [options.ast](#optionsast)
|
|
28
31
|
- [Syntax highlighting](#syntax-highlighting)
|
|
29
32
|
- [Handling shortcodes](#handling-shortcodes)
|
|
30
33
|
- [Getting the smallest possible bundle size](#getting-the-smallest-possible-bundle-size)
|
|
@@ -53,10 +56,36 @@ The most lightweight, customizable React markdown component.
|
|
|
53
56
|
|
|
54
57
|
- Fenced code blocks with [highlight.js](https://highlightjs.org/) support; see [Syntax highlighting](#syntax-highlighting) for instructions on setting up highlight.js.
|
|
55
58
|
|
|
56
|
-
All this clocks in at around
|
|
59
|
+
All this clocks in at around 7.5 kB gzipped, which is a fraction of the size of most other React markdown components.
|
|
57
60
|
|
|
58
61
|
Requires React >= 0.14.
|
|
59
62
|
|
|
63
|
+
## Upgrading
|
|
64
|
+
|
|
65
|
+
### From v7.x to v8.x
|
|
66
|
+
|
|
67
|
+
**Breaking Changes:**
|
|
68
|
+
|
|
69
|
+
- Type `ParserResult` renamed to `ASTNode` - If you were using `MarkdownToJSX.ParserResult` in your code, update to `MarkdownToJSX.ASTNode`
|
|
70
|
+
|
|
71
|
+
```typescript
|
|
72
|
+
// Before
|
|
73
|
+
const nodes: MarkdownToJSX.ParserResult[] = parse(markdown)
|
|
74
|
+
|
|
75
|
+
// After
|
|
76
|
+
const nodes: MarkdownToJSX.ASTNode[] = parse(markdown)
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
- Multiple `RuleType` enums consolidated into `RuleType.textFormatted` - If you were checking for `RuleType.textBolded`, `RuleType.textEmphasized`, `RuleType.textMarked`, or `RuleType.textStrikethroughed`, update to check for `RuleType.textFormatted` and inspect the node's boolean flags:
|
|
80
|
+
|
|
81
|
+
```typescript
|
|
82
|
+
// Before
|
|
83
|
+
if (node.type === RuleType.textBolded) { ... }
|
|
84
|
+
|
|
85
|
+
// After
|
|
86
|
+
if (node.type === RuleType.textFormatted && node.bold) { ... }
|
|
87
|
+
```
|
|
88
|
+
|
|
60
89
|
## Installation
|
|
61
90
|
|
|
62
91
|
Install `markdown-to-jsx` with your favorite package manager.
|
|
@@ -573,6 +602,32 @@ compiler('This text has <span>html</span> in it but it won't be rendered', { dis
|
|
|
573
602
|
<span>This text has <span>html</span> in it but it won't be rendered</span>
|
|
574
603
|
```
|
|
575
604
|
|
|
605
|
+
#### options.ast
|
|
606
|
+
|
|
607
|
+
When `ast: true`, the compiler returns the parsed AST structure instead of rendered JSX. **This is the first time the AST is accessible to users!**
|
|
608
|
+
|
|
609
|
+
```tsx
|
|
610
|
+
import { compiler } from 'markdown-to-jsx'
|
|
611
|
+
import type { MarkdownToJSX } from 'markdown-to-jsx'
|
|
612
|
+
|
|
613
|
+
// Get the AST directly
|
|
614
|
+
const ast = compiler('# Hello world', { ast: true })
|
|
615
|
+
|
|
616
|
+
// TypeScript: AST is MarkdownToJSX.AST[]
|
|
617
|
+
console.log(ast) // Array of parsed nodes with types
|
|
618
|
+
|
|
619
|
+
// You can manipulate, transform, or analyze the AST before rendering
|
|
620
|
+
```
|
|
621
|
+
|
|
622
|
+
The AST format is `MarkdownToJSX.AST[]` and enables:
|
|
623
|
+
|
|
624
|
+
- AST manipulation and transformation
|
|
625
|
+
- Custom rendering logic without re-parsing
|
|
626
|
+
- Caching parsed AST for performance
|
|
627
|
+
- Linting or validation of markdown structure
|
|
628
|
+
|
|
629
|
+
When footnotes are present, the returned value will be an object with `ast` and `footnotes` properties instead of just the AST array.
|
|
630
|
+
|
|
576
631
|
### Syntax highlighting
|
|
577
632
|
|
|
578
633
|
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`:
|