@headwall/markdown-to-blocks 1.3.0 → 1.4.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/CHANGELOG.md +56 -1
- package/README.md +29 -3
- package/dist/{chunk-FWYKR6IX.js → chunk-26IEHNWU.js} +265 -104
- package/dist/chunk-26IEHNWU.js.map +1 -0
- package/dist/cli.js +65 -18
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +13 -3
- package/dist/index.js +1 -1
- package/package.json +7 -7
- package/dist/chunk-FWYKR6IX.js.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,60 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [1.4.0] - 2026-11-20
|
|
11
|
+
|
|
12
|
+
### Security
|
|
13
|
+
|
|
14
|
+
- **Link and image URLs are now restricted to safe schemes by default**
|
|
15
|
+
(`urlSchemes: 'safe'`). Links keep their `href` only for `http:`, `https:`,
|
|
16
|
+
`mailto:`, `tel:` and relative URLs, otherwise only the link text renders.
|
|
17
|
+
Images need `http:`, `https:` or a relative URL, otherwise they are dropped.
|
|
18
|
+
This covers inline, reference-style and resolver-supplied URLs, and reads
|
|
19
|
+
schemes as a browser does (case, embedded tabs/newlines, leading
|
|
20
|
+
whitespace). `urlSchemes: 'any'` / `--url-schemes any` restores the old
|
|
21
|
+
pass-through.
|
|
22
|
+
- `unsupported: 'skip'` now drops inline HTML too. Previously only block HTML
|
|
23
|
+
was dropped, so inline markup, including a `<!-- wp:… -->` comment that
|
|
24
|
+
injects a block, survived in skip mode.
|
|
25
|
+
- Fenced code blocks now apply core/code's own save-time escaping: `[` becomes
|
|
26
|
+
`[` and the first URL alone on its line has its `//` escaped. Shortcodes
|
|
27
|
+
in code examples previously ran on the front end, and the output didn't match
|
|
28
|
+
what the block editor saves.
|
|
29
|
+
- `resolveImage` must return a positive integer `id`; anything else throws a
|
|
30
|
+
`RangeError`. A malformed id could previously break out of the image's
|
|
31
|
+
`class` attribute.
|
|
32
|
+
- Markdown nesting deeper than 200 levels throws a `RangeError` naming the
|
|
33
|
+
depth, instead of overflowing the call stack (about 3,000 nested `>` was
|
|
34
|
+
enough).
|
|
35
|
+
|
|
36
|
+
### Fixed
|
|
37
|
+
|
|
38
|
+
- Ordered lists that don't start at 1 (`3. Three`) kept their numbering in
|
|
39
|
+
Markdown but were renumbered from 1 in WordPress. They now carry `start` in
|
|
40
|
+
the block attributes and on the `<ol>`, matching core's serialiser.
|
|
41
|
+
- With `codeLanguage: 'class'`, the fence language was written into the `class`
|
|
42
|
+
attribute unescaped, so a language containing `"` broke out of the attribute
|
|
43
|
+
and produced an invalid block. It is now attribute-escaped.
|
|
44
|
+
- A resolver-supplied `sizeSlug` is now escaped in both the `wp:image`
|
|
45
|
+
attributes (as core's serialiser does, so `-->` can't close the comment) and
|
|
46
|
+
the figure's `size-…` class.
|
|
47
|
+
- Invalid options no longer produce invalid markup (`<hNaN>`, `<h0>`). All
|
|
48
|
+
conversion functions now throw a `RangeError` listing every invalid option:
|
|
49
|
+
`headingShift` must be an integer, `minHeadingLevel` an integer from 1 to 6,
|
|
50
|
+
and `codeLanguage` / `unsupported` one of their documented modes. Unknown
|
|
51
|
+
mode strings were previously treated as the default.
|
|
52
|
+
- The CLI no longer silently ignores unknown options, flags missing their
|
|
53
|
+
value, non-integer numbers or extra file arguments. It reports every problem
|
|
54
|
+
together and exits 1 without converting.
|
|
55
|
+
|
|
56
|
+
### Changed
|
|
57
|
+
|
|
58
|
+
- Output is now validated against `@wordpress/block-library` 12 and
|
|
59
|
+
`@wordpress/blocks` 17 (dev-only). Dev tooling refreshed: tsup 9, jsdom 31,
|
|
60
|
+
vitest 5.1. Bundled runtime code is unchanged, and the built JavaScript is
|
|
61
|
+
byte-identical between tsup 8 and 9. Clears a dev-only `undici` advisory
|
|
62
|
+
(via jsdom).
|
|
63
|
+
|
|
10
64
|
## [1.3.0] - 2026-10-06
|
|
11
65
|
|
|
12
66
|
### Fixed
|
|
@@ -98,7 +152,8 @@ parser and confirmed to import into the block editor with no recovery prompts.
|
|
|
98
152
|
- ESM-only. Requires Node ≥ 18.
|
|
99
153
|
- Zero runtime dependencies — all bundled into the published package.
|
|
100
154
|
|
|
101
|
-
[Unreleased]: https://github.com/headwalluk/markdown-to-blocks/compare/v1.
|
|
155
|
+
[Unreleased]: https://github.com/headwalluk/markdown-to-blocks/compare/v1.4.0...HEAD
|
|
156
|
+
[1.4.0]: https://github.com/headwalluk/markdown-to-blocks/compare/v1.3.0...v1.4.0
|
|
102
157
|
[1.3.0]: https://github.com/headwalluk/markdown-to-blocks/compare/v1.2.0...v1.3.0
|
|
103
158
|
[1.2.0]: https://github.com/headwalluk/markdown-to-blocks/compare/v1.1.1...v1.2.0
|
|
104
159
|
[1.1.1]: https://github.com/headwalluk/markdown-to-blocks/compare/v1.1.0...v1.1.1
|
package/README.md
CHANGED
|
@@ -101,10 +101,11 @@ Modes:
|
|
|
101
101
|
|
|
102
102
|
Conversion options:
|
|
103
103
|
--heading-shift <n> Shift all heading levels by n (default 0)
|
|
104
|
-
--min-heading-level <n> Clamp heading levels to [n, 6] (default 2)
|
|
104
|
+
--min-heading-level <n> Clamp heading levels to [n, 6], n from 1 to 6 (default 2)
|
|
105
105
|
--heading-anchors Add an id/anchor to each heading from its text
|
|
106
106
|
--code-language <mode> 'drop' (default) or 'class' (emit language-xxx)
|
|
107
|
-
--unsupported <mode> 'html' (default, wrap in core/html) or 'skip'
|
|
107
|
+
--unsupported <mode> 'html' (default, wrap in core/html) or 'skip' (drop block and inline HTML)
|
|
108
|
+
--url-schemes <mode> 'safe' (default: http(s)/mailto/tel/relative) or 'any'
|
|
108
109
|
--no-gfm Disable GFM (tables, strikethrough, autolinks)
|
|
109
110
|
|
|
110
111
|
-h, --help Show help
|
|
@@ -165,9 +166,12 @@ Body text.
|
|
|
165
166
|
| `headingAnchors` | `boolean` | `false` | Derive an `id` (WordPress `anchor` attribute) for each heading from its text, so in-page anchor links work. GitHub-style slugs, de-duplicated per document (`overview`, `overview-1`, …). A heading that slugs to nothing (only punctuation/emoji) gets no `id`. |
|
|
166
167
|
| `resolveImage` | `(src, alt, title?) => ResolvedImage \| undefined` | — | Resolve a Markdown image to a WordPress image (see [Images](#images)). |
|
|
167
168
|
| `codeLanguage` | `'drop' \| 'class'` | `'drop'` | `'drop'` discards the fence language (core behaviour). `'class'` emits `<code class="language-xxx">` for a syntax-highlighting plugin. |
|
|
168
|
-
| `unsupported` | `'html' \| 'skip'` | `'html'` | How to handle raw
|
|
169
|
+
| `unsupported` | `'html' \| 'skip'` | `'html'` | How to handle raw HTML and unsupported nodes. `'html'`: block HTML goes into `core/html` and inline HTML passes through verbatim. `'skip'`: both are omitted. |
|
|
170
|
+
| `urlSchemes` | `'safe' \| 'any'` | `'safe'` | Restrict link and image URLs to safe schemes (see [URL safety](#url-safety)). `'any'` turns the check off. |
|
|
169
171
|
| `gfm` | `boolean` | `true` | Enable GFM (tables, strikethrough, autolinks). |
|
|
170
172
|
|
|
173
|
+
Invalid option values (a non-integer `headingShift`, a `minHeadingLevel` outside 1–6, an unknown mode string) throw a `RangeError` listing every problem.
|
|
174
|
+
|
|
171
175
|
### `ResolvedImage`
|
|
172
176
|
|
|
173
177
|
```ts
|
|
@@ -200,6 +204,27 @@ const html = markdownToBlocks(markdown, {
|
|
|
200
204
|
|
|
201
205
|
- When `resolveImage` returns an object **with an `id`**, you get the attachment shape: `wp:image {"id":…,"sizeSlug":…,"linkDestination":"none"}`, a `size-<slug>` figure class, and a `wp-image-<id>` class on the `<img>`.
|
|
202
206
|
- When it returns `undefined`, you get the **external** fallback: a plain `<figure class="wp-block-image">` / `<img>` with no attachment id.
|
|
207
|
+
- An `id` must be a positive integer; anything else throws a `RangeError`.
|
|
208
|
+
- The final URL, whether from the Markdown or the resolver, is subject to the [URL safety](#url-safety) policy.
|
|
209
|
+
|
|
210
|
+
---
|
|
211
|
+
|
|
212
|
+
## Untrusted Markdown
|
|
213
|
+
|
|
214
|
+
The converter escapes text correctly, but it is **not an HTML sanitiser**. When the Markdown comes from somewhere you don't control (user input, scraped pages, another model's output):
|
|
215
|
+
|
|
216
|
+
- **Raw HTML passes through by default.** Use `unsupported: 'skip'` to drop both block and inline HTML. WordPress strips unsafe HTML on save only for accounts without the `unfiltered_html` capability, so don't rely on that when posting as an administrator.
|
|
217
|
+
- **Shortcodes in prose still run.** `[gallery]` in a paragraph is rendered by WordPress as a shortcode, exactly as if typed in the editor. Inside fenced code blocks `[` is escaped as `[`, matching what the block editor itself saves, so code examples display literally. Inline code is not escaped: the editor would undo it on the next edit.
|
|
218
|
+
- **Size is the caller's to bound.** Nesting deeper than 200 levels throws a `RangeError`; overall input size is not limited, so cap it before converting if the source is untrusted.
|
|
219
|
+
|
|
220
|
+
### URL safety
|
|
221
|
+
|
|
222
|
+
By default (`urlSchemes: 'safe'`):
|
|
223
|
+
|
|
224
|
+
- **Links** keep their `href` only for `http:`, `https:`, `mailto:`, `tel:` and relative URLs (`/about`, `#top`). Any other scheme (`javascript:`, `data:`, `vbscript:`, …) renders as the link text alone.
|
|
225
|
+
- **Images** need an `http:`, `https:` or relative URL; any other image is dropped.
|
|
226
|
+
|
|
227
|
+
The scheme is read the way a browser reads it, so `JAVASCRIPT:`, `java	script:` and leading whitespace are all caught. Pass `urlSchemes: 'any'` (`--url-schemes any`) to turn the check off.
|
|
203
228
|
|
|
204
229
|
---
|
|
205
230
|
|
|
@@ -237,6 +262,7 @@ By default `headingShift` is `0` and `minHeadingLevel` is `2`, so a body `#` bec
|
|
|
237
262
|
- **No interactive task-list checkboxes** — a glyph is rendered instead.
|
|
238
263
|
- **No media uploads** — your agent uploads and feeds results via `resolveImage`.
|
|
239
264
|
- **No block-theme / Site Editor constructs** (columns, groups, cover, etc.). Core content blocks only.
|
|
265
|
+
- **Nesting is capped at 200 levels** (quotes, lists and inline formatting combined).
|
|
240
266
|
|
|
241
267
|
---
|
|
242
268
|
|
|
@@ -7560,6 +7560,52 @@ var require_dist = __commonJS({
|
|
|
7560
7560
|
}
|
|
7561
7561
|
});
|
|
7562
7562
|
|
|
7563
|
+
// src/types.ts
|
|
7564
|
+
var CODE_LANGUAGE_MODES = ["drop", "class"];
|
|
7565
|
+
var UNSUPPORTED_MODES = ["html", "skip"];
|
|
7566
|
+
var URL_SCHEME_MODES = ["safe", "any"];
|
|
7567
|
+
function applyOptionDefaults(options) {
|
|
7568
|
+
return {
|
|
7569
|
+
headingShift: options?.headingShift ?? 0,
|
|
7570
|
+
minHeadingLevel: options?.minHeadingLevel ?? 2,
|
|
7571
|
+
headingAnchors: options?.headingAnchors ?? false,
|
|
7572
|
+
resolveImage: options?.resolveImage,
|
|
7573
|
+
codeLanguage: options?.codeLanguage ?? "drop",
|
|
7574
|
+
unsupported: options?.unsupported ?? "html",
|
|
7575
|
+
urlSchemes: options?.urlSchemes ?? "safe",
|
|
7576
|
+
gfm: options?.gfm ?? true
|
|
7577
|
+
};
|
|
7578
|
+
}
|
|
7579
|
+
function resolveOptions(options) {
|
|
7580
|
+
const resolved = applyOptionDefaults(options);
|
|
7581
|
+
const problems = validateOptions(resolved);
|
|
7582
|
+
if (problems.length > 0) {
|
|
7583
|
+
throw new RangeError(`invalid options:
|
|
7584
|
+
${problems.join("\n ")}`);
|
|
7585
|
+
}
|
|
7586
|
+
return resolved;
|
|
7587
|
+
}
|
|
7588
|
+
function validateOptions(options) {
|
|
7589
|
+
const problems = [];
|
|
7590
|
+
if (!Number.isInteger(options.headingShift)) {
|
|
7591
|
+
problems.push(`headingShift must be an integer (got ${String(options.headingShift)})`);
|
|
7592
|
+
}
|
|
7593
|
+
const minLevel = options.minHeadingLevel;
|
|
7594
|
+
if (!Number.isInteger(minLevel) || minLevel < 1 || minLevel > 6) {
|
|
7595
|
+
problems.push(`minHeadingLevel must be an integer from 1 to 6 (got ${String(minLevel)})`);
|
|
7596
|
+
}
|
|
7597
|
+
if (!CODE_LANGUAGE_MODES.includes(options.codeLanguage)) {
|
|
7598
|
+
problems.push(`codeLanguage must be 'drop' or 'class' (got ${JSON.stringify(options.codeLanguage)})`);
|
|
7599
|
+
}
|
|
7600
|
+
if (!UNSUPPORTED_MODES.includes(options.unsupported)) {
|
|
7601
|
+
problems.push(`unsupported must be 'html' or 'skip' (got ${JSON.stringify(options.unsupported)})`);
|
|
7602
|
+
}
|
|
7603
|
+
if (!URL_SCHEME_MODES.includes(options.urlSchemes)) {
|
|
7604
|
+
problems.push(`urlSchemes must be 'safe' or 'any' (got ${JSON.stringify(options.urlSchemes)})`);
|
|
7605
|
+
}
|
|
7606
|
+
return problems;
|
|
7607
|
+
}
|
|
7608
|
+
|
|
7563
7609
|
// node_modules/devlop/lib/default.js
|
|
7564
7610
|
function ok() {
|
|
7565
7611
|
}
|
|
@@ -8062,16 +8108,50 @@ var empty = [];
|
|
|
8062
8108
|
var CONTINUE = true;
|
|
8063
8109
|
var EXIT = false;
|
|
8064
8110
|
var SKIP = "skip";
|
|
8065
|
-
function visitParents(tree,
|
|
8111
|
+
function visitParents(tree, testOrEnterOrVisitors, enterOrVisitorsOrReverse, reverse) {
|
|
8112
|
+
if (!tree || typeof tree !== "object") {
|
|
8113
|
+
throw new Error("Unexpected value `" + tree + "` for `tree`, expected node");
|
|
8114
|
+
}
|
|
8115
|
+
let preorder = true;
|
|
8066
8116
|
let check;
|
|
8067
|
-
|
|
8068
|
-
|
|
8069
|
-
|
|
8117
|
+
let visitors;
|
|
8118
|
+
let enter;
|
|
8119
|
+
let exit3;
|
|
8120
|
+
if (typeof enterOrVisitorsOrReverse === "function" || enterOrVisitorsOrReverse && typeof enterOrVisitorsOrReverse === "object") {
|
|
8121
|
+
check = /** @type {Test} */
|
|
8122
|
+
testOrEnterOrVisitors;
|
|
8123
|
+
visitors = enterOrVisitorsOrReverse;
|
|
8124
|
+
if (reverse) preorder = false;
|
|
8125
|
+
} else {
|
|
8126
|
+
visitors = /** @type {Visitors | Visitor} */
|
|
8127
|
+
testOrEnterOrVisitors;
|
|
8128
|
+
if (enterOrVisitorsOrReverse) preorder = false;
|
|
8129
|
+
}
|
|
8130
|
+
if (typeof visitors === "function") {
|
|
8131
|
+
enter = visitors;
|
|
8132
|
+
} else if (visitors && typeof visitors === "object") {
|
|
8133
|
+
if (visitors.enter === null || visitors.enter === void 0) {
|
|
8134
|
+
} else if (typeof visitors.enter === "function") {
|
|
8135
|
+
enter = visitors.enter;
|
|
8136
|
+
} else {
|
|
8137
|
+
throw new Error(
|
|
8138
|
+
"Unexpected value `" + visitors.enter + "` for `visitors.enter`, expected optional visitor"
|
|
8139
|
+
);
|
|
8140
|
+
}
|
|
8141
|
+
if (typeof visitors.exit === "function") {
|
|
8142
|
+
exit3 = visitors.exit;
|
|
8143
|
+
} else {
|
|
8144
|
+
throw new Error(
|
|
8145
|
+
"Unexpected value `" + visitors.exit + "` for `visitors.exit`, expected visitor (pass a visitor directly if you only want an enter visitor)"
|
|
8146
|
+
);
|
|
8147
|
+
}
|
|
8070
8148
|
} else {
|
|
8071
|
-
|
|
8149
|
+
throw new Error(
|
|
8150
|
+
"Unexpected value `" + visitors + "` for `enter` or `visitors`, expected visitor or object with visitors"
|
|
8151
|
+
);
|
|
8072
8152
|
}
|
|
8073
8153
|
const is2 = convert(check);
|
|
8074
|
-
const step =
|
|
8154
|
+
const step = preorder ? 1 : -1;
|
|
8075
8155
|
factory(tree, void 0, [])();
|
|
8076
8156
|
function factory(node2, index2, parents) {
|
|
8077
8157
|
const value2 = (
|
|
@@ -8092,12 +8172,10 @@ function visitParents(tree, test, visitor, reverse) {
|
|
|
8092
8172
|
}
|
|
8093
8173
|
return visit2;
|
|
8094
8174
|
function visit2() {
|
|
8175
|
+
const matches = !check || is2(node2, index2, parents[parents.length - 1] || void 0);
|
|
8095
8176
|
let result = empty;
|
|
8096
|
-
|
|
8097
|
-
|
|
8098
|
-
let grandparents;
|
|
8099
|
-
if (!test || is2(node2, index2, parents[parents.length - 1] || void 0)) {
|
|
8100
|
-
result = toResult(visitor(node2, parents));
|
|
8177
|
+
if (enter && matches) {
|
|
8178
|
+
result = toResult(enter(node2, parents, index2));
|
|
8101
8179
|
if (result[0] === EXIT) {
|
|
8102
8180
|
return result;
|
|
8103
8181
|
}
|
|
@@ -8108,11 +8186,11 @@ function visitParents(tree, test, visitor, reverse) {
|
|
|
8108
8186
|
node2
|
|
8109
8187
|
);
|
|
8110
8188
|
if (nodeAsParent.children && result[0] !== SKIP) {
|
|
8111
|
-
offset = (
|
|
8112
|
-
grandparents = parents
|
|
8189
|
+
let offset = (preorder ? -1 : nodeAsParent.children.length) + step;
|
|
8190
|
+
const grandparents = [...parents, nodeAsParent];
|
|
8113
8191
|
while (offset > -1 && offset < nodeAsParent.children.length) {
|
|
8114
8192
|
const child = nodeAsParent.children[offset];
|
|
8115
|
-
subresult = factory(child, offset, grandparents)();
|
|
8193
|
+
const subresult = factory(child, offset, grandparents)();
|
|
8116
8194
|
if (subresult[0] === EXIT) {
|
|
8117
8195
|
return subresult;
|
|
8118
8196
|
}
|
|
@@ -8120,6 +8198,17 @@ function visitParents(tree, test, visitor, reverse) {
|
|
|
8120
8198
|
}
|
|
8121
8199
|
}
|
|
8122
8200
|
}
|
|
8201
|
+
if (exit3 && matches) {
|
|
8202
|
+
const exitResult = toResult(exit3(node2, parents, index2));
|
|
8203
|
+
if (exitResult[0] === SKIP) {
|
|
8204
|
+
throw new Error(
|
|
8205
|
+
"Unexpected value `" + exitResult[0] + "` from `exit`, expected `CONTINUE`, `EXIT`, index, or nothing"
|
|
8206
|
+
);
|
|
8207
|
+
}
|
|
8208
|
+
if (exitResult[0] === EXIT || typeof exitResult[1] === "number") {
|
|
8209
|
+
return exitResult;
|
|
8210
|
+
}
|
|
8211
|
+
}
|
|
8123
8212
|
return result;
|
|
8124
8213
|
}
|
|
8125
8214
|
}
|
|
@@ -8989,24 +9078,37 @@ function encodeCharacterReference(code3) {
|
|
|
8989
9078
|
}
|
|
8990
9079
|
|
|
8991
9080
|
// node_modules/unist-util-visit/lib/index.js
|
|
8992
|
-
function visit(tree,
|
|
9081
|
+
function visit(tree, testOrEnterOrVisitors, enterOrVisitorsOrReverse, maybeReverse) {
|
|
9082
|
+
let check;
|
|
9083
|
+
let visitors;
|
|
8993
9084
|
let reverse;
|
|
8994
|
-
|
|
8995
|
-
|
|
8996
|
-
|
|
8997
|
-
|
|
8998
|
-
visitor = testOrVisitor;
|
|
8999
|
-
reverse = visitorOrReverse;
|
|
9000
|
-
} else {
|
|
9001
|
-
test = testOrVisitor;
|
|
9002
|
-
visitor = visitorOrReverse;
|
|
9085
|
+
if (typeof enterOrVisitorsOrReverse === "function" || enterOrVisitorsOrReverse && typeof enterOrVisitorsOrReverse === "object") {
|
|
9086
|
+
check = /** @type {Test} */
|
|
9087
|
+
testOrEnterOrVisitors;
|
|
9088
|
+
visitors = enterOrVisitorsOrReverse;
|
|
9003
9089
|
reverse = maybeReverse;
|
|
9090
|
+
} else {
|
|
9091
|
+
visitors = /** @type {Visitor | Visitors} */
|
|
9092
|
+
testOrEnterOrVisitors;
|
|
9093
|
+
reverse = enterOrVisitorsOrReverse;
|
|
9004
9094
|
}
|
|
9005
|
-
|
|
9006
|
-
|
|
9007
|
-
|
|
9008
|
-
|
|
9009
|
-
|
|
9095
|
+
if (typeof visitors === "function") {
|
|
9096
|
+
visitParents(tree, check, wrap(visitors), reverse);
|
|
9097
|
+
} else {
|
|
9098
|
+
visitParents(tree, check, wrapVisitors(visitors), reverse);
|
|
9099
|
+
}
|
|
9100
|
+
}
|
|
9101
|
+
function wrapVisitors(visitors) {
|
|
9102
|
+
if (!visitors || typeof visitors !== "object") return visitors;
|
|
9103
|
+
return {
|
|
9104
|
+
enter: typeof visitors.enter === "function" ? wrap(visitors.enter) : visitors.enter,
|
|
9105
|
+
exit: typeof visitors.exit === "function" ? wrap(visitors.exit) : visitors.exit
|
|
9106
|
+
};
|
|
9107
|
+
}
|
|
9108
|
+
function wrap(visitor) {
|
|
9109
|
+
return overload;
|
|
9110
|
+
function overload(node2, parents, index2) {
|
|
9111
|
+
return visitor(node2, index2, parents[parents.length - 1]);
|
|
9010
9112
|
}
|
|
9011
9113
|
}
|
|
9012
9114
|
|
|
@@ -18284,7 +18386,7 @@ function trough() {
|
|
|
18284
18386
|
}
|
|
18285
18387
|
values = output;
|
|
18286
18388
|
if (fn) {
|
|
18287
|
-
|
|
18389
|
+
wrap2(fn, next)(...output);
|
|
18288
18390
|
} else {
|
|
18289
18391
|
callback(null, ...output);
|
|
18290
18392
|
}
|
|
@@ -18300,7 +18402,7 @@ function trough() {
|
|
|
18300
18402
|
return pipeline;
|
|
18301
18403
|
}
|
|
18302
18404
|
}
|
|
18303
|
-
function
|
|
18405
|
+
function wrap2(middleware, callback) {
|
|
18304
18406
|
let called;
|
|
18305
18407
|
return wrapped;
|
|
18306
18408
|
function wrapped(...parameters) {
|
|
@@ -19630,6 +19732,44 @@ function escapeAttribute(value2) {
|
|
|
19630
19732
|
return escaped;
|
|
19631
19733
|
}
|
|
19632
19734
|
|
|
19735
|
+
// src/url.ts
|
|
19736
|
+
var LINK_SCHEMES = ["http", "https", "mailto", "tel"];
|
|
19737
|
+
var IMAGE_SCHEMES = ["http", "https"];
|
|
19738
|
+
function urlScheme(url) {
|
|
19739
|
+
const normalised = url.replace(/[\t\n\r]/g, "").replace(/^[\u0000- ]+|[\u0000- ]+$/g, "");
|
|
19740
|
+
const match = /^([a-z][a-z0-9+.-]*):/i.exec(normalised);
|
|
19741
|
+
return match?.[1] != null ? match[1].toLowerCase() : null;
|
|
19742
|
+
}
|
|
19743
|
+
function hasAllowedScheme(url, schemes) {
|
|
19744
|
+
const scheme = urlScheme(url);
|
|
19745
|
+
return scheme == null || schemes.includes(scheme);
|
|
19746
|
+
}
|
|
19747
|
+
function isSafeLinkUrl(url) {
|
|
19748
|
+
return hasAllowedScheme(url, LINK_SCHEMES);
|
|
19749
|
+
}
|
|
19750
|
+
function isSafeImageUrl(url) {
|
|
19751
|
+
return hasAllowedScheme(url, IMAGE_SCHEMES);
|
|
19752
|
+
}
|
|
19753
|
+
|
|
19754
|
+
// src/resolve-image.ts
|
|
19755
|
+
function resolveMarkdownImage(node2, options) {
|
|
19756
|
+
const alt = node2.alt ?? "";
|
|
19757
|
+
const resolved = options.resolveImage?.(node2.url, alt, node2.title ?? void 0);
|
|
19758
|
+
const id = resolved?.id;
|
|
19759
|
+
if (id != null && !(Number.isSafeInteger(id) && id > 0)) {
|
|
19760
|
+
throw new RangeError(
|
|
19761
|
+
`resolveImage returned an invalid id for ${JSON.stringify(node2.url)}: expected a positive integer, got ${JSON.stringify(id)}`
|
|
19762
|
+
);
|
|
19763
|
+
}
|
|
19764
|
+
const image2 = {
|
|
19765
|
+
...resolved,
|
|
19766
|
+
url: resolved?.url ?? node2.url,
|
|
19767
|
+
alt: resolved?.alt ?? alt
|
|
19768
|
+
};
|
|
19769
|
+
const allowed = options.urlSchemes === "any" || isSafeImageUrl(image2.url);
|
|
19770
|
+
return allowed ? image2 : null;
|
|
19771
|
+
}
|
|
19772
|
+
|
|
19633
19773
|
// src/inline.ts
|
|
19634
19774
|
function renderInline(nodes, options) {
|
|
19635
19775
|
const parts = [];
|
|
@@ -19666,7 +19806,7 @@ function renderInlineNode(node2, options) {
|
|
|
19666
19806
|
out = renderInlineImage(node2, options);
|
|
19667
19807
|
break;
|
|
19668
19808
|
case "html":
|
|
19669
|
-
out = node2.value;
|
|
19809
|
+
out = options.unsupported === "skip" ? "" : node2.value;
|
|
19670
19810
|
break;
|
|
19671
19811
|
default:
|
|
19672
19812
|
out = renderUnknownInline(node2, options);
|
|
@@ -19675,19 +19815,24 @@ function renderInlineNode(node2, options) {
|
|
|
19675
19815
|
return out;
|
|
19676
19816
|
}
|
|
19677
19817
|
function renderLink(node2, options) {
|
|
19678
|
-
const href = escapeAttribute(node2.url);
|
|
19679
|
-
const title = node2.title != null && node2.title !== "" ? ` title="${escapeAttribute(node2.title)}"` : "";
|
|
19680
19818
|
const inner = renderInline(node2.children, options);
|
|
19681
|
-
|
|
19819
|
+
let out = inner;
|
|
19820
|
+
if (options.urlSchemes === "any" || isSafeLinkUrl(node2.url)) {
|
|
19821
|
+
const href = escapeAttribute(node2.url);
|
|
19822
|
+
const title = node2.title != null && node2.title !== "" ? ` title="${escapeAttribute(node2.title)}"` : "";
|
|
19823
|
+
out = `<a href="${href}"${title}>${inner}</a>`;
|
|
19824
|
+
}
|
|
19825
|
+
return out;
|
|
19682
19826
|
}
|
|
19683
19827
|
function renderInlineImage(node2, options) {
|
|
19684
|
-
const
|
|
19685
|
-
|
|
19686
|
-
|
|
19687
|
-
|
|
19688
|
-
|
|
19689
|
-
|
|
19690
|
-
|
|
19828
|
+
const image2 = resolveMarkdownImage(node2, options);
|
|
19829
|
+
let out = "";
|
|
19830
|
+
if (image2 != null) {
|
|
19831
|
+
const altAttr = ` alt="${escapeAttribute(image2.alt ?? "")}"`;
|
|
19832
|
+
const idClass = image2.id != null ? ` class="wp-image-${image2.id}"` : "";
|
|
19833
|
+
out = `<img src="${escapeAttribute(image2.url)}"${altAttr}${idClass}/>`;
|
|
19834
|
+
}
|
|
19835
|
+
return out;
|
|
19691
19836
|
}
|
|
19692
19837
|
function renderUnknownInline(node2, options) {
|
|
19693
19838
|
let out = "";
|
|
@@ -19725,31 +19870,22 @@ function createHeadingSlugger() {
|
|
|
19725
19870
|
};
|
|
19726
19871
|
}
|
|
19727
19872
|
|
|
19728
|
-
// src/types.ts
|
|
19729
|
-
function resolveOptions(options) {
|
|
19730
|
-
return {
|
|
19731
|
-
headingShift: options?.headingShift ?? 0,
|
|
19732
|
-
minHeadingLevel: options?.minHeadingLevel ?? 2,
|
|
19733
|
-
headingAnchors: options?.headingAnchors ?? false,
|
|
19734
|
-
resolveImage: options?.resolveImage,
|
|
19735
|
-
codeLanguage: options?.codeLanguage ?? "drop",
|
|
19736
|
-
unsupported: options?.unsupported ?? "html",
|
|
19737
|
-
gfm: options?.gfm ?? true
|
|
19738
|
-
};
|
|
19739
|
-
}
|
|
19740
|
-
|
|
19741
19873
|
// src/blocks/code.ts
|
|
19742
19874
|
function renderCode(node2, ctx) {
|
|
19743
|
-
const body = escapeCode(node2.value);
|
|
19875
|
+
const body = escapeShortcodesAndEmbeds(escapeCode(node2.value));
|
|
19744
19876
|
let codeOpen = "<code>";
|
|
19745
19877
|
if (ctx.options.codeLanguage === "class" && node2.lang) {
|
|
19746
|
-
codeOpen = `<code class="language-${node2.lang}">`;
|
|
19878
|
+
codeOpen = `<code class="language-${escapeAttribute(node2.lang)}">`;
|
|
19747
19879
|
}
|
|
19748
19880
|
const inner = `<pre class="wp-block-code">${codeOpen}${body}</code></pre>`;
|
|
19749
19881
|
return `<!-- wp:code -->
|
|
19750
19882
|
${inner}
|
|
19751
19883
|
<!-- /wp:code -->`;
|
|
19752
19884
|
}
|
|
19885
|
+
function escapeShortcodesAndEmbeds(html2) {
|
|
19886
|
+
const escaped = html2.replace(/\[/g, "[").replace(/^(\s*https?:)\/\/([^\s<>"]+\s*)$/m, "$1//$2");
|
|
19887
|
+
return escaped;
|
|
19888
|
+
}
|
|
19753
19889
|
|
|
19754
19890
|
// src/blocks/html.ts
|
|
19755
19891
|
function renderHtml(node2, ctx) {
|
|
@@ -19761,38 +19897,43 @@ ${node2.value}
|
|
|
19761
19897
|
<!-- /wp:html -->`;
|
|
19762
19898
|
}
|
|
19763
19899
|
|
|
19900
|
+
// src/attributes.ts
|
|
19901
|
+
function serializeBlockAttributes(attributes) {
|
|
19902
|
+
let out = "";
|
|
19903
|
+
if (Object.keys(attributes).length > 0) {
|
|
19904
|
+
const json = JSON.stringify(attributes).replace(/--/g, "\\u002d\\u002d").replace(/</g, "\\u003c").replace(/>/g, "\\u003e").replace(/&/g, "\\u0026").replace(/ /g, "\\u00a0");
|
|
19905
|
+
out = ` ${json}`;
|
|
19906
|
+
}
|
|
19907
|
+
return out;
|
|
19908
|
+
}
|
|
19909
|
+
|
|
19764
19910
|
// src/blocks/image.ts
|
|
19765
19911
|
function renderImage(node2, ctx) {
|
|
19766
|
-
const
|
|
19767
|
-
|
|
19768
|
-
|
|
19769
|
-
|
|
19770
|
-
|
|
19771
|
-
|
|
19772
|
-
return resolved != null && resolved.id != null ? renderLibraryImage(resolved, alt) : renderExternalImage(resolved, node2.url, alt);
|
|
19912
|
+
const image2 = resolveMarkdownImage(node2, ctx.options);
|
|
19913
|
+
let out = null;
|
|
19914
|
+
if (image2 != null) {
|
|
19915
|
+
out = image2.id != null ? renderLibraryImage(image2, image2.id) : renderExternalImage(image2);
|
|
19916
|
+
}
|
|
19917
|
+
return out;
|
|
19773
19918
|
}
|
|
19774
|
-
function renderLibraryImage(
|
|
19775
|
-
const
|
|
19776
|
-
const altText = resolved.alt ?? fallbackAlt;
|
|
19777
|
-
const sizeSlug = resolved.sizeSlug;
|
|
19919
|
+
function renderLibraryImage(image2, id) {
|
|
19920
|
+
const sizeSlug = image2.sizeSlug;
|
|
19778
19921
|
const attrs = { id };
|
|
19779
19922
|
if (sizeSlug != null) {
|
|
19780
19923
|
attrs.sizeSlug = sizeSlug;
|
|
19781
19924
|
}
|
|
19782
19925
|
attrs.linkDestination = "none";
|
|
19783
|
-
const figureClass = sizeSlug != null ? `wp-block-image size-${sizeSlug}` : "wp-block-image";
|
|
19784
|
-
const img = `<img src="${escapeAttribute(
|
|
19785
|
-
const caption = renderCaption(
|
|
19926
|
+
const figureClass = sizeSlug != null ? `wp-block-image size-${escapeAttribute(sizeSlug)}` : "wp-block-image";
|
|
19927
|
+
const img = `<img src="${escapeAttribute(image2.url)}" alt="${escapeAttribute(image2.alt ?? "")}" class="wp-image-${id}"/>`;
|
|
19928
|
+
const caption = renderCaption(image2.caption);
|
|
19786
19929
|
const inner = `<figure class="${figureClass}">${img}${caption}</figure>`;
|
|
19787
|
-
return `<!-- wp:image
|
|
19930
|
+
return `<!-- wp:image${serializeBlockAttributes(attrs)} -->
|
|
19788
19931
|
${inner}
|
|
19789
19932
|
<!-- /wp:image -->`;
|
|
19790
19933
|
}
|
|
19791
|
-
function renderExternalImage(
|
|
19792
|
-
const
|
|
19793
|
-
const
|
|
19794
|
-
const img = `<img src="${escapeAttribute(url)}" alt="${escapeAttribute(altText)}"/>`;
|
|
19795
|
-
const caption = renderCaption(resolved?.caption);
|
|
19934
|
+
function renderExternalImage(image2) {
|
|
19935
|
+
const img = `<img src="${escapeAttribute(image2.url)}" alt="${escapeAttribute(image2.alt ?? "")}"/>`;
|
|
19936
|
+
const caption = renderCaption(image2.caption);
|
|
19796
19937
|
const inner = `<figure class="wp-block-image">${img}${caption}</figure>`;
|
|
19797
19938
|
return `<!-- wp:image -->
|
|
19798
19939
|
${inner}
|
|
@@ -19805,16 +19946,6 @@ function renderCaption(caption) {
|
|
|
19805
19946
|
return `<figcaption class="wp-element-caption">${escapeText(caption)}</figcaption>`;
|
|
19806
19947
|
}
|
|
19807
19948
|
|
|
19808
|
-
// src/attributes.ts
|
|
19809
|
-
function serializeBlockAttributes(attributes) {
|
|
19810
|
-
let out = "";
|
|
19811
|
-
if (Object.keys(attributes).length > 0) {
|
|
19812
|
-
const json = JSON.stringify(attributes).replace(/--/g, "\\u002d\\u002d").replace(/</g, "\\u003c").replace(/>/g, "\\u003e").replace(/&/g, "\\u0026").replace(/ /g, "\\u00a0");
|
|
19813
|
-
out = ` ${json}`;
|
|
19814
|
-
}
|
|
19815
|
-
return out;
|
|
19816
|
-
}
|
|
19817
|
-
|
|
19818
19949
|
// src/blocks/heading.ts
|
|
19819
19950
|
function renderHeading(node2, ctx) {
|
|
19820
19951
|
const { headingShift, minHeadingLevel, headingAnchors } = ctx.options;
|
|
@@ -19854,12 +19985,21 @@ function headingText(nodes) {
|
|
|
19854
19985
|
// src/blocks/list.ts
|
|
19855
19986
|
function renderList(node2, ctx) {
|
|
19856
19987
|
const tag = node2.ordered ? "ol" : "ul";
|
|
19857
|
-
const
|
|
19988
|
+
const attributes = {};
|
|
19989
|
+
let startAttr = "";
|
|
19990
|
+
if (node2.ordered) {
|
|
19991
|
+
attributes.ordered = true;
|
|
19992
|
+
if (node2.start != null && node2.start !== 1) {
|
|
19993
|
+
attributes.start = node2.start;
|
|
19994
|
+
startAttr = ` start="${node2.start}"`;
|
|
19995
|
+
}
|
|
19996
|
+
}
|
|
19997
|
+
const attrs = serializeBlockAttributes(attributes);
|
|
19858
19998
|
const items = [];
|
|
19859
19999
|
for (const child of node2.children) {
|
|
19860
20000
|
items.push(renderListItem(child, ctx));
|
|
19861
20001
|
}
|
|
19862
|
-
const inner = `<${tag} class="wp-block-list">${items.join("\n\n")}</${tag}>`;
|
|
20002
|
+
const inner = `<${tag}${startAttr} class="wp-block-list">${items.join("\n\n")}</${tag}>`;
|
|
19863
20003
|
return `<!-- wp:list${attrs} -->
|
|
19864
20004
|
${inner}
|
|
19865
20005
|
<!-- /wp:list -->`;
|
|
@@ -19947,14 +20087,35 @@ function renderRow(row, cellTag, ctx) {
|
|
|
19947
20087
|
}
|
|
19948
20088
|
|
|
19949
20089
|
// src/convert.ts
|
|
20090
|
+
var MAX_NESTING_DEPTH = 200;
|
|
19950
20091
|
function parseMarkdown(markdown, options) {
|
|
19951
20092
|
const base = unified().use(remarkParse).use(remarkFrontmatter, ["yaml"]);
|
|
19952
20093
|
const processor = options.gfm ? base.use(remarkGfm) : base;
|
|
19953
20094
|
const tree = processor.parse(markdown);
|
|
19954
20095
|
const root2 = processor.runSync(tree);
|
|
20096
|
+
const depth = maxDepth(root2);
|
|
20097
|
+
if (depth > MAX_NESTING_DEPTH) {
|
|
20098
|
+
throw new RangeError(
|
|
20099
|
+
`Markdown nests ${depth} levels deep; the limit is ${MAX_NESTING_DEPTH}`
|
|
20100
|
+
);
|
|
20101
|
+
}
|
|
19955
20102
|
resolveReferences(root2);
|
|
19956
20103
|
return root2;
|
|
19957
20104
|
}
|
|
20105
|
+
function maxDepth(root2) {
|
|
20106
|
+
let deepest = 0;
|
|
20107
|
+
const pending = [{ node: root2, depth: 0 }];
|
|
20108
|
+
let entry = pending.pop();
|
|
20109
|
+
while (entry != null) {
|
|
20110
|
+
deepest = Math.max(deepest, entry.depth);
|
|
20111
|
+
const children = entry.node.children ?? [];
|
|
20112
|
+
for (const child of children) {
|
|
20113
|
+
pending.push({ node: child, depth: entry.depth + 1 });
|
|
20114
|
+
}
|
|
20115
|
+
entry = pending.pop();
|
|
20116
|
+
}
|
|
20117
|
+
return deepest;
|
|
20118
|
+
}
|
|
19958
20119
|
function resolveReferences(tree) {
|
|
19959
20120
|
const definitions = /* @__PURE__ */ new Map();
|
|
19960
20121
|
visit(tree, "definition", (node2) => {
|
|
@@ -19962,25 +20123,23 @@ function resolveReferences(tree) {
|
|
|
19962
20123
|
});
|
|
19963
20124
|
visit(tree, "linkReference", (node2) => {
|
|
19964
20125
|
const def = definitions.get(node2.identifier);
|
|
19965
|
-
if (def
|
|
19966
|
-
|
|
20126
|
+
if (def != null) {
|
|
20127
|
+
const link2 = node2;
|
|
20128
|
+
link2.type = "link";
|
|
20129
|
+
link2.url = def.url;
|
|
20130
|
+
link2.title = def.title ?? null;
|
|
19967
20131
|
}
|
|
19968
|
-
const link2 = node2;
|
|
19969
|
-
link2.type = "link";
|
|
19970
|
-
link2.url = def.url;
|
|
19971
|
-
link2.title = def.title ?? null;
|
|
19972
20132
|
});
|
|
19973
20133
|
visit(tree, "imageReference", (node2) => {
|
|
19974
20134
|
const def = definitions.get(node2.identifier);
|
|
19975
|
-
if (def
|
|
19976
|
-
|
|
20135
|
+
if (def != null) {
|
|
20136
|
+
const alt = node2.alt ?? "";
|
|
20137
|
+
const image2 = node2;
|
|
20138
|
+
image2.type = "image";
|
|
20139
|
+
image2.url = def.url;
|
|
20140
|
+
image2.title = def.title ?? null;
|
|
20141
|
+
image2.alt = alt;
|
|
19977
20142
|
}
|
|
19978
|
-
const alt = node2.alt ?? "";
|
|
19979
|
-
const image2 = node2;
|
|
19980
|
-
image2.type = "image";
|
|
19981
|
-
image2.url = def.url;
|
|
19982
|
-
image2.title = def.title ?? null;
|
|
19983
|
-
image2.alt = alt;
|
|
19984
20143
|
});
|
|
19985
20144
|
}
|
|
19986
20145
|
function createContext(options) {
|
|
@@ -20103,8 +20262,10 @@ function parseFrontmatter(value2) {
|
|
|
20103
20262
|
}
|
|
20104
20263
|
|
|
20105
20264
|
export {
|
|
20265
|
+
applyOptionDefaults,
|
|
20266
|
+
validateOptions,
|
|
20106
20267
|
markdownToBlockList,
|
|
20107
20268
|
markdownToBlocks,
|
|
20108
20269
|
parseMarkdownDocument
|
|
20109
20270
|
};
|
|
20110
|
-
//# sourceMappingURL=chunk-
|
|
20271
|
+
//# sourceMappingURL=chunk-26IEHNWU.js.map
|