@dogsbay/format-hugo 0.2.0-beta.183 → 0.2.0-beta.184

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/static.js ADDED
@@ -0,0 +1,195 @@
1
+ /**
2
+ * Files of the Hugo site's `static/` folder that the pages show.
3
+ *
4
+ * Hugo serves `static/images/a.png` at `/images/a.png`, and pages point there. A Dogsbay site
5
+ * keeps such files under `content/_assets/` and pages point at `/_assets/images/a.png`. Only
6
+ * the files the converted pages refer to are taken (not the folder's fonts, favicons and
7
+ * verification files), and a file a page shows that is not there is reported.
8
+ *
9
+ * A path is the page's text: it is taken apart, never resolved with `..`, and the file it
10
+ * names must be a regular file inside the static folder after links are followed.
11
+ */
12
+ import { existsSync, realpathSync, statSync } from "node:fs";
13
+ import { extname, join, sep } from "node:path";
14
+ /** What a page may show or offer from the static folder. */
15
+ const ASSET_EXTS = new Set([
16
+ ".png", ".jpg", ".jpeg", ".gif", ".webp", ".avif", ".svg", ".ico", ".bmp",
17
+ ".mp4", ".webm", ".mov", ".mp3", ".ogg", ".wav", ".vtt",
18
+ ".pdf", ".txt", ".csv", ".json", ".yaml", ".yml", ".zip", ".tar", ".gz", ".tgz",
19
+ ]);
20
+ /** The ones a page SHOWS: one of these that is missing is a broken picture, and is reported. */
21
+ const SHOWN_EXTS = new Set([".png", ".jpg", ".jpeg", ".gif", ".webp", ".avif", ".svg", ".bmp", ".mp4", ".webm", ".mov"]);
22
+ const MAX_FILES = 100_000;
23
+ /** `staticDir`: absolute path of the site's static folder. Nothing is taken when it is not inside `siteDir`. */
24
+ export function staticAssets(siteDir, staticDir, options = {}) {
25
+ const basePath = /^\/[A-Za-z0-9_.~/-]*[A-Za-z0-9_.~-]$/.test(options.basePath ?? "") ? options.basePath : "";
26
+ const contentRoots = [];
27
+ for (const dir of options.contentRoots ?? []) {
28
+ try {
29
+ contentRoots.push(realpathSync(dir));
30
+ }
31
+ catch {
32
+ // no such folder
33
+ }
34
+ }
35
+ let root;
36
+ try {
37
+ const site = realpathSync(siteDir);
38
+ const real = realpathSync(staticDir);
39
+ if (real.startsWith(site + sep) && statSync(real).isDirectory())
40
+ root = real;
41
+ }
42
+ catch {
43
+ root = undefined; // no static folder
44
+ }
45
+ const found = new Map();
46
+ let taken = 0;
47
+ let full = false;
48
+ /** The plain segments of a site path, or undefined when it is not one a file could have. */
49
+ const segmentsOf = (path) => {
50
+ try {
51
+ const segments = path.slice(1).split("/").map((s) => decodeURIComponent(s));
52
+ return segments.every((s) => s !== "" && s !== "." && s !== ".." && !/[\\/\0]/.test(s) && !s.startsWith(".")) ? segments : undefined;
53
+ }
54
+ catch {
55
+ return undefined; // a path that cannot be decoded names nothing
56
+ }
57
+ };
58
+ /** Whether a content folder holds the file: it is copied beside its page, and the reference works. */
59
+ const inContent = (path) => {
60
+ const segments = segmentsOf(path);
61
+ if (!segments)
62
+ return false;
63
+ for (const root of contentRoots) {
64
+ try {
65
+ const real = realpathSync(join(root, ...segments));
66
+ if (real.startsWith(root + sep) && statSync(real).isFile())
67
+ return true;
68
+ }
69
+ catch {
70
+ // not there
71
+ }
72
+ }
73
+ return false;
74
+ };
75
+ /** The static file a site path names, or null. `path` starts with one `/`. */
76
+ const lookup = (path) => {
77
+ // (only a path that could be a file is remembered: a page's links are not)
78
+ if (!root || !ASSET_EXTS.has(extname(path).toLowerCase()))
79
+ return null;
80
+ const cached = found.get(path);
81
+ if (cached !== undefined)
82
+ return cached;
83
+ if (found.size >= MAX_FILES * 2)
84
+ return null;
85
+ let file = null;
86
+ const segments = segmentsOf(path);
87
+ if (segments) {
88
+ try {
89
+ const candidate = join(root, ...segments);
90
+ if (existsSync(candidate)) {
91
+ const real = realpathSync(candidate);
92
+ // (a content file already at that place under `_assets/` keeps it: the reference is
93
+ // left as the site wrote it, and reported, rather than shown as another picture)
94
+ if (real.startsWith(root + sep) && statSync(real).isFile() && !inContent(`/_assets/${segments.join("/")}`)) {
95
+ if (taken < MAX_FILES) {
96
+ taken++;
97
+ file = { path: `_assets/${segments.join("/")}`, source: real };
98
+ }
99
+ else
100
+ full = true;
101
+ }
102
+ }
103
+ }
104
+ catch {
105
+ file = null; // a file that cannot be read names nothing
106
+ }
107
+ }
108
+ found.set(path, file);
109
+ return file;
110
+ };
111
+ /** A reference as written → what it becomes, or undefined to leave it. `shown` collects missing pictures. */
112
+ const moved = (ref, missing, shown) => {
113
+ // a path of the site only: `/images/a.png`, not `//host/x`, a scheme, or a page-relative path
114
+ const m = /^(\/(?!\/)[^?#\s"'<>]*)([?#][^\s"'<>]*)?$/.exec(ref);
115
+ if (!m || m[1].startsWith("/_assets/"))
116
+ return undefined;
117
+ // a site served under a path (`baseURL = "https://example.org/docs/"`) writes it in front
118
+ const sitePath = basePath && m[1].startsWith(`${basePath}/`) ? m[1].slice(basePath.length) : m[1];
119
+ const file = lookup(sitePath);
120
+ if (file)
121
+ return `/${file.path.split("/").map(encodeURIComponent).join("/")}${m[2] ?? ""}`;
122
+ if (shown && SHOWN_EXTS.has(extname(sitePath).toLowerCase()) && missing.length < 50 && !missing.includes(m[1]) && !inContent(sitePath))
123
+ missing.push(m[1]);
124
+ return undefined;
125
+ };
126
+ // `src="…"` and `poster="…"` in raw HTML (an <img>, a <video>, its <source>), in the quote
127
+ // the page used
128
+ const HTML_REF = /(\s(?:src|poster)\s*=\s*)(?:"([^"]*)"|'([^']*)')/gi;
129
+ const inMarkup = (html, missing) => html.replace(HTML_REF, (whole, lead, dq, sq) => {
130
+ const to = moved(dq ?? sq ?? "", missing, true);
131
+ return to === undefined ? whole : `${lead}${dq !== undefined ? `"${to}"` : `'${to}'`}`;
132
+ });
133
+ /** As `inMarkup`, leaving comments, scripts and styles as they are: nothing in them is shown. */
134
+ const OPAQUE = [["<!--", "-->"], ["<script", "</script"], ["<style", "</style"]];
135
+ const inHtml = (html, missing) => {
136
+ const lower = html.toLowerCase();
137
+ let out = "";
138
+ let at = 0;
139
+ while (at < html.length) {
140
+ let start = -1;
141
+ let closer = "";
142
+ for (const [open, close] of OPAQUE) {
143
+ const i = lower.indexOf(open, at);
144
+ if (i >= 0 && (start < 0 || i < start)) {
145
+ start = i;
146
+ closer = close;
147
+ }
148
+ }
149
+ if (start < 0)
150
+ break;
151
+ out += inMarkup(html.slice(at, start), missing);
152
+ const end = lower.indexOf(closer, start);
153
+ // (one that never closes runs to the end)
154
+ const stop = end < 0 ? html.length : end + closer.length;
155
+ out += html.slice(start, stop);
156
+ at = stop;
157
+ }
158
+ return out + inMarkup(html.slice(at), missing);
159
+ };
160
+ const rewrite = (tree) => {
161
+ const missing = [];
162
+ const visit = (node, depth) => {
163
+ if (depth > 200 || !node || typeof node !== "object")
164
+ return;
165
+ if (Array.isArray(node)) {
166
+ for (const item of node)
167
+ visit(item, depth + 1);
168
+ return;
169
+ }
170
+ const n = node;
171
+ if (n.type === "image" && typeof n.src === "string") {
172
+ n.src = moved(n.src, missing, true) ?? n.src;
173
+ }
174
+ else if (n.type === "link" && typeof n.href === "string") {
175
+ n.href = moved(n.href, missing, false) ?? n.href;
176
+ }
177
+ else if ((n.type === "html" || n.type === "html-inline") && typeof n.html === "string" && n.html.includes("=")) {
178
+ n.html = inHtml(n.html, missing);
179
+ }
180
+ for (const key of Object.keys(n)) {
181
+ const value = n[key];
182
+ if (value && typeof value === "object")
183
+ visit(value, depth + 1);
184
+ }
185
+ };
186
+ visit(tree, 0);
187
+ return missing;
188
+ };
189
+ return {
190
+ rewrite,
191
+ // (one file may be written two ways in the pages: `a.png`, `%61.png`)
192
+ files: () => [...new Map([...found.values()].filter((f) => f !== null).map((f) => [f.path, f])).values()].sort((a, b) => a.path.localeCompare(b.path)),
193
+ full: () => full,
194
+ };
195
+ }
@@ -1,18 +1,45 @@
1
- import { type HugoLedgerEntry, type ShortcodeRegistry } from "./registry.js";
1
+ import { type HugoSiteAdapter, type HugoLedgerEntry, type ShortcodeRegistry } from "./registry.js";
2
2
  import type { HugoConfig } from "./config.js";
3
+ import { type HugoIntent } from "./intent.js";
4
+ import type { LocatedContent } from "./resolve.js";
5
+ import type { SharedKind } from "./registry.js";
3
6
  export interface TranslateOptions {
4
7
  config: HugoConfig;
5
8
  /** Extra/overriding shortcode mappings, merged last. */
6
9
  shortcodes?: ShortcodeRegistry;
7
- /** Include the Kubernetes site layer. Auto-enabled when the site looks like k8s. */
8
- kubernetes?: boolean;
10
+ /**
11
+ * The theme's and the site's adapters, lowest first (`chooseAdapters`). Default: none, so
12
+ * only Hugo's own shortcodes are mapped.
13
+ */
14
+ adapters?: readonly HugoSiteAdapter[];
9
15
  resolveRef?: (target: string, from?: string) => string | undefined;
10
16
  readContentFile?: (path: string, fromFile?: string) => string | undefined;
11
17
  /** Source file, relative to the content root — stamped onto ledger entries. */
12
18
  file?: string;
19
+ /** The site's translated strings (`loadHugoI18n`), for `{{< heading >}}`. */
20
+ i18n?: Record<string, string>;
21
+ /** Keep the source's intent (intent.ts). Needs `locateContentFile` and `sharedPath` for files. */
22
+ intent?: HugoIntent;
23
+ locateContentFile?: (path: string, fromFile?: string) => LocatedContent | undefined;
24
+ sharedPath?: (located: LocatedContent, kind: SharedKind) => string | undefined;
25
+ shortcodeFile?: (name: string) => LocatedContent | undefined;
26
+ /** The page's front matter, for a mapping that prints from it. */
27
+ pageParams?: Record<string, unknown>;
28
+ listContentDir?: (dir: string) => Array<{
29
+ name: string;
30
+ text: string;
31
+ }>;
32
+ readSiteData?: (name: string) => unknown;
13
33
  }
14
34
  export interface TranslateResult {
15
35
  markdown: string;
16
36
  ledger: HugoLedgerEntry[];
37
+ /** With `intent`: the page computes a value, so it must be a template page (`template: jinja`). */
38
+ template?: boolean;
39
+ /**
40
+ * Blocks of template text in `markdown` (a loop over a data file) that Markdown would read as
41
+ * its own lines: lift them out before parsing the page (`liftTemplateBlocks`).
42
+ */
43
+ blocks?: string[];
17
44
  }
18
45
  export declare function translateHugo(source: string, opts: TranslateOptions): TranslateResult;
package/dist/translate.js CHANGED
@@ -9,37 +9,114 @@
9
9
  * recorded. A migration that silently deletes what it does not understand is
10
10
  * worse than one that leaves a visible marker.
11
11
  */
12
- import { scanShortcodes, stripContentTypeMarkers } from "./shortcodes.js";
12
+ import { unescapeShownShortcodes, scanShortcodes, stripContentTypeMarkers } from "./shortcodes.js";
13
13
  import { composeRegistry } from "./registry.js";
14
14
  import { BUILTIN_SHORTCODES } from "./builtins.js";
15
- import { KUBERNETES_SHORTCODES } from "./kubernetes.js";
15
+ import { stripFenceMinjaMarkers, transformCodeRegions } from "@dogsbay/format-dogsbay-md/browser";
16
+ import { definitionLines, hasMarkerChars, resolveIntent, withoutMarkerChars } from "./intent.js";
17
+ import { linkReferences } from "./references.js";
18
+ import { rewriteHtmlBlocks } from "./html-blocks.js";
19
+ /**
20
+ * Shortcodes that print a VALUE (a version, a site param). Hugo runs shortcodes before
21
+ * markdown, so these are filled in inside a code block or a code span too
22
+ * (`kubectl version v{{< skew currentVersion >}}`). Every other shortcode found in code is
23
+ * left as written: it is far more often an example of the syntax than a call.
24
+ */
25
+ const VALUE_SHORTCODES = ["param"];
16
26
  /** Depth cap: an include cycle must not recurse forever. */
17
27
  const MAX_DEPTH = 8;
18
28
  export function translateHugo(source, opts) {
19
29
  const ledger = [];
20
- const registry = composeRegistry(BUILTIN_SHORTCODES, opts.kubernetes === false ? {} : KUBERNETES_SHORTCODES, opts.shortcodes ?? {});
30
+ const adapters = opts.adapters ?? [];
31
+ const registry = composeRegistry(BUILTIN_SHORTCODES, ...adapters.map((a) => a.shortcodes), opts.shortcodes ?? {});
32
+ // rules for a name nothing maps: the highest adapter's first
33
+ const fallbacks = adapters.flatMap((a) => (a.fallback ? [a.fallback] : [])).reverse();
34
+ const valueShortcodes = new Set([...VALUE_SHORTCODES, ...adapters.flatMap((a) => a.valueShortcodes ?? [])]);
35
+ if (opts.intent)
36
+ for (const a of adapters)
37
+ a.prepare?.(opts.intent.store, opts.config.params);
21
38
  const report = (entry) => {
22
39
  ledger.push({ ...entry, file: opts.file });
23
40
  };
41
+ let references;
42
+ const pageReferences = () => (references ??= linkReferences(source));
24
43
  const translate = (text, depth) => {
25
44
  if (depth > MAX_DEPTH)
26
45
  return text;
27
46
  const ctx = {
28
47
  translate: (inner) => translate(inner, depth + 1),
48
+ translateData: (inner) => translate(inner, 1),
29
49
  config: opts.config,
30
50
  report,
31
51
  resolveRef: opts.resolveRef,
32
52
  readContentFile: (path, from) => opts.readContentFile?.(path, from ?? opts.file),
33
53
  file: opts.file,
54
+ i18n: opts.i18n,
55
+ intent: opts.intent,
56
+ locateContentFile: opts.locateContentFile
57
+ ? (path, from) => opts.locateContentFile(path, from ?? opts.file)
58
+ : undefined,
59
+ sharedPath: opts.sharedPath,
60
+ listContentDir: opts.listContentDir,
61
+ readSiteData: opts.readSiteData,
62
+ shortcodeFile: opts.shortcodeFile,
63
+ pageParams: opts.pageParams,
64
+ pageReferences,
65
+ pageSource: source,
34
66
  };
35
67
  let out = "";
36
- for (const node of scanShortcodes(text)) {
68
+ const nodes = scanShortcodes(text, valueShortcodes);
69
+ for (let i = 0; i < nodes.length; i++) {
70
+ const node = nodes[i];
37
71
  if (node.kind === "text") {
38
- out += node.text;
72
+ // a shown shortcode (`{{</* note */>}}`) is printed as Hugo prints it; only in the
73
+ // page's own text, never in a file a mapping embeds
74
+ out += unescapeShownShortcodes(node.text);
39
75
  continue;
40
76
  }
41
77
  const mapping = registry[node.name];
78
+ // alone on its line: only spaces before it since the last line break, and after it until
79
+ // the next (asked by the mappings that need it; each side read only to its first character)
80
+ ctx.alone = () => {
81
+ const next = nodes[i + 1];
82
+ if (next && next.kind !== "text")
83
+ return false;
84
+ for (let k = out.length - 1; k >= 0 && out[k] !== "\n"; k--)
85
+ if (out[k] !== " " && out[k] !== "\t")
86
+ return false;
87
+ const after = next?.text ?? "";
88
+ for (let k = 0; k < after.length && after[k] !== "\n"; k++)
89
+ if (after[k] !== " " && after[k] !== "\t" && after[k] !== "\r")
90
+ return false;
91
+ return true;
92
+ };
93
+ if (node.inCode) {
94
+ // In code, a value shortcode is filled in only when it HAS a value: with no mapping,
95
+ // or nothing to print, the code stays as written and nothing is recorded.
96
+ const before = ledger.length;
97
+ const value = mapping?.(node, ctx);
98
+ if (typeof value === "string" && value !== "")
99
+ out += value;
100
+ else {
101
+ ledger.length = before;
102
+ out += node.raw;
103
+ }
104
+ continue;
105
+ }
42
106
  if (!mapping) {
107
+ // a rule that reads what the shortcode is, before giving up on it
108
+ let ruled;
109
+ for (const rule of fallbacks) {
110
+ ruled = rule(node, ctx);
111
+ if (ruled !== undefined)
112
+ break;
113
+ }
114
+ if (ruled === null)
115
+ continue;
116
+ if (ruled !== undefined) {
117
+ out += indented(out, ruled);
118
+ continue;
119
+ }
43
120
  // NEVER drop. Preserve verbatim + record.
44
121
  report({
45
122
  shortcode: node.name,
@@ -63,15 +140,59 @@ export function translateHugo(source, opts) {
63
140
  out += node.raw;
64
141
  continue;
65
142
  }
66
- out += result;
143
+ out += indented(out, result);
67
144
  }
68
145
  return out;
69
146
  };
70
147
  // Body markers are structural template slots, not content: left in place
71
148
  // they render as stray comments and push the page into a raw-HTML path.
72
- const cleaned = stripContentTypeMarkers(source);
73
- const markdown = tidy(translate(cleaned, 0));
74
- return { markdown, ledger };
149
+ const cleaned = stripContentTypeMarkers(opts.intent ? withoutMarkerChars(source) : source);
150
+ if (opts.intent && hasMarkerChars(source)) {
151
+ report({ shortcode: "(intent)", action: "stripped", note: "Unicode noncharacters (U+FDD0 to U+FDD3) were removed from the page: the import uses them as its own marks", line: 0 });
152
+ }
153
+ // a site's HTML boxes as directives, after the shortcodes (their lines are the source's) and
154
+ // before resolveIntent (a value in `<code>` becomes one in a code span)
155
+ const htmlBlocks = adapters.flatMap((a) => a.htmlBlocks ?? []);
156
+ const tidied = tidy(rewriteHtmlBlocks(translate(cleaned, 0), htmlBlocks, report, cleaned));
157
+ if (!opts.intent)
158
+ return { markdown: tidied, ledger };
159
+ // A code block or span the SOURCE marked `{minja}` means nothing in Hugo and would be run by
160
+ // the build on a template page. The marks the import adds come after this, in resolveIntent.
161
+ const neutral = transformCodeRegions(stripFenceMinjaMarkers(tidied), (code) => code,
162
+ // an inline span's own attribute group, on a line of text (never inside a code block)
163
+ (group) => (/(^|[\s{])minja([\s}]|$)/.test(group) ? `\\${group}` : group));
164
+ if (neutral !== tidied) {
165
+ report({ shortcode: "(intent)", action: "degraded", note: "a `{minja}` mark written in the source was made plain text: in Hugo it is text, and the build would run the code it marks", line: 0 });
166
+ }
167
+ // Each marker a mapping wrote becomes its intent form or its value, now the page is whole.
168
+ const resolved = resolveIntent(neutral, opts.intent.allowTemplate, opts.intent.store, opts.intent.whyNotTemplate);
169
+ for (const note of resolved.notes)
170
+ report({ shortcode: "(intent)", action: "degraded", note, line: 0 });
171
+ // A template page sets the values it computes before its text.
172
+ const definitions = definitionLines(opts.intent, resolved.computed);
173
+ const markdown = definitions ? `${definitions}\n\n${resolved.markdown}` : resolved.markdown;
174
+ return { markdown, ledger, template: resolved.template, ...(resolved.blocks.length > 0 ? { blocks: resolved.blocks } : {}) };
175
+ }
176
+ /**
177
+ * A shortcode written indented (inside a list item) that gives a CODE BLOCK: the block belongs
178
+ * at that indent, so every line after the first gets it too. Hugo inserts the output as it is, which its HTML does
179
+ * not mind; markdown does, and an example's lines fell out of their list item and out of their
180
+ * code block (the YAML came out as one flowed paragraph).
181
+ */
182
+ function indented(before, result) {
183
+ if (!result.includes("\n"))
184
+ return result;
185
+ const indent = before.slice(before.lastIndexOf("\n") + 1);
186
+ if (indent === "" || /[^ \t]/.test(indent))
187
+ return result;
188
+ if (/^(`{3,}|~{3,})/.test(result))
189
+ return result.replace(/\n(?=[^\n])/g, `\n${indent}`);
190
+ // A block directive (a region block in a list item): its body keeps the indent the site wrote,
191
+ // and its closer takes the opener's, or the block would end the list item. Its text is not
192
+ // indented again: four more spaces would make it code.
193
+ if (/^:{3,}when\{/.test(result))
194
+ return result.replace(/\n(:{3,})(?=\n|$)/g, `\n${indent}$1`);
195
+ return result;
75
196
  }
76
197
  /**
77
198
  * A block directive must start its own line, and Dogsbay-MD closes a `:::`
@@ -80,19 +201,55 @@ export function translateHugo(source, opts) {
80
201
  * which is a paragraph containing colons rather than a callout.
81
202
  */
82
203
  function tidy(markdown) {
83
- return (markdown
84
- // An OPENER is a colon run followed by a directive name, so it must
85
- // begin its own line.
86
- // `[^\n:]` — NOT `[^\n]`. A nested group uses a longer fence
87
- // (`::::tabs` around `:::tab`), and a class that admits `:` matched the
88
- // run's own first colon, splitting `::::tabs` into `:` + `:::tabs` and
89
- // leaving a stray colon in the page.
90
- .replace(/([^\n:])\n?(:{3,}[A-Za-z])/g, "$1\n\n$2")
204
+ return (openersOnTheirLines(markdown)
91
205
  // A CLOSER is a colon run NOT followed by a name. Only break after it
92
206
  // when text follows on the same line — the negative lookahead is what
93
207
  // keeps this rule from splitting `:::note` into `:::` + `note`, which
94
208
  // is exactly what a naive version of this function did.
95
209
  .replace(/(^|\n)(:{3,})(?![A-Za-z{:])[ \t]*([^\s:][^\n]*)/g, "$1$2\n\n$3")
96
210
  .replace(/\n{3,}/g, "\n\n")
97
- .replace(/[ \t]+$/gm, ""));
211
+ // trailing spaces off each line, by a loop: `/[ \t]+$/gm` is quadratic on a long run of
212
+ // spaces followed by text (seconds on one 100,000-character line)
213
+ .split("\n")
214
+ .map(trimSpacesEnd)
215
+ .join("\n"));
216
+ }
217
+ function trimSpacesEnd(line) {
218
+ let end = line.length;
219
+ while (end > 0 && (line.charCodeAt(end - 1) === 32 || line.charCodeAt(end - 1) === 9))
220
+ end--;
221
+ return end === line.length ? line : line.slice(0, end);
222
+ }
223
+ /**
224
+ * An OPENER is a colon run followed by a directive name, so it must begin its own line, after a
225
+ * blank one. An opener on an indented line of its own (a block in a list item) keeps its indent:
226
+ * the blank line goes before the line, never between the indent and the opener. One pass per
227
+ * line, linear: the text is someone else's.
228
+ */
229
+ function openersOnTheirLines(markdown) {
230
+ const out = [];
231
+ for (const line of markdown.split("\n")) {
232
+ // `(^|[^:])`: a nested group uses a longer fence (`::::tabs` around `:::tab`), and a match
233
+ // starting inside the run split `::::tabs` into `:` + `:::tabs`
234
+ const re = /(^|[^:])(:{3,}[A-Za-z])/g;
235
+ const pieces = [];
236
+ let cut = 0;
237
+ for (let m = re.exec(line); m; m = re.exec(line)) {
238
+ const at = m.index + m[1].length;
239
+ if (at > cut && /\S/.test(line.slice(cut, at))) {
240
+ pieces.push(line.slice(cut, at));
241
+ cut = at;
242
+ }
243
+ }
244
+ pieces.push(line.slice(cut));
245
+ pieces.forEach((piece, i) => {
246
+ const prev = out[out.length - 1];
247
+ const opens = i > 0 || /^[ \t]*:{3,}[A-Za-z]/.test(piece);
248
+ // (after a line ending in a colon, as before: `:::` closing one block, `Note:`)
249
+ if (opens && prev !== undefined && prev.trim() !== "" && (i > 0 || !prev.endsWith(":")))
250
+ out.push("");
251
+ out.push(piece);
252
+ });
253
+ }
254
+ return out.join("\n");
98
255
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dogsbay/format-hugo",
3
- "version": "0.2.0-beta.183",
3
+ "version": "0.2.0-beta.184",
4
4
  "description": "Hugo format plugin for Dogsbay — imports Hugo/Docsy sites into TreeNode[] by scanning shortcodes and translating them to Dogsbay-MD.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -22,8 +22,8 @@
22
22
  "dependencies": {
23
23
  "smol-toml": "^1.4.2",
24
24
  "yaml": "^2.9.0",
25
- "@dogsbay/format-dogsbay-md": "0.2.0-beta.183",
26
- "@dogsbay/types": "0.2.0-beta.183"
25
+ "@dogsbay/format-dogsbay-md": "0.2.0-beta.184",
26
+ "@dogsbay/types": "0.2.0-beta.184"
27
27
  },
28
28
  "devDependencies": {
29
29
  "@types/node": "^25.9.5",
@@ -1,13 +0,0 @@
1
- /**
2
- * Kubernetes site shortcodes.
3
- *
4
- * These are defined in `kubernetes/website/layouts/shortcodes/`, not in Hugo
5
- * or Docsy, so they belong in a SITE layer rather than the core — the same
6
- * separation the MDX adapters use. They are here because kubernetes/website is
7
- * the testbed and because several are extremely common (`glossary_tooltip`
8
- * alone is 1,266 uses), so leaving them unmapped would dominate the ledger.
9
- *
10
- * Counts are measured in `content/en`.
11
- */
12
- import { type ShortcodeRegistry } from "./registry.js";
13
- export declare const KUBERNETES_SHORTCODES: ShortcodeRegistry;