Skip to content

Commit c6b45e0

Browse files
committed
stuff
1 parent 6c34787 commit c6b45e0

File tree

13 files changed

+3259
-792
lines changed

13 files changed

+3259
-792
lines changed

README.md

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -878,7 +878,7 @@ _The React code in this entry point is deprecated and will be removed in a futur
878878
For React-specific usage, import from the `/react` entry point:
879879
880880
```tsx
881-
import Markdown, { compiler, parser } from 'markdown-to-jsx/react'
881+
import Markdown, { compiler, parser, astToJSX } from 'markdown-to-jsx/react'
882882

883883
// Use compiler for markdown → JSX
884884
const jsxElement = compiler('# Hello world')
@@ -889,8 +889,9 @@ function App() {
889889
return <Markdown children={markdown} />
890890
}
891891

892-
// Or use parser for total control
892+
// Or use parser + astToJSX for total control
893893
const ast = parser('# Hello world')
894+
const jsxElement2 = astToJSX(ast)
894895
```
895896
896897
### HTML
@@ -959,7 +960,7 @@ Use `parser` when you need:
959960
960961
The Abstract Syntax Tree (AST) is a structured representation of parsed markdown. Each node in the AST has a `type` property that identifies its kind, and type-specific properties.
961962
962-
**Important:** The first node in the AST is typically a `RuleType.refCollection` node that contains all reference definitions found in the document. This node is skipped during rendering but is useful for accessing reference data.
963+
**Important:** The first node in the AST is typically a `RuleType.refCollection` node that contains all reference definitions found in the document, including footnotes (stored with keys prefixed with `^`). This node is skipped during rendering but is useful for accessing reference data. Footnotes are automatically extracted from the refCollection and rendered in a `<footer>` element by both `compiler()` and `astToJSX()`.
963964
964965
### Node Types
965966
@@ -1029,7 +1030,9 @@ The AST consists of the following node types (use `RuleType` to check node types
10291030
- `RuleType.breakLine` - Hard line breaks (` `)
10301031
- `RuleType.breakThematic` - Horizontal rules (`---`)
10311032
- `RuleType.gfmTask` - GFM task list items (`- [ ]`)
1032-
- `RuleType.refCollection` - Reference definitions collection (appears at AST root)
1033+
- `RuleType.refCollection` - Reference definitions collection (appears at AST root, includes footnotes with `^` prefix)
1034+
- `RuleType.footnote` - Footnote definition node (not rendered, stored in refCollection)
1035+
- `RuleType.footnoteReference` - Footnote reference (`[^identifier]`)
10331036
10341037
### Example AST Structure
10351038
@@ -1105,9 +1108,9 @@ if (node.type === RuleType.heading) {
11051108
11061109
**When to use `compiler` vs `parser` vs `<Markdown>`:**
11071110

1108-
- Use `<Markdown>` when you need a simple React component that renders markdown to JSX or HTML.
1109-
- Use `compiler` when you need React JSX or HTML output (the component uses this internally)
1110-
- Use `parser` when you need the AST for custom processing
1111+
- Use `<Markdown>` when you need a simple React component that renders markdown to JSX.
1112+
- Use `compiler` when you need React JSX output from markdown (the component uses this internally).
1113+
- Use `parser` + `astToJSX` when you need the AST for custom processing before rendering to JSX, or just the AST itself.
11111114

11121115
## Changelog
11131116

scripts/benchmark.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ const parseTests = [
9696
name: 'markdown-it [parse]',
9797
fn: input => mdIt.parse(input, {}),
9898
},
99-
{
99+
isAll && {
100100
name: 'marked [parse]',
101101
fn: input => marked.parse(input, {}),
102102
},

scripts/build-plugins.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -246,15 +246,15 @@ function parseInlineSpan(
246246
if (angleBrace) {
247247
trackHit('angleBraceLink')
248248
result.push(angleBrace)
249-
pos = angleBrace.endPos
249+
pos = angleBrace.end
250250
}
251251
252252
trackAttempt('htmlComment')
253253
const comment = parseHTMLComment(source, pos)
254254
if (comment) {
255255
trackHit('htmlComment')
256256
result.push(comment)
257-
pos = comment.endPos
257+
pos = comment.end
258258
}
259259
260260
return result
@@ -314,7 +314,7 @@ function trackHit(key: string): void {
314314
items.push(hasTask
315315
? (trackBlockAttempt('listGfmTask'), trackBlockHit('listGfmTask'), [
316316
task,
317-
...parseContentWithParagraphHandling(actualItemContent.slice(task.endPos), itemHasBlankLine, state, options)
317+
...parseContentWithParagraphHandling(actualItemContent.slice(task.end), itemHasBlankLine, state, options)
318318
])
319319
: parseContentWithParagraphHandling(actualItemContent, itemHasBlankLine, state, options))
320320
`

0 commit comments

Comments
 (0)