@dogsbay/format-dogsbay-md 0.2.0-beta.1 → 0.2.0-beta.100
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/dist/attributes.d.ts +16 -1
- package/dist/attributes.d.ts.map +1 -1
- package/dist/attributes.js +14 -2
- package/dist/attributes.js.map +1 -1
- package/dist/browser.d.ts +22 -0
- package/dist/browser.d.ts.map +1 -0
- package/dist/browser.js +21 -0
- package/dist/browser.js.map +1 -0
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +147 -27
- package/dist/cli.js.map +1 -1
- package/dist/code-regions.d.ts +89 -0
- package/dist/code-regions.d.ts.map +1 -0
- package/dist/code-regions.js +215 -0
- package/dist/code-regions.js.map +1 -0
- package/dist/directive-guard.d.ts +11 -0
- package/dist/directive-guard.d.ts.map +1 -0
- package/dist/directive-guard.js +16 -0
- package/dist/directive-guard.js.map +1 -0
- package/dist/directive-preserve.d.ts +66 -0
- package/dist/directive-preserve.d.ts.map +1 -0
- package/dist/directive-preserve.js +410 -0
- package/dist/directive-preserve.js.map +1 -0
- package/dist/directives.js +23 -1
- package/dist/directives.js.map +1 -1
- package/dist/escape.d.ts +46 -3
- package/dist/escape.d.ts.map +1 -1
- package/dist/escape.js +83 -26
- package/dist/escape.js.map +1 -1
- package/dist/frontmatter.d.ts +12 -0
- package/dist/frontmatter.d.ts.map +1 -0
- package/dist/frontmatter.js +67 -0
- package/dist/frontmatter.js.map +1 -0
- package/dist/headings.d.ts +50 -0
- package/dist/headings.d.ts.map +1 -0
- package/dist/headings.js +116 -0
- package/dist/headings.js.map +1 -0
- package/dist/index.d.ts +7 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -1
- package/dist/index.js.map +1 -1
- package/dist/inline.d.ts +0 -3
- package/dist/inline.d.ts.map +1 -1
- package/dist/inline.js +221 -7
- package/dist/inline.js.map +1 -1
- package/dist/minja-mask.d.ts +64 -0
- package/dist/minja-mask.d.ts.map +1 -0
- package/dist/minja-mask.js +128 -0
- package/dist/minja-mask.js.map +1 -0
- package/dist/nav-file.d.ts +26 -3
- package/dist/nav-file.d.ts.map +1 -1
- package/dist/nav-file.js +84 -12
- package/dist/nav-file.js.map +1 -1
- package/dist/nav.d.ts +7 -0
- package/dist/nav.d.ts.map +1 -1
- package/dist/nav.js +14 -2
- package/dist/nav.js.map +1 -1
- package/dist/parse.d.ts +12 -1
- package/dist/parse.d.ts.map +1 -1
- package/dist/parse.js +505 -15
- package/dist/parse.js.map +1 -1
- package/dist/plugin-containers.d.ts +1 -1
- package/dist/plugin-containers.d.ts.map +1 -1
- package/dist/plugin-containers.js +22 -1
- package/dist/plugin-containers.js.map +1 -1
- package/dist/plugin-math.d.ts +23 -0
- package/dist/plugin-math.d.ts.map +1 -0
- package/dist/plugin-math.js +91 -0
- package/dist/plugin-math.js.map +1 -0
- package/dist/renderers/diagrams.d.ts +25 -0
- package/dist/renderers/diagrams.d.ts.map +1 -0
- package/dist/renderers/diagrams.js +71 -0
- package/dist/renderers/diagrams.js.map +1 -0
- package/dist/renderers/mermaid.d.ts +24 -0
- package/dist/renderers/mermaid.d.ts.map +1 -0
- package/dist/renderers/mermaid.js +135 -0
- package/dist/renderers/mermaid.js.map +1 -0
- package/dist/serialize.d.ts +1 -1
- package/dist/serialize.d.ts.map +1 -1
- package/dist/serialize.js +352 -37
- package/dist/serialize.js.map +1 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +18 -1
- package/dist/types.js.map +1 -1
- package/dist/yaml.d.ts.map +1 -1
- package/dist/yaml.js +6 -0
- package/dist/yaml.js.map +1 -1
- package/package.json +20 -11
package/dist/attributes.d.ts
CHANGED
|
@@ -8,12 +8,27 @@
|
|
|
8
8
|
export interface RenderedAttrs {
|
|
9
9
|
id?: string;
|
|
10
10
|
classes?: string[];
|
|
11
|
-
|
|
11
|
+
/**
|
|
12
|
+
* Props captured from `TreeNode.props`. Primitive values (string,
|
|
13
|
+
* number, boolean) round-trip through inline `{key="value"}` form.
|
|
14
|
+
* Arrays / plain objects are preserved here too — `renderAttrs`
|
|
15
|
+
* skips them (inline form can't represent them) but the
|
|
16
|
+
* directive renderer's `shouldUseYaml` branch picks them up and
|
|
17
|
+
* routes the directive to YAML body form, where complex values
|
|
18
|
+
* survive intact.
|
|
19
|
+
*/
|
|
20
|
+
props?: Record<string, unknown>;
|
|
12
21
|
}
|
|
13
22
|
/**
|
|
14
23
|
* Render an attribute block.
|
|
15
24
|
* Returns `{ #id .a .b key="value" }` or "" if no attrs.
|
|
16
25
|
* Leading space included so callers can append directly to content.
|
|
26
|
+
*
|
|
27
|
+
* Inline form can only carry primitive values. Arrays / objects in
|
|
28
|
+
* `props` are silently skipped here — the caller is expected to have
|
|
29
|
+
* already routed those to YAML body form (see `shouldUseYaml` in
|
|
30
|
+
* directives.ts). If a non-primitive does reach this point, dropping
|
|
31
|
+
* it is the safest fallback (there's no inline syntax for it).
|
|
17
32
|
*/
|
|
18
33
|
export declare function renderAttrs(attrs: RenderedAttrs): string;
|
|
19
34
|
/**
|
package/dist/attributes.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"attributes.d.ts","sourceRoot":"","sources":["../src/attributes.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,MAAM,WAAW,aAAa;IAC5B,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,
|
|
1
|
+
{"version":3,"file":"attributes.d.ts","sourceRoot":"","sources":["../src/attributes.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,MAAM,WAAW,aAAa;IAC5B,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB;;;;;;;;OAQG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACjC;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,aAAa,GAAG,MAAM,CA6BxD;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAGrD;AAED;;;;;GAKG;AACH,wBAAgB,UAAU,CACxB,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,EAC1C,WAAW,GAAE,MAAM,EAAO,GACzB,aAAa,CAiCf"}
|
package/dist/attributes.js
CHANGED
|
@@ -9,6 +9,12 @@
|
|
|
9
9
|
* Render an attribute block.
|
|
10
10
|
* Returns `{ #id .a .b key="value" }` or "" if no attrs.
|
|
11
11
|
* Leading space included so callers can append directly to content.
|
|
12
|
+
*
|
|
13
|
+
* Inline form can only carry primitive values. Arrays / objects in
|
|
14
|
+
* `props` are silently skipped here — the caller is expected to have
|
|
15
|
+
* already routed those to YAML body form (see `shouldUseYaml` in
|
|
16
|
+
* directives.ts). If a non-primitive does reach this point, dropping
|
|
17
|
+
* it is the safest fallback (there's no inline syntax for it).
|
|
12
18
|
*/
|
|
13
19
|
export function renderAttrs(attrs) {
|
|
14
20
|
const parts = [];
|
|
@@ -29,6 +35,10 @@ export function renderAttrs(attrs) {
|
|
|
29
35
|
parts.push(key);
|
|
30
36
|
continue;
|
|
31
37
|
}
|
|
38
|
+
// Skip arrays / plain objects — inline form can't represent
|
|
39
|
+
// them. They survive via the YAML body branch upstream.
|
|
40
|
+
if (typeof value === "object")
|
|
41
|
+
continue;
|
|
32
42
|
parts.push(`${key}=${escapeAttrValue(String(value))}`);
|
|
33
43
|
}
|
|
34
44
|
}
|
|
@@ -71,8 +81,10 @@ export function splitProps(props, excludeKeys = []) {
|
|
|
71
81
|
}
|
|
72
82
|
if (value === null || value === undefined)
|
|
73
83
|
continue;
|
|
74
|
-
|
|
75
|
-
|
|
84
|
+
// Pass arrays / objects through. Inline-form rendering will skip
|
|
85
|
+
// them (`renderAttrs`); YAML-body rendering preserves them
|
|
86
|
+
// (`attrsToYaml`). The `shouldUseYaml` heuristic in directives.ts
|
|
87
|
+
// detects their presence and routes the directive accordingly.
|
|
76
88
|
cleanProps[key] = value;
|
|
77
89
|
}
|
|
78
90
|
if (Object.keys(cleanProps).length > 0) {
|
package/dist/attributes.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"attributes.js","sourceRoot":"","sources":["../src/attributes.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;
|
|
1
|
+
{"version":3,"file":"attributes.js","sourceRoot":"","sources":["../src/attributes.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAiBH;;;;;;;;;;GAUG;AACH,MAAM,UAAU,WAAW,CAAC,KAAoB;IAC9C,MAAM,KAAK,GAAa,EAAE,CAAC;IAE3B,IAAI,KAAK,CAAC,EAAE,EAAE,CAAC;QACb,KAAK,CAAC,IAAI,CAAC,IAAI,KAAK,CAAC,EAAE,EAAE,CAAC,CAAC;IAC7B,CAAC;IAED,IAAI,KAAK,CAAC,OAAO,EAAE,CAAC;QAClB,KAAK,MAAM,GAAG,IAAI,KAAK,CAAC,OAAO,EAAE,CAAC;YAChC,IAAI,GAAG;gBAAE,KAAK,CAAC,IAAI,CAAC,IAAI,GAAG,EAAE,CAAC,CAAC;QACjC,CAAC;IACH,CAAC;IAED,IAAI,KAAK,CAAC,KAAK,EAAE,CAAC;QAChB,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC;YACvD,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,KAAK;gBAAE,SAAS;YACvE,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;gBACnB,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;gBAChB,SAAS;YACX,CAAC;YACD,4DAA4D;YAC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,OAAO,IAAI,GAAG,KAAK,WAAW,CAAC,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;YAC1E,MAAM,CAAC,OAAO,GAAG,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;YACpD,SAAS;QACX,CAAC;QAED,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS;YAAE,SAAS;QACpD,iEAAiE;QACjE,2DAA2D;QAC3D,kEAAkE;QAClE,+DAA+D;QAC/D,UAAU,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;IAC1B,CAAC;IAED,IAAI,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACvC,MAAM,CAAC,KAAK,GAAG,UAAU,CAAC;IAC5B,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Browser-safe entry point — the pure TreeNode round-trip and text
|
|
3
|
+
* helpers, with NO `node:fs` in the module graph.
|
|
4
|
+
*
|
|
5
|
+
* The main barrel (`.`) re-exports nav / nav-file / mermaid, which
|
|
6
|
+
* import `node:fs` at module load and so break browser/extension
|
|
7
|
+
* bundling. Consumers that only need parse/serialize (the editing
|
|
8
|
+
* engine, extension contexts) import from `@dogsbay/format-dogsbay-md/browser`
|
|
9
|
+
* instead. `parse.ts` and `serialize.ts` transit only browser-safe deps
|
|
10
|
+
* (markdown-it, js-yaml). Frontmatter is split by the local `frontmatter.ts`
|
|
11
|
+
* (js-yaml only) rather than gray-matter, whose entry `require('fs')`s at
|
|
12
|
+
* module load and would drag `node:fs` back into this graph.
|
|
13
|
+
*/
|
|
14
|
+
export { dogsbayMdToTree, parseInline, type ParseResult, type ParseOptions } from "./parse.js";
|
|
15
|
+
export { treeToDogsbayMd, nodeToDogsbayMd } from "./serialize.js";
|
|
16
|
+
export type { SerializeOptions } from "./types.js";
|
|
17
|
+
export { inlineToDogsbayMd } from "./inline.js";
|
|
18
|
+
export { transformCodeRegions, transformProseLines, transformProseSegments, fenceOpenBefore, createFenceTracker, } from "./code-regions.js";
|
|
19
|
+
export { maskMinjaInCode, unmaskMinjaInCode, maskAllMinjaOpeners, isMinjaProcessedFence, stripInlineMinjaMarkers, stripFenceMinjaMarkers } from "./minja-mask.js";
|
|
20
|
+
export { extractHeadings, slugifyHeadingText, type HeadingInfo } from "./headings.js";
|
|
21
|
+
export { splitFrontmatter, type Frontmatter } from "./frontmatter.js";
|
|
22
|
+
//# sourceMappingURL=browser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browser.d.ts","sourceRoot":"","sources":["../src/browser.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,KAAK,WAAW,EAAE,KAAK,YAAY,EAAE,MAAM,YAAY,CAAC;AAC/F,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAClE,YAAY,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AACnD,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EACL,oBAAoB,EACpB,mBAAmB,EACnB,sBAAsB,EACtB,eAAe,EACf,kBAAkB,GACnB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,uBAAuB,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AAClK,OAAO,EAAE,eAAe,EAAE,kBAAkB,EAAE,KAAK,WAAW,EAAE,MAAM,eAAe,CAAC;AACtF,OAAO,EAAE,gBAAgB,EAAE,KAAK,WAAW,EAAE,MAAM,kBAAkB,CAAC"}
|
package/dist/browser.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Browser-safe entry point — the pure TreeNode round-trip and text
|
|
3
|
+
* helpers, with NO `node:fs` in the module graph.
|
|
4
|
+
*
|
|
5
|
+
* The main barrel (`.`) re-exports nav / nav-file / mermaid, which
|
|
6
|
+
* import `node:fs` at module load and so break browser/extension
|
|
7
|
+
* bundling. Consumers that only need parse/serialize (the editing
|
|
8
|
+
* engine, extension contexts) import from `@dogsbay/format-dogsbay-md/browser`
|
|
9
|
+
* instead. `parse.ts` and `serialize.ts` transit only browser-safe deps
|
|
10
|
+
* (markdown-it, js-yaml). Frontmatter is split by the local `frontmatter.ts`
|
|
11
|
+
* (js-yaml only) rather than gray-matter, whose entry `require('fs')`s at
|
|
12
|
+
* module load and would drag `node:fs` back into this graph.
|
|
13
|
+
*/
|
|
14
|
+
export { dogsbayMdToTree, parseInline } from "./parse.js";
|
|
15
|
+
export { treeToDogsbayMd, nodeToDogsbayMd } from "./serialize.js";
|
|
16
|
+
export { inlineToDogsbayMd } from "./inline.js";
|
|
17
|
+
export { transformCodeRegions, transformProseLines, transformProseSegments, fenceOpenBefore, createFenceTracker, } from "./code-regions.js";
|
|
18
|
+
export { maskMinjaInCode, unmaskMinjaInCode, maskAllMinjaOpeners, isMinjaProcessedFence, stripInlineMinjaMarkers, stripFenceMinjaMarkers } from "./minja-mask.js";
|
|
19
|
+
export { extractHeadings, slugifyHeadingText } from "./headings.js";
|
|
20
|
+
export { splitFrontmatter } from "./frontmatter.js";
|
|
21
|
+
//# sourceMappingURL=browser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browser.js","sourceRoot":"","sources":["../src/browser.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,EAAE,eAAe,EAAE,WAAW,EAAuC,MAAM,YAAY,CAAC;AAC/F,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAElE,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EACL,oBAAoB,EACpB,mBAAmB,EACnB,sBAAsB,EACtB,eAAe,EACf,kBAAkB,GACnB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,uBAAuB,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AAClK,OAAO,EAAE,eAAe,EAAE,kBAAkB,EAAoB,MAAM,eAAe,CAAC;AACtF,OAAO,EAAE,gBAAgB,EAAoB,MAAM,kBAAkB,CAAC"}
|
package/dist/cli.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,YAAY,
|
|
1
|
+
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,YAAY,EAA8C,MAAM,gBAAgB,CAAC;AA0Q/F,eAAO,MAAM,MAAM,EAAE,YAiBpB,CAAC"}
|
package/dist/cli.js
CHANGED
|
@@ -4,11 +4,14 @@
|
|
|
4
4
|
* Reads a directory of .md files, parses each via dogsbayMdToTree, builds nav
|
|
5
5
|
* from directory structure + frontmatter, returns ExportPage[] + NavItem[].
|
|
6
6
|
*/
|
|
7
|
-
import { existsSync, readdirSync, readFileSync, statSync } from "node:fs";
|
|
8
|
-
import { join, relative, basename } from "node:path";
|
|
7
|
+
import { cpSync, existsSync, mkdirSync, readdirSync, readFileSync, statSync, writeFileSync } from "node:fs";
|
|
8
|
+
import { join, relative, basename, dirname } from "node:path";
|
|
9
|
+
import { extractHeadings } from "./headings.js";
|
|
9
10
|
import { parseMeta } from "@dogsbay/types";
|
|
10
11
|
import { dogsbayMdToTree } from "./parse.js";
|
|
12
|
+
import { treeToDogsbayMd } from "./serialize.js";
|
|
11
13
|
import { buildNavFromDirectory } from "./nav.js";
|
|
14
|
+
import { renderDiagrams } from "./renderers/diagrams.js";
|
|
12
15
|
/**
|
|
13
16
|
* Detect whether a directory contains a Dogsbay MD source tree.
|
|
14
17
|
*
|
|
@@ -32,13 +35,28 @@ function detectDogsbayMdSource(path) {
|
|
|
32
35
|
}
|
|
33
36
|
function walkMdFiles(dir, root, out = []) {
|
|
34
37
|
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
38
|
+
// `_`-prefixed files/dirs are include targets (fragments), not routable
|
|
39
|
+
// pages — the standard Jekyll/Docusaurus convention. The build-time Minja
|
|
40
|
+
// preprocessor `{% include %}`s them into pages; they get no route of their
|
|
41
|
+
// own. (e.g. structural Docusaurus import writes `_includes/**` fragments.)
|
|
42
|
+
if (entry.name.startsWith("_"))
|
|
43
|
+
continue;
|
|
35
44
|
const full = join(dir, entry.name);
|
|
36
45
|
if (entry.isDirectory()) {
|
|
37
46
|
walkMdFiles(full, root, out);
|
|
38
47
|
}
|
|
39
48
|
else if (entry.name.endsWith(".md")) {
|
|
40
49
|
const rel = relative(root, full).replace(/\\/g, "/");
|
|
41
|
-
|
|
50
|
+
let slug = rel.replace(/\.md$/, "");
|
|
51
|
+
// A `<dir>/index.md` page is the directory's landing page: its slug
|
|
52
|
+
// is the directory, not `<dir>/index`. This MUST match how the nav
|
|
53
|
+
// layer normalizes the same file (nav-file.ts `fileToHref` strips
|
|
54
|
+
// `/index`), or `routablesFrom: nav`'s `filterPagesToNav` drops the
|
|
55
|
+
// page and the section landing 404s. The bare root `index.md` keeps
|
|
56
|
+
// slug `index` — format-astro's root-home + `.md`-mirror special-case
|
|
57
|
+
// keys off `slug === "index"`. See plans/dir-index-slug-nav-drop.md.
|
|
58
|
+
if (slug.endsWith("/index"))
|
|
59
|
+
slug = slug.slice(0, -"/index".length);
|
|
42
60
|
out.push({ filePath: full, slug });
|
|
43
61
|
}
|
|
44
62
|
}
|
|
@@ -61,26 +79,31 @@ async function importDogsbayMd(source, opts) {
|
|
|
61
79
|
const taxonomyNames = Array.isArray(opts.taxonomyNames)
|
|
62
80
|
? opts.taxonomyNames
|
|
63
81
|
: undefined;
|
|
82
|
+
// Pre-parse pass — opt-out via `diagrams: false`. When enabled
|
|
83
|
+
// (default), `code` fences with `lang: mermaid` get transformed
|
|
84
|
+
// to `diagram` nodes with pre-rendered SVG. Fail-open: if mmdc
|
|
85
|
+
// (mermaid-cli) isn't installed the code block is left as-is and
|
|
86
|
+
// a one-line warning is printed. See plans/mermaid-dogsbay-md.md.
|
|
87
|
+
const diagramsOn = opts.diagrams !== false;
|
|
64
88
|
for (const { filePath, slug } of files) {
|
|
65
89
|
const content = readFileSync(filePath, "utf-8");
|
|
66
90
|
const { tree, frontmatter } = dogsbayMdToTree(content);
|
|
91
|
+
if (diagramsOn) {
|
|
92
|
+
await renderDiagrams(tree);
|
|
93
|
+
}
|
|
67
94
|
const title = String(frontmatter.title
|
|
68
95
|
?? prettifyName(basename(slug)));
|
|
69
|
-
// Extract heading metadata for TOC
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
text,
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
}
|
|
96
|
+
// Extract heading metadata for TOC AND backfill `node.props.slug`
|
|
97
|
+
// so format-astro's headingToAstro emits a matching `id` on the
|
|
98
|
+
// rendered `<h2>` / `<h3>`. Without this, the TOC's
|
|
99
|
+
// `<a href="#quick-start">` had nothing to scroll to — the
|
|
100
|
+
// heading was emitted without an id because the tree didn't
|
|
101
|
+
// carry the slug. Mirrors format-mkdocs/src/loader.ts:312.
|
|
102
|
+
//
|
|
103
|
+
// Duplicate slugs get `-1`, `-2` suffixes so two `## Foo`
|
|
104
|
+
// headings on the same page produce distinct anchors. Same
|
|
105
|
+
// collision-handling shape as MkDocs.
|
|
106
|
+
const headings = extractHeadings(tree);
|
|
84
107
|
const redirect = frontmatter.redirect;
|
|
85
108
|
const meta = parseMeta(frontmatter, { slug, taxonomyNames });
|
|
86
109
|
pages.push({
|
|
@@ -95,8 +118,31 @@ async function importDogsbayMd(source, opts) {
|
|
|
95
118
|
}
|
|
96
119
|
const navFilePath = opts.nav || undefined;
|
|
97
120
|
const hrefPrefix = typeof opts.hrefPrefix === "string" ? opts.hrefPrefix : undefined;
|
|
98
|
-
|
|
99
|
-
|
|
121
|
+
// `--strict` at the CLI layer maps to "fail" here. `loadNavFile`
|
|
122
|
+
// already throws on the first miss in fail mode; the build
|
|
123
|
+
// surfaces the throw as a fatal error and exits non-zero.
|
|
124
|
+
// See plans/site-build-strict.md.
|
|
125
|
+
const missingNavTargets = opts.missingNavTargets === "fail"
|
|
126
|
+
? "fail"
|
|
127
|
+
: undefined;
|
|
128
|
+
const nav = buildNavFromDirectory(source, {
|
|
129
|
+
navFilePath,
|
|
130
|
+
hrefPrefix,
|
|
131
|
+
missingFile: missingNavTargets,
|
|
132
|
+
});
|
|
133
|
+
// Declare where this corpus's media lives, so an exporter copies the FILES
|
|
134
|
+
// that the `_assets/…` references in the pages point at.
|
|
135
|
+
//
|
|
136
|
+
// Without this the reference survives the conversion and the file does not,
|
|
137
|
+
// which looks exactly like success: the page count, the retention score and
|
|
138
|
+
// a clean exit are all unaffected while every image 404s. `dogsbay site
|
|
139
|
+
// build` has its own asset pass, so this was invisible there and only bit
|
|
140
|
+
// `convert` — an OpenShift vault shipped with 294 dead image references.
|
|
141
|
+
const assetMounts = [];
|
|
142
|
+
const assetsDir = join(source, "_assets");
|
|
143
|
+
if (existsSync(assetsDir))
|
|
144
|
+
assetMounts.push({ dir: assetsDir });
|
|
145
|
+
return assetMounts.length ? { pages, nav, assetMounts } : { pages, nav };
|
|
100
146
|
}
|
|
101
147
|
function prettifyName(slug) {
|
|
102
148
|
return slug
|
|
@@ -104,17 +150,88 @@ function prettifyName(slug) {
|
|
|
104
150
|
.map((w) => w.charAt(0).toUpperCase() + w.slice(1))
|
|
105
151
|
.join(" ");
|
|
106
152
|
}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
153
|
+
/**
|
|
154
|
+
* Export ExportPage[] + nav to a directory of Dogsbay-MD files.
|
|
155
|
+
*
|
|
156
|
+
* Each page's tree is serialized via `treeToDogsbayMd` (which preserves any
|
|
157
|
+
* Minja directives via `escapePreservingMinja`) and written to `<output>/<slug>.md`.
|
|
158
|
+
*
|
|
159
|
+
* Fragment pages (`page.fragment`) are include targets, not routable pages:
|
|
160
|
+
* written with NO frontmatter, NO title, and excluded from nav — their identity
|
|
161
|
+
* is the include path. Mirrors migrate-asciidoc's fragment convention so the
|
|
162
|
+
* build-time Minja preprocessor can `{% include %}` them.
|
|
163
|
+
*/
|
|
164
|
+
/** Media files worth carrying into `_assets` from a media-only mount. */
|
|
165
|
+
const MEDIA_EXTS = new Set([
|
|
166
|
+
".png", ".jpg", ".jpeg", ".gif", ".webp", ".avif",
|
|
167
|
+
".svg", ".ico", ".pdf", ".mp4", ".webm",
|
|
168
|
+
]);
|
|
169
|
+
/** Recursively copy only media files, preserving relative structure. */
|
|
170
|
+
function copyMediaTree(srcDir, destDir) {
|
|
171
|
+
for (const entry of readdirSync(srcDir, { withFileTypes: true })) {
|
|
172
|
+
const full = join(srcDir, entry.name);
|
|
173
|
+
if (entry.isDirectory()) {
|
|
174
|
+
copyMediaTree(full, join(destDir, entry.name));
|
|
175
|
+
continue;
|
|
176
|
+
}
|
|
177
|
+
const dot = entry.name.lastIndexOf(".");
|
|
178
|
+
if (dot === -1 || !MEDIA_EXTS.has(entry.name.slice(dot).toLowerCase()))
|
|
179
|
+
continue;
|
|
180
|
+
mkdirSync(destDir, { recursive: true });
|
|
181
|
+
cpSync(full, join(destDir, entry.name));
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
async function exportDogsbayMd(pages, nav, output, opts) {
|
|
185
|
+
mkdirSync(output, { recursive: true });
|
|
186
|
+
// Copy mounted asset dirs (e.g. Docusaurus `static/`) into `content/_assets/`,
|
|
187
|
+
// the Dogsbay standard (docs/images.md). Preserves internal structure
|
|
188
|
+
// (static/img/x → <output>/_assets/img/x) so the parser's rewritten
|
|
189
|
+
// `/_assets/img/x` refs resolve, and a later `site build`'s asset pass copies
|
|
190
|
+
// `content/_assets/**` through to `/_assets/**`. A mount may target an
|
|
191
|
+
// `_assets` subdir (`into`) and restrict itself to media files (`mediaOnly`) —
|
|
192
|
+
// used for docs-co-located images where the mount dir IS the docs tree.
|
|
193
|
+
if (Array.isArray(opts.assetMounts)) {
|
|
194
|
+
const assetsRoot = join(output, "_assets");
|
|
195
|
+
for (const mount of opts.assetMounts) {
|
|
196
|
+
if (!existsSync(mount.dir))
|
|
197
|
+
continue;
|
|
198
|
+
const dest = mount.into ? join(assetsRoot, mount.into) : assetsRoot;
|
|
199
|
+
if (mount.mediaOnly) {
|
|
200
|
+
copyMediaTree(mount.dir, dest);
|
|
201
|
+
continue;
|
|
202
|
+
}
|
|
203
|
+
const skip = new Set(mount.exclude ?? []);
|
|
204
|
+
cpSync(mount.dir, dest, {
|
|
205
|
+
recursive: true,
|
|
206
|
+
...(skip.size === 0 ? {} : {
|
|
207
|
+
// Relative to the mount, so an exclusion cannot be accidentally
|
|
208
|
+
// satisfied by a directory name somewhere above it on disk.
|
|
209
|
+
filter: (src) => {
|
|
210
|
+
const rel = relative(mount.dir, src);
|
|
211
|
+
return rel === "" || !rel.split(/[\\/]/).some((seg) => skip.has(seg));
|
|
212
|
+
},
|
|
213
|
+
}),
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
for (const page of pages) {
|
|
218
|
+
const slug = page.slug || "index";
|
|
219
|
+
const outPath = join(output, `${slug}.md`);
|
|
220
|
+
mkdirSync(dirname(outPath), { recursive: true });
|
|
221
|
+
const frontmatter = page.fragment || !page.title
|
|
222
|
+
? undefined
|
|
223
|
+
: { title: page.title, ...(page.redirect ? { redirect: page.redirect } : {}) };
|
|
224
|
+
const md = treeToDogsbayMd(page.tree, frontmatter ? { frontmatter } : undefined);
|
|
225
|
+
writeFileSync(outPath, md.endsWith("\n") ? md : md + "\n", "utf-8");
|
|
226
|
+
}
|
|
227
|
+
// Nav as nav.json at the content root (the dogsbay-md importer + runtime
|
|
228
|
+
// loader both prefer nav.json). Fragments never appear here.
|
|
229
|
+
writeFileSync(join(output, "nav.json"), JSON.stringify(nav, null, 2) + "\n", "utf-8");
|
|
113
230
|
}
|
|
114
231
|
export const plugin = {
|
|
115
232
|
name: "dogsbay-md",
|
|
116
233
|
canImport: true,
|
|
117
|
-
canExport:
|
|
234
|
+
canExport: true,
|
|
118
235
|
detectSource: detectDogsbayMdSource,
|
|
119
236
|
importOptions: [
|
|
120
237
|
{
|
|
@@ -125,5 +242,8 @@ export const plugin = {
|
|
|
125
242
|
async import(source, opts) {
|
|
126
243
|
return importDogsbayMd(source, opts);
|
|
127
244
|
},
|
|
245
|
+
async export(pages, nav, output, opts) {
|
|
246
|
+
return exportDogsbayMd(pages, nav, output, opts);
|
|
247
|
+
},
|
|
128
248
|
};
|
|
129
249
|
//# sourceMappingURL=cli.js.map
|
package/dist/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,WAAW,EAAE,YAAY,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAC5G,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAE9D,OAAO,EAAE,eAAe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AAK,EAAE,cAAc;YACrB,WAAW,EAAE,2IAA2I;SACzJ;KACF;IACD,KAAK,CAAC,MAAM,CAAC,MAAc,EAAE,IAA6B;QACxD,OAAO,eAAe,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;IACvC,CAAC;IACD,KAAK,CAAC,MAAM,CAAC,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI;QACnC,OAAO,eAAe,CAAC,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC;IACnD,CAAC;CACF,CAAC"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Code-region walker — THE fence grammar shared by every tool that must
|
|
3
|
+
* treat code specially: the build preprocessor masks Minja openers
|
|
4
|
+
* inside code so template examples never evaluate, the workspace
|
|
5
|
+
* indexer blanks code so `{% include %}` examples never count as real
|
|
6
|
+
* includes, and the refactor commands edit only prose so code samples
|
|
7
|
+
* are never rewritten. One implementation, so none of them can drift.
|
|
8
|
+
*
|
|
9
|
+
* Fence rules (CommonMark): a fence opens with ``` or ~~~ (3+ chars,
|
|
10
|
+
* info string allowed) and closes only on a line of the SAME character
|
|
11
|
+
* with AT LEAST the opener's length and nothing but whitespace after —
|
|
12
|
+
* the serializer emits escalated fences (```` around content containing
|
|
13
|
+
* ```), so honoring the length rule is load-bearing. Fence-looking
|
|
14
|
+
* lines inside an open fence that don't close it are code content.
|
|
15
|
+
*/
|
|
16
|
+
type LineKind = "prose" | "fence" | "code";
|
|
17
|
+
/** Context passed to a code transform: which fence the line belongs to. */
|
|
18
|
+
export interface CodeRegionContext {
|
|
19
|
+
/**
|
|
20
|
+
* Fence info string (e.g. `yaml {minja}`). For inline code spans:
|
|
21
|
+
* the markdown-it-attrs group immediately following the closing
|
|
22
|
+
* backticks when present (e.g. `{minja}` for `` `x`{minja} ``),
|
|
23
|
+
* empty otherwise — so `isMinjaProcessedFence` grades fences and
|
|
24
|
+
* marked inline spans with the same predicate.
|
|
25
|
+
*/
|
|
26
|
+
fenceInfo: string;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Transform CODE content: every line inside a fence, and the inner
|
|
30
|
+
* content of inline code spans on prose lines (backticks kept). Fence
|
|
31
|
+
* marker lines themselves are untouched.
|
|
32
|
+
*
|
|
33
|
+
* `transformInlineAttrs` (optional) rewrites the attr group of an
|
|
34
|
+
* inline span at re-emission — return `""` to drop it. Only inline
|
|
35
|
+
* spans see it; fence info strings are never routed through it.
|
|
36
|
+
*/
|
|
37
|
+
/**
|
|
38
|
+
* Line-by-line fence tracker on THE shared grammar — for tools that must
|
|
39
|
+
* walk a document themselves (the remote-include inliner) instead of
|
|
40
|
+
* transforming regions. A locally re-implemented open/close regex pair
|
|
41
|
+
* drifted immediately: it missed the deflist-hosted `: ```` opener the
|
|
42
|
+
* shared grammar just gained, took the indented closer for an opener,
|
|
43
|
+
* and re-created the exact phantom-fence inversion it was fixing
|
|
44
|
+
* (issue #039 review).
|
|
45
|
+
*
|
|
46
|
+
* step(line) returns what the line IS: "fence" (an opener or closer),
|
|
47
|
+
* "code" (content of an open fence), or "prose". open() reports the
|
|
48
|
+
* state AFTER the last step, so an opener steps "fence" with
|
|
49
|
+
* open()===true and its closer steps "fence" with open()===false.
|
|
50
|
+
*/
|
|
51
|
+
export declare function createFenceTracker(): {
|
|
52
|
+
step(line: string): LineKind;
|
|
53
|
+
open(): boolean;
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* Transform only fence OPENING lines' info strings, on the same shared
|
|
57
|
+
* grammar — a fence-looking line inside an open fence is code content
|
|
58
|
+
* and is never touched. Used to strip the spent `{minja}` marker after
|
|
59
|
+
* the terminal Minja render (a fence marker that survives into the
|
|
60
|
+
* mirror leaks into serializers that round-trip fence info verbatim —
|
|
61
|
+
* the Obsidian vault showed literal ```` ```yaml {minja} ````).
|
|
62
|
+
*/
|
|
63
|
+
export declare function transformFenceInfo(source: string, transform: (info: string) => string): string;
|
|
64
|
+
export declare function transformCodeRegions(source: string, transform: (codeText: string, ctx: CodeRegionContext) => string, transformInlineAttrs?: (attrs: string) => string): string;
|
|
65
|
+
/**
|
|
66
|
+
* The inverse walk: transform PROSE lines (outside fences), leaving
|
|
67
|
+
* fenced content and the fence lines untouched. Used by refactor
|
|
68
|
+
* commands that rewrite markdown structure line-wise (heading shifts,
|
|
69
|
+
* section splits) — a `# heading` inside a code example must never be
|
|
70
|
+
* treated as structure.
|
|
71
|
+
*/
|
|
72
|
+
export declare function transformProseLines(source: string, transform: (line: string, lineIndex: number) => string): string;
|
|
73
|
+
/**
|
|
74
|
+
* Transform PROSE TEXT SEGMENTS: prose lines with their inline code
|
|
75
|
+
* spans protected (the transform sees only the non-code stretches of
|
|
76
|
+
* each prose line). This is the write-side counterpart of
|
|
77
|
+
* transformCodeRegions — refactor commands rewrite references through
|
|
78
|
+
* it so `[x](old.md)` or `{{ key }}` inside examples survive verbatim.
|
|
79
|
+
*/
|
|
80
|
+
export declare function transformProseSegments(source: string, transform: (proseText: string) => string): string;
|
|
81
|
+
/**
|
|
82
|
+
* Fence state BEFORE each line: `openBefore[i]` is true when line i
|
|
83
|
+
* starts inside an unclosed fence. One extra trailing entry gives the
|
|
84
|
+
* state after the last line. Lets line-range refactors check "does
|
|
85
|
+
* this range start or end mid-fence" with the same grammar.
|
|
86
|
+
*/
|
|
87
|
+
export declare function fenceOpenBefore(source: string): boolean[];
|
|
88
|
+
export {};
|
|
89
|
+
//# sourceMappingURL=code-regions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"code-regions.d.ts","sourceRoot":"","sources":["../src/code-regions.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAgBH,KAAK,QAAQ,GAAG,OAAO,GAAG,OAAO,GAAG,MAAM,CAAC;AA6D3C,2EAA2E;AAC3E,MAAM,WAAW,iBAAiB;IAChC;;;;;;OAMG;IACH,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;;;;;;;GAQG;AACH;;;;;;;;;;;;;GAaG;AACH,wBAAgB,kBAAkB,IAAI;IACpC,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,QAAQ,CAAC;IAC7B,IAAI,IAAI,OAAO,CAAC;CACjB,CAMA;AAED;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,GAClC,MAAM,CAuBR;AAED,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,EAAE,iBAAiB,KAAK,MAAM,EAC/D,oBAAoB,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,GAC/C,MAAM,CAyBR;AAED;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,KAAK,MAAM,GACrD,MAAM,CAMR;AAED;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CACpC,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,MAAM,GACvC,MAAM,CAmBR;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,EAAE,CASzD"}
|