@cloudhal/astro-renderer 0.7.0 → 0.7.1
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/src/embed-client.d.ts +0 -12
- package/dist/src/embed-client.js +2 -1
- package/dist/src/kit.js +2 -7
- package/dist/src/markdown.d.ts +2 -2
- package/dist/src/markdown.js +6 -23
- package/dist/src/text-scan.d.ts +56 -0
- package/dist/src/text-scan.js +183 -0
- package/package.json +8 -8
|
@@ -1,15 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The click-to-load video player (RFC-0015 §4): a small first-party module under `/_cloudhal/`,
|
|
3
|
-
* so the site's `script-src 'self'` stays as it is. An `embed` block renders a link card to the
|
|
4
|
-
* video; with this module, following the link swaps the card for the player's iframe, and only
|
|
5
|
-
* then does the reader's browser contact the video host (YouTube's no-cookie domain or Vimeo's
|
|
6
|
-
* player, with Do Not Track). Without JavaScript the link still opens the video page.
|
|
7
|
-
*
|
|
8
|
-
* Worker-safe: the code is a constant, written as a static asset by the build (`integration.ts`)
|
|
9
|
-
* and served from memory by `cloudhal dev` (`embed-middleware.ts`). The file name carries a
|
|
10
|
-
* version (`/_cloudhal/*` is cached as immutable): bump it with any change to the code; a test
|
|
11
|
-
* pins the code's hash to the version.
|
|
12
|
-
*/
|
|
13
1
|
/** The only hosts an `embed` player may load from (also the CSP `frame-src`). */
|
|
14
2
|
export declare const EMBED_FRAME_ORIGINS: readonly ["https://www.youtube-nocookie.com", "https://player.vimeo.com"];
|
|
15
3
|
export declare const EMBED_SCRIPT: {
|
package/dist/src/embed-client.js
CHANGED
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
* version (`/_cloudhal/*` is cached as immutable): bump it with any change to the code; a test
|
|
11
11
|
* pins the code's hash to the version.
|
|
12
12
|
*/
|
|
13
|
+
import { hasEmbedLine } from "./text-scan.js";
|
|
13
14
|
|
|
14
15
|
/** The only hosts an `embed` player may load from (also the CSP `frame-src`). */
|
|
15
16
|
export const EMBED_FRAME_ORIGINS = [
|
|
@@ -88,7 +89,7 @@ export function usesEmbeds(content
|
|
|
88
89
|
|
|
89
90
|
|
|
90
91
|
) {
|
|
91
|
-
const md = (s ) => !!s &&
|
|
92
|
+
const md = (s ) => !!s && hasEmbedLine(s);
|
|
92
93
|
if (md(content.markdown)) return true;
|
|
93
94
|
return (content.sections ?? []).some(
|
|
94
95
|
(s) =>
|
package/dist/src/kit.js
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
import { htmlText, renderBody, renderInlineMarkdown } from "./markdown.js";
|
|
8
|
+
import { renderedHeadings } from "./text-scan.js";
|
|
8
9
|
|
|
9
10
|
/** One heading of an article's table of contents; `id` is the anchor the rendered body carries. */
|
|
10
11
|
|
|
@@ -22,18 +23,12 @@ import { htmlText, renderBody, renderInlineMarkdown } from "./markdown.js";
|
|
|
22
23
|
/** Words per minute when a theme sets none (RFC-0018 §1 `readingSpeed`). */
|
|
23
24
|
export const READING_SPEED = 230;
|
|
24
25
|
|
|
25
|
-
const HEADING = /<h([23]) id="([^"]+)">([\s\S]*?)<\/h\1>/g;
|
|
26
|
-
|
|
27
26
|
/**
|
|
28
27
|
* Headings of HTML rendered by `renderMarkdown`/`renderBody` (their ids come from `headingSlug`).
|
|
29
28
|
* HTML bodies keep no ids through the sanitizer, so they have no table of contents.
|
|
30
29
|
*/
|
|
31
30
|
export function tableOfContents(html ) {
|
|
32
|
-
return
|
|
33
|
-
id: m[2] ,
|
|
34
|
-
text: htmlText(m[3] ),
|
|
35
|
-
depth: Number(m[1]) ,
|
|
36
|
-
}));
|
|
31
|
+
return renderedHeadings(html).map((h) => ({ id: h.id, text: htmlText(h.inner), depth: h.depth }));
|
|
37
32
|
}
|
|
38
33
|
|
|
39
34
|
/**
|
package/dist/src/markdown.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { type BlockRegistry } from "@cloudhal/core-ts/blocks";
|
|
|
3
3
|
import { mediaPath } from "@cloudhal/core-ts/media";
|
|
4
4
|
import { type MediaContext } from "./media.js";
|
|
5
5
|
import { safeHref, safeSrc } from "./safe-urls.js";
|
|
6
|
+
import { htmlText } from "./text-scan.js";
|
|
6
7
|
export type { MediaContext } from "./media.js";
|
|
7
8
|
export declare const escapeHtml: (s: string) => string;
|
|
8
9
|
export { safeHref, safeSrc };
|
|
@@ -27,8 +28,7 @@ export declare function renderInlineMarkdown(source: string): string;
|
|
|
27
28
|
export declare function markdownText(source: string): string;
|
|
28
29
|
/** Inline markdown as plain text: inline tags go without leaving gaps ("**537**," → "537,"). */
|
|
29
30
|
export declare function inlineMarkdownText(source: string): string;
|
|
30
|
-
|
|
31
|
-
export declare function htmlText(html: string): string;
|
|
31
|
+
export { htmlText };
|
|
32
32
|
/**
|
|
33
33
|
* `markdown` bodies are rendered as data; `html` bodies go through the allowlist sanitizer
|
|
34
34
|
* (RFC-0012): any writer can store them — agent keys over REST, `cloudhal push`, every role — so
|
package/dist/src/markdown.js
CHANGED
|
@@ -19,6 +19,7 @@ import {
|
|
|
19
19
|
import { safeHref, safeSrc } from "./safe-urls.js";
|
|
20
20
|
import { sanitizeHtml } from "./sanitize.js";
|
|
21
21
|
import { renderSurface, surfaceProblems } from "./surfaces.js";
|
|
22
|
+
import { htmlText, leadingHeading, stripTags } from "./text-scan.js";
|
|
22
23
|
|
|
23
24
|
|
|
24
25
|
|
|
@@ -357,14 +358,6 @@ export function renderInlineMarkdown(source ) {
|
|
|
357
358
|
}
|
|
358
359
|
}
|
|
359
360
|
|
|
360
|
-
const ENTITIES = {
|
|
361
|
-
"&": "&",
|
|
362
|
-
"<": "<",
|
|
363
|
-
">": ">",
|
|
364
|
-
""": '"',
|
|
365
|
-
"'": "'",
|
|
366
|
-
};
|
|
367
|
-
|
|
368
361
|
/** Markdown as plain text (meta descriptions): rendered safely, then tags dropped and entities decoded. */
|
|
369
362
|
export function markdownText(source ) {
|
|
370
363
|
return htmlText(renderMarkdown(source));
|
|
@@ -372,20 +365,10 @@ export function markdownText(source ) {
|
|
|
372
365
|
|
|
373
366
|
/** Inline markdown as plain text: inline tags go without leaving gaps ("**537**," → "537,"). */
|
|
374
367
|
export function inlineMarkdownText(source ) {
|
|
375
|
-
return htmlText(renderInlineMarkdown(source)
|
|
368
|
+
return htmlText(stripTags(renderInlineMarkdown(source), ""));
|
|
376
369
|
}
|
|
377
370
|
|
|
378
|
-
|
|
379
|
-
export function htmlText(html ) {
|
|
380
|
-
return html
|
|
381
|
-
.replace(/<[^>]*>/g, " ")
|
|
382
|
-
.replace(/&(?:amp|lt|gt|quot|#39);/g, (m) => ENTITIES[m] ?? m)
|
|
383
|
-
.replace(/&#(\d{1,7});/g, (m, n ) =>
|
|
384
|
-
Number(n) <= 0x10ffff ? String.fromCodePoint(Number(n)) : m,
|
|
385
|
-
)
|
|
386
|
-
.replace(/\s+/g, " ")
|
|
387
|
-
.trim();
|
|
388
|
-
}
|
|
371
|
+
export { htmlText };
|
|
389
372
|
|
|
390
373
|
/**
|
|
391
374
|
* `markdown` bodies are rendered as data; `html` bodies go through the allowlist sanitizer
|
|
@@ -492,9 +475,9 @@ export function entryArticleParts(
|
|
|
492
475
|
) {
|
|
493
476
|
let body = entry.body;
|
|
494
477
|
if (body.format === "markdown") {
|
|
495
|
-
const
|
|
496
|
-
if (
|
|
497
|
-
body = { ...body, value: body.value.slice(
|
|
478
|
+
const h1 = leadingHeading(body.value);
|
|
479
|
+
if (h1 && h1.text.trim().toLowerCase() === entry.title.trim().toLowerCase())
|
|
480
|
+
body = { ...body, value: body.value.slice(h1.length) };
|
|
498
481
|
}
|
|
499
482
|
const when = entry.publishedAt ?? undefined;
|
|
500
483
|
const date = when
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Linear scanners for text the renderer reads from markdown and from the HTML it rendered
|
|
3
|
+
* (AGENTS.md rule 13). Each replaces a regex CodeQL reported as polynomial backtracking
|
|
4
|
+
* (js/polynomial-redos) and gives the same answers on ordinary input; `test/text-scan.test.ts`
|
|
5
|
+
* checks each against the regex it replaced and against a 100k-character adversarial input.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* `html` with every tag (`<` up to the next `>`) replaced by `gap`: what
|
|
9
|
+
* `.replace(/<[^>]*>/g, gap)` did, without rescanning to the end from every `<` when no `>`
|
|
10
|
+
* follows. As there, a `<` with no `>` after it stays.
|
|
11
|
+
*/
|
|
12
|
+
export declare function stripTags(html: string, gap: string): string;
|
|
13
|
+
/**
|
|
14
|
+
* Text of HTML this module's callers rendered (meta and feed descriptions, JSON-LD,
|
|
15
|
+
* table-of-contents labels, heading ids, reading time): tags dropped, entities decoded once,
|
|
16
|
+
* whitespace collapsed.
|
|
17
|
+
*
|
|
18
|
+
* **Plain text, not HTML.** Decoding is the point (`Array<string>` reads `Array<string>`),
|
|
19
|
+
* so the result can hold `<script>` when the source said `<script>`. Every sink escapes it
|
|
20
|
+
* for its context, and `test/html-text-sinks.test.ts` checks each one with that input: Astro
|
|
21
|
+
* attributes and text (meta, og, twitter, the table of contents), `jsonLdText` (JSON-LD:
|
|
22
|
+
* `<`, `>` and `&` as `\u003c`…, so no `</script>` or `<!--`), the feeds' `xml()` (RSS). A new
|
|
23
|
+
* caller must put the result through an escaping sink too, never `set:html`.
|
|
24
|
+
*
|
|
25
|
+
* Entities are decoded in one pass, so `&lt;` is the text `<`, and `&#60;` the text
|
|
26
|
+
* `<` (the regex chain before decoded those twice).
|
|
27
|
+
*/
|
|
28
|
+
export declare function htmlText(html: string): string;
|
|
29
|
+
/**
|
|
30
|
+
* The opening ATX heading of a markdown body (`# Title`, closing `#`s allowed): its text, and how
|
|
31
|
+
* much of the body it takes (the blank lines and `#`-only lines after it too). Exactly what
|
|
32
|
+
* `/^\s*#\s+(.+?)\s*#*\s*(?:\r?\n|$)/` matched (text trimmed), in one pass: that regex was cubic
|
|
33
|
+
* on a heading line of spaces (CodeQL js/polynomial-redos, alert 17).
|
|
34
|
+
*/
|
|
35
|
+
export declare function leadingHeading(markdown: string): {
|
|
36
|
+
text: string;
|
|
37
|
+
length: number;
|
|
38
|
+
} | undefined;
|
|
39
|
+
/** A heading `renderMarkdown` wrote: `<h2 id="…">…</h2>` or `<h3 …>`. */
|
|
40
|
+
export interface HeadingMatch {
|
|
41
|
+
depth: 2 | 3;
|
|
42
|
+
id: string;
|
|
43
|
+
inner: string;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* The `<h2 id="…">…</h2>` and `<h3 id="…">…</h3>` of rendered HTML, in order: what
|
|
47
|
+
* `/<h([23]) id="([^"]+)">([\s\S]*?)<\/h\1>/g` found, without rescanning to the end from every
|
|
48
|
+
* opening tag when its closing tag is missing.
|
|
49
|
+
*/
|
|
50
|
+
export declare function renderedHeadings(html: string): HeadingMatch[];
|
|
51
|
+
/**
|
|
52
|
+
* Whether a line of `markdown`, after leading whitespace and `>` quote markers, starts with an
|
|
53
|
+
* `::embed` directive: what `/(^|\n)\s*(?:>\s*)*::embed\b/` tested, in one pass. That regex
|
|
54
|
+
* retried its whitespace run from every line start of a run of blank lines.
|
|
55
|
+
*/
|
|
56
|
+
export declare function hasEmbedLine(markdown: string): boolean;
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Linear scanners for text the renderer reads from markdown and from the HTML it rendered
|
|
3
|
+
* (AGENTS.md rule 13). Each replaces a regex CodeQL reported as polynomial backtracking
|
|
4
|
+
* (js/polynomial-redos) and gives the same answers on ordinary input; `test/text-scan.test.ts`
|
|
5
|
+
* checks each against the regex it replaced and against a 100k-character adversarial input.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
const isSpace = (c ) => c !== undefined && /\s/.test(c);
|
|
9
|
+
const LINE_BREAK = /[\n\r\u2028\u2029]/;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* `html` with every tag (`<` up to the next `>`) replaced by `gap`: what
|
|
13
|
+
* `.replace(/<[^>]*>/g, gap)` did, without rescanning to the end from every `<` when no `>`
|
|
14
|
+
* follows. As there, a `<` with no `>` after it stays.
|
|
15
|
+
*/
|
|
16
|
+
export function stripTags(html , gap ) {
|
|
17
|
+
let out = "";
|
|
18
|
+
let at = 0;
|
|
19
|
+
for (;;) {
|
|
20
|
+
const open = html.indexOf("<", at);
|
|
21
|
+
if (open === -1) break;
|
|
22
|
+
const close = html.indexOf(">", open + 1);
|
|
23
|
+
if (close === -1) break;
|
|
24
|
+
out += html.slice(at, open) + gap;
|
|
25
|
+
at = close + 1;
|
|
26
|
+
}
|
|
27
|
+
return at === 0 ? html : out + html.slice(at);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const NAMED = { amp: "&", lt: "<", gt: ">", quot: '"', "#39": "'" };
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Text of HTML this module's callers rendered (meta and feed descriptions, JSON-LD,
|
|
34
|
+
* table-of-contents labels, heading ids, reading time): tags dropped, entities decoded once,
|
|
35
|
+
* whitespace collapsed.
|
|
36
|
+
*
|
|
37
|
+
* **Plain text, not HTML.** Decoding is the point (`Array<string>` reads `Array<string>`),
|
|
38
|
+
* so the result can hold `<script>` when the source said `<script>`. Every sink escapes it
|
|
39
|
+
* for its context, and `test/html-text-sinks.test.ts` checks each one with that input: Astro
|
|
40
|
+
* attributes and text (meta, og, twitter, the table of contents), `jsonLdText` (JSON-LD:
|
|
41
|
+
* `<`, `>` and `&` as `\u003c`…, so no `</script>` or `<!--`), the feeds' `xml()` (RSS). A new
|
|
42
|
+
* caller must put the result through an escaping sink too, never `set:html`.
|
|
43
|
+
*
|
|
44
|
+
* Entities are decoded in one pass, so `&lt;` is the text `<`, and `&#60;` the text
|
|
45
|
+
* `<` (the regex chain before decoded those twice).
|
|
46
|
+
*/
|
|
47
|
+
export function htmlText(html ) {
|
|
48
|
+
return stripTags(html, " ")
|
|
49
|
+
.replace(/&(amp|lt|gt|quot|#39|#(\d{1,7}));/g, (m, name , code ) => {
|
|
50
|
+
if (code === undefined) return NAMED[name] ?? m;
|
|
51
|
+
const n = Number(code);
|
|
52
|
+
return n <= 0x10ffff ? String.fromCodePoint(n) : m;
|
|
53
|
+
})
|
|
54
|
+
.replace(/\s+/g, " ")
|
|
55
|
+
.trim();
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** `\s` runs and the last `\n` inside them, for `leadingHeading`. */
|
|
59
|
+
function skipSpace(text , from ) {
|
|
60
|
+
let i = from;
|
|
61
|
+
let lastNl = -1;
|
|
62
|
+
for (; isSpace(text[i]); i++) if (text[i] === "\n") lastNl = i;
|
|
63
|
+
return { end: i, lastNl };
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Where `\s*#*\s*(?:\r?\n|$)` from `at` ends (the old regex's tail, with its backtracking worked
|
|
68
|
+
* out): at the end of the text when only whitespace and `#`s are left; else after the last `\n`
|
|
69
|
+
* of the whitespace after the `#`s; else after the last `\n` of the whitespace before them; -1
|
|
70
|
+
* when none of those exist.
|
|
71
|
+
*/
|
|
72
|
+
function headingTailEnd(text , at ) {
|
|
73
|
+
const before = skipSpace(text, at);
|
|
74
|
+
if (before.end === text.length) return text.length;
|
|
75
|
+
let hashes = before.end;
|
|
76
|
+
while (text[hashes] === "#") hashes++;
|
|
77
|
+
const after = skipSpace(text, hashes);
|
|
78
|
+
if (after.end === text.length) return text.length;
|
|
79
|
+
if (after.lastNl !== -1) return after.lastNl + 1;
|
|
80
|
+
return before.lastNl !== -1 ? before.lastNl + 1 : -1;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* The opening ATX heading of a markdown body (`# Title`, closing `#`s allowed): its text, and how
|
|
85
|
+
* much of the body it takes (the blank lines and `#`-only lines after it too). Exactly what
|
|
86
|
+
* `/^\s*#\s+(.+?)\s*#*\s*(?:\r?\n|$)/` matched (text trimmed), in one pass: that regex was cubic
|
|
87
|
+
* on a heading line of spaces (CodeQL js/polynomial-redos, alert 17).
|
|
88
|
+
*/
|
|
89
|
+
export function leadingHeading(markdown ) {
|
|
90
|
+
let p = 0;
|
|
91
|
+
while (isSpace(markdown[p])) p++;
|
|
92
|
+
if (markdown[p] !== "#") return undefined;
|
|
93
|
+
p++;
|
|
94
|
+
// `\s+`: at least one, and it may cross line breaks.
|
|
95
|
+
const r = skipSpace(markdown, p).end;
|
|
96
|
+
if (r === p) return undefined;
|
|
97
|
+
if (r < markdown.length) {
|
|
98
|
+
// `(.+?)` from `r` up to the line's end: the shortest text whose rest of line is `\s*#*\s*`.
|
|
99
|
+
let lineEnd = r;
|
|
100
|
+
while (lineEnd < markdown.length && !LINE_BREAK.test(markdown[lineEnd] )) lineEnd++;
|
|
101
|
+
// The tail must cover the rest of the line (it holds no `\n` there), so the text ends where
|
|
102
|
+
// the line's last `\s*#*\s*` starts. Past the line the tail runs on through whitespace (a
|
|
103
|
+
// `\u2028` or a lone `\r` is whitespace, not a `\n`), so where the `#`s fall can differ: a
|
|
104
|
+
// text ending before the line's closing `#`s, or one keeping them and ending before the
|
|
105
|
+
// trailing whitespace. The earlier one that works is the regex's (lazy) answer.
|
|
106
|
+
let trailing = lineEnd;
|
|
107
|
+
while (trailing > r && isSpace(markdown[trailing - 1])) trailing--;
|
|
108
|
+
let closing = trailing;
|
|
109
|
+
while (closing > r && markdown[closing - 1] === "#") closing--;
|
|
110
|
+
while (closing > r && isSpace(markdown[closing - 1])) closing--;
|
|
111
|
+
for (const e of new Set([Math.max(closing, r + 1), Math.max(trailing, r + 1)])) {
|
|
112
|
+
const end = headingTailEnd(markdown, e);
|
|
113
|
+
if (end !== -1) return { text: markdown.slice(r, e).trim(), length: end };
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
// No text from `r` works (or the whitespace runs to the end): the regex backs `\s+` off,
|
|
117
|
+
// keeping at least one, until `(.+?)` can take one whitespace character that is not a line
|
|
118
|
+
// break and the tail after it ends: at the end of the text, or after a `\n` before `r`.
|
|
119
|
+
const run = skipSpace(markdown, p);
|
|
120
|
+
const tailEnd = r === markdown.length ? r : run.lastNl;
|
|
121
|
+
for (let q = tailEnd - 1; q > p; q--)
|
|
122
|
+
if (!LINE_BREAK.test(markdown[q] ))
|
|
123
|
+
return { text: "", length: r === markdown.length ? r : run.lastNl + 1 };
|
|
124
|
+
return undefined;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/** A heading `renderMarkdown` wrote: `<h2 id="…">…</h2>` or `<h3 …>`. */
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* The `<h2 id="…">…</h2>` and `<h3 id="…">…</h3>` of rendered HTML, in order: what
|
|
136
|
+
* `/<h([23]) id="([^"]+)">([\s\S]*?)<\/h\1>/g` found, without rescanning to the end from every
|
|
137
|
+
* opening tag when its closing tag is missing.
|
|
138
|
+
*/
|
|
139
|
+
export function renderedHeadings(html ) {
|
|
140
|
+
const out = [];
|
|
141
|
+
// Where the next `</h2>` / `</h3>` is (-1: none after the last search), so each is searched once.
|
|
142
|
+
const closer = { 2: -2, 3: -2 } ;
|
|
143
|
+
let at = 0;
|
|
144
|
+
for (;;) {
|
|
145
|
+
const open = html.indexOf("<h", at);
|
|
146
|
+
if (open === -1) return out;
|
|
147
|
+
at = open + 1;
|
|
148
|
+
const digit = html[open + 2];
|
|
149
|
+
if (digit !== "2" && digit !== "3") continue;
|
|
150
|
+
if (!html.startsWith(' id="', open + 3)) continue;
|
|
151
|
+
const idStart = open + 8;
|
|
152
|
+
const idEnd = html.indexOf('"', idStart);
|
|
153
|
+
if (idEnd <= idStart || html[idEnd + 1] !== ">") continue;
|
|
154
|
+
const depth = digit === "2" ? 2 : 3;
|
|
155
|
+
const innerStart = idEnd + 2;
|
|
156
|
+
if (closer[depth] !== -1 && closer[depth] < innerStart)
|
|
157
|
+
closer[depth] = html.indexOf(`</h${depth}>`, innerStart);
|
|
158
|
+
const end = closer[depth];
|
|
159
|
+
if (end === -1) continue;
|
|
160
|
+
out.push({ depth, id: html.slice(idStart, idEnd), inner: html.slice(innerStart, end) });
|
|
161
|
+
at = end + 5;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
const isWordChar = (c ) => c !== undefined && /\w/.test(c);
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* Whether a line of `markdown`, after leading whitespace and `>` quote markers, starts with an
|
|
169
|
+
* `::embed` directive: what `/(^|\n)\s*(?:>\s*)*::embed\b/` tested, in one pass. That regex
|
|
170
|
+
* retried its whitespace run from every line start of a run of blank lines.
|
|
171
|
+
*/
|
|
172
|
+
export function hasEmbedLine(markdown ) {
|
|
173
|
+
let at = 0;
|
|
174
|
+
for (;;) {
|
|
175
|
+
let i = at;
|
|
176
|
+
while (i < markdown.length && (markdown[i] === ">" || isSpace(markdown[i]))) i++;
|
|
177
|
+
if (markdown.startsWith("::embed", i) && !isWordChar(markdown[i + 7])) return true;
|
|
178
|
+
// Line starts inside the skipped run lead to the same place; the next one after it may not.
|
|
179
|
+
const nl = markdown.indexOf("\n", i);
|
|
180
|
+
if (nl === -1) return false;
|
|
181
|
+
at = nl + 1;
|
|
182
|
+
}
|
|
183
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloudhal/astro-renderer",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.1",
|
|
4
4
|
"description": "Render a Cloudhal Site Graph with Astro: data sources (live/snapshot), section components and the cloudhal() integration",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"homepage": "https://cloudhal.dev",
|
|
@@ -223,21 +223,21 @@
|
|
|
223
223
|
"README.md"
|
|
224
224
|
],
|
|
225
225
|
"dependencies": {
|
|
226
|
-
"@cloudhal/core-contracts": "0.7.
|
|
227
|
-
"@cloudhal/core-ts": "0.7.
|
|
228
|
-
"@cloudhal/storage": "0.7.
|
|
226
|
+
"@cloudhal/core-contracts": "0.7.1",
|
|
227
|
+
"@cloudhal/core-ts": "0.7.1",
|
|
228
|
+
"@cloudhal/storage": "0.7.1",
|
|
229
229
|
"marked": "^18.1.1",
|
|
230
|
-
"parse5": "8.0
|
|
231
|
-
"@cloudhal/analytics": "0.7.
|
|
230
|
+
"parse5": "8.1.0",
|
|
231
|
+
"@cloudhal/analytics": "0.7.1",
|
|
232
232
|
"vite": "^8.3.5",
|
|
233
|
-
"@cloudhal/comments": "0.7.
|
|
233
|
+
"@cloudhal/comments": "0.7.1"
|
|
234
234
|
},
|
|
235
235
|
"peerDependencies": {
|
|
236
236
|
"astro": "^7.4.0",
|
|
237
237
|
"@astrojs/cloudflare": "^14.3.0"
|
|
238
238
|
},
|
|
239
239
|
"devDependencies": {
|
|
240
|
-
"@astrojs/cloudflare": "14.4.
|
|
240
|
+
"@astrojs/cloudflare": "14.4.6",
|
|
241
241
|
"@cloudflare/workers-types": "^5.20261007.1",
|
|
242
242
|
"@types/node": "^26.6.5",
|
|
243
243
|
"astro": "^7.4.7",
|