@headwall/markdown-to-blocks 1.1.1 → 1.2.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 +14 -1
- package/README.md +2 -0
- package/dist/{chunk-7B766ZGD.js → chunk-CHMDS2SX.js} +67 -6
- package/dist/chunk-CHMDS2SX.js.map +1 -0
- package/dist/cli.js +6 -2
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +7 -0
- package/dist/index.js +1 -1
- package/package.json +5 -2
- package/dist/chunk-7B766ZGD.js.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [1.2.0] - 2026-07-05
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- `headingAnchors` option (CLI `--heading-anchors`): derive an `id` (WordPress
|
|
15
|
+
`anchor` attribute) for each heading from its text, so in-page anchor links
|
|
16
|
+
work. GitHub-style slugs, de-duplicated per document (`overview`,
|
|
17
|
+
`overview-1`, …); a heading that slugs to nothing (only punctuation/emoji)
|
|
18
|
+
gets no `id`. Off by default. Output matches core's serialiser byte-for-byte
|
|
19
|
+
(including `--` attribute escaping) and validates against the
|
|
20
|
+
WordPress parser.
|
|
21
|
+
|
|
10
22
|
## [1.1.1] - 2026-06-29
|
|
11
23
|
|
|
12
24
|
### Fixed
|
|
@@ -66,7 +78,8 @@ parser and confirmed to import into the block editor with no recovery prompts.
|
|
|
66
78
|
- ESM-only. Requires Node ≥ 18.
|
|
67
79
|
- Zero runtime dependencies — all bundled into the published package.
|
|
68
80
|
|
|
69
|
-
[Unreleased]: https://github.com/headwalluk/markdown-to-blocks/compare/v1.
|
|
81
|
+
[Unreleased]: https://github.com/headwalluk/markdown-to-blocks/compare/v1.2.0...HEAD
|
|
82
|
+
[1.2.0]: https://github.com/headwalluk/markdown-to-blocks/compare/v1.1.1...v1.2.0
|
|
70
83
|
[1.1.1]: https://github.com/headwalluk/markdown-to-blocks/compare/v1.1.0...v1.1.1
|
|
71
84
|
[1.1.0]: https://github.com/headwalluk/markdown-to-blocks/compare/v1.0.0...v1.1.0
|
|
72
85
|
[1.0.0]: https://github.com/headwalluk/markdown-to-blocks/releases/tag/v1.0.0
|
package/README.md
CHANGED
|
@@ -102,6 +102,7 @@ Modes:
|
|
|
102
102
|
Conversion options:
|
|
103
103
|
--heading-shift <n> Shift all heading levels by n (default 0)
|
|
104
104
|
--min-heading-level <n> Clamp heading levels to [n, 6] (default 2)
|
|
105
|
+
--heading-anchors Add an id/anchor to each heading from its text
|
|
105
106
|
--code-language <mode> 'drop' (default) or 'class' (emit language-xxx)
|
|
106
107
|
--unsupported <mode> 'html' (default, wrap in core/html) or 'skip'
|
|
107
108
|
--no-gfm Disable GFM (tables, strikethrough, autolinks)
|
|
@@ -161,6 +162,7 @@ Body text.
|
|
|
161
162
|
|---|---|---|---|
|
|
162
163
|
| `headingShift` | `number` | `0` | Shift every heading level by this amount before clamping. |
|
|
163
164
|
| `minHeadingLevel` | `number` | `2` | Clamp resulting heading levels into `[min, 6]`. The default of `2` keeps body content from emitting an `h1`. |
|
|
165
|
+
| `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`. |
|
|
164
166
|
| `resolveImage` | `(src, alt, title?) => ResolvedImage \| undefined` | — | Resolve a Markdown image to a WordPress image (see [Images](#images)). |
|
|
165
167
|
| `codeLanguage` | `'drop' \| 'class'` | `'drop'` | `'drop'` discards the fence language (core behaviour). `'class'` emits `<code class="language-xxx">` for a syntax-highlighting plugin. |
|
|
166
168
|
| `unsupported` | `'html' \| 'skip'` | `'html'` | How to handle raw/unsupported nodes: wrap in `core/html`, or omit. |
|
|
@@ -13,7 +13,11 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
|
|
|
13
13
|
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
14
14
|
});
|
|
15
15
|
var __commonJS = (cb, mod) => function __require2() {
|
|
16
|
-
|
|
16
|
+
try {
|
|
17
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
18
|
+
} catch (e) {
|
|
19
|
+
throw mod = 0, e;
|
|
20
|
+
}
|
|
17
21
|
};
|
|
18
22
|
var __export = (target, all2) => {
|
|
19
23
|
for (var name in all2)
|
|
@@ -19556,11 +19560,36 @@ function renderUnknownInline(node2, options) {
|
|
|
19556
19560
|
return out;
|
|
19557
19561
|
}
|
|
19558
19562
|
|
|
19563
|
+
// src/slug.ts
|
|
19564
|
+
function slugify(text5) {
|
|
19565
|
+
const slug = text5.toLowerCase().replace(/[^\p{L}\p{N}_ -]+/gu, "").replace(/ /g, "-");
|
|
19566
|
+
return slug;
|
|
19567
|
+
}
|
|
19568
|
+
function createHeadingSlugger() {
|
|
19569
|
+
const occurrences = /* @__PURE__ */ new Map();
|
|
19570
|
+
return {
|
|
19571
|
+
slug(text5) {
|
|
19572
|
+
const base = slugify(text5);
|
|
19573
|
+
let result = base;
|
|
19574
|
+
if (base !== "") {
|
|
19575
|
+
while (occurrences.has(result)) {
|
|
19576
|
+
const next = (occurrences.get(base) ?? 0) + 1;
|
|
19577
|
+
occurrences.set(base, next);
|
|
19578
|
+
result = `${base}-${next}`;
|
|
19579
|
+
}
|
|
19580
|
+
occurrences.set(result, 0);
|
|
19581
|
+
}
|
|
19582
|
+
return result;
|
|
19583
|
+
}
|
|
19584
|
+
};
|
|
19585
|
+
}
|
|
19586
|
+
|
|
19559
19587
|
// src/types.ts
|
|
19560
19588
|
function resolveOptions(options) {
|
|
19561
19589
|
return {
|
|
19562
19590
|
headingShift: options?.headingShift ?? 0,
|
|
19563
19591
|
minHeadingLevel: options?.minHeadingLevel ?? 2,
|
|
19592
|
+
headingAnchors: options?.headingAnchors ?? false,
|
|
19564
19593
|
resolveImage: options?.resolveImage,
|
|
19565
19594
|
codeLanguage: options?.codeLanguage ?? "drop",
|
|
19566
19595
|
unsupported: options?.unsupported ?? "html",
|
|
@@ -19635,20 +19664,51 @@ function renderCaption(caption) {
|
|
|
19635
19664
|
return `<figcaption class="wp-element-caption">${escapeText(caption)}</figcaption>`;
|
|
19636
19665
|
}
|
|
19637
19666
|
|
|
19667
|
+
// src/attributes.ts
|
|
19668
|
+
function serializeBlockAttributes(attributes) {
|
|
19669
|
+
let out = "";
|
|
19670
|
+
if (Object.keys(attributes).length > 0) {
|
|
19671
|
+
const json = JSON.stringify(attributes).replace(/--/g, "\\u002d\\u002d").replace(/</g, "\\u003c").replace(/>/g, "\\u003e").replace(/&/g, "\\u0026").replace(/ /g, "\\u00a0");
|
|
19672
|
+
out = ` ${json}`;
|
|
19673
|
+
}
|
|
19674
|
+
return out;
|
|
19675
|
+
}
|
|
19676
|
+
|
|
19638
19677
|
// src/blocks/heading.ts
|
|
19639
19678
|
function renderHeading(node2, ctx) {
|
|
19640
|
-
const { headingShift, minHeadingLevel } = ctx.options;
|
|
19679
|
+
const { headingShift, minHeadingLevel, headingAnchors } = ctx.options;
|
|
19641
19680
|
const shifted = node2.depth + headingShift;
|
|
19642
19681
|
const level = Math.min(6, Math.max(minHeadingLevel, shifted));
|
|
19643
19682
|
const inner = ctx.renderInline(node2.children);
|
|
19644
|
-
const
|
|
19645
|
-
const
|
|
19646
|
-
|
|
19683
|
+
const anchor = headingAnchors ? ctx.slugger.slug(headingText(node2.children)) : "";
|
|
19684
|
+
const attributes = {};
|
|
19685
|
+
if (level !== 2) {
|
|
19686
|
+
attributes.level = level;
|
|
19687
|
+
}
|
|
19688
|
+
if (anchor !== "") {
|
|
19689
|
+
attributes.anchor = anchor;
|
|
19690
|
+
}
|
|
19691
|
+
const idAttr = anchor !== "" ? ` id="${anchor}"` : "";
|
|
19692
|
+
const open = `<!-- wp:heading${serializeBlockAttributes(attributes)} -->`;
|
|
19693
|
+
const tag = `<h${level}${idAttr} class="wp-block-heading">${inner}</h${level}>`;
|
|
19647
19694
|
const close2 = "<!-- /wp:heading -->";
|
|
19648
19695
|
return `${open}
|
|
19649
19696
|
${tag}
|
|
19650
19697
|
${close2}`;
|
|
19651
19698
|
}
|
|
19699
|
+
function headingText(nodes) {
|
|
19700
|
+
let text5 = "";
|
|
19701
|
+
for (const node2 of nodes) {
|
|
19702
|
+
const value2 = node2.value;
|
|
19703
|
+
const children = node2.children;
|
|
19704
|
+
if (typeof value2 === "string") {
|
|
19705
|
+
text5 += value2;
|
|
19706
|
+
} else if (children != null) {
|
|
19707
|
+
text5 += headingText(children);
|
|
19708
|
+
}
|
|
19709
|
+
}
|
|
19710
|
+
return text5;
|
|
19711
|
+
}
|
|
19652
19712
|
|
|
19653
19713
|
// src/blocks/list.ts
|
|
19654
19714
|
function renderList(node2, ctx) {
|
|
@@ -19785,6 +19845,7 @@ function resolveReferences(tree) {
|
|
|
19785
19845
|
function createContext(options) {
|
|
19786
19846
|
const context = {
|
|
19787
19847
|
options,
|
|
19848
|
+
slugger: createHeadingSlugger(),
|
|
19788
19849
|
renderInline(nodes) {
|
|
19789
19850
|
return renderInline(nodes, options);
|
|
19790
19851
|
},
|
|
@@ -19905,4 +19966,4 @@ export {
|
|
|
19905
19966
|
markdownToBlocks,
|
|
19906
19967
|
parseMarkdownDocument
|
|
19907
19968
|
};
|
|
19908
|
-
//# sourceMappingURL=chunk-
|
|
19969
|
+
//# sourceMappingURL=chunk-CHMDS2SX.js.map
|