@odla-ai/blog 0.0.5 → 0.0.6

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/README.md CHANGED
@@ -47,6 +47,15 @@ same-named file in your site's `theme/` directory. Build your site with the
47
47
  package API and preview the emitted static directory with your usual local
48
48
  static server.
49
49
 
50
+ ## Input boundaries
51
+
52
+ Footnote identifiers are capped at 256 characters, and malformed `[^`
53
+ introducers are handled by a monotonic scanner so adversarial Markdown cannot
54
+ force repeated whole-suffix regex scans. Markdown still permits authored raw
55
+ HTML by design; it is not a sanitizer. JS pages and collection templates must
56
+ use `escapeHtml(String(value))` for every schema-free frontmatter value or
57
+ filename-derived slug placed into HTML.
58
+
50
59
  ## Deploy (Cloudflare)
51
60
 
52
61
  `build()` emits a plain static directory; serve it from a Worker assets
package/llms.txt CHANGED
@@ -87,7 +87,9 @@ package (`import { escapeHtml, renderMarkdown, postList } from "@odla-ai/blog"`)
87
87
  ## Markdown extras
88
88
 
89
89
  - **Footnotes** (GFM `[^1]` / `[^1]: text`) render as numbered superscript
90
- links plus a `<section class="footnotes">` appended to the content.
90
+ links plus a `<section class="footnotes">` appended to the content. IDs are
91
+ limited to 256 characters, and malformed introducers are handled by a
92
+ monotonic scanner rather than repeated whole-suffix regex matching.
91
93
  - **Smart typography**: `--`/`---` become em dashes and straight quotes curl,
92
94
  in prose text only — code spans and blocks are never touched.
93
95
  - **Excerpts**: the home page (`indexLimit` most recent, default 20) and
@@ -130,6 +132,11 @@ GitHub-flavored, rendered by `marked`. Fenced code blocks are highlighted at
130
132
  build time by highlight.js (`lib/common` language set) into `hljs-*` classes —
131
133
  no client-side JS. Headings get slugified `id` anchors.
132
134
 
135
+ Authored raw HTML remains enabled; this renderer is not a sanitizer. Treat
136
+ schema-free collection/frontmatter fields and filename-derived slugs as
137
+ untrusted when writing a JS page, and apply `escapeHtml(String(value))` in the
138
+ correct HTML context.
139
+
133
140
  ## Theming
134
141
 
135
142
  Bundled themes: `juniper` (default), `salt`, `chalk`, `clay` — pick with
@@ -179,7 +186,7 @@ to the theme's CSS (after the `ui.css` aliases). Post URLs live under
179
186
 
180
187
  The output is a plain static directory — serve it from a Worker's assets
181
188
  binding (this is what `blog init --deploy cloudflare` will generate; a
182
- the public platform manual documents the same Worker + assets composition):
189
+ the public machine-readable platform runbook documents the same Worker + assets composition):
183
190
 
184
191
  ```js
185
192
  // build-site.mjs — run before every deploy
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@odla-ai/blog",
3
- "version": "0.0.5",
3
+ "version": "0.0.6",
4
4
  "description": "Minimal-dependency, static-first blogging platform. Files in, site out; odla-db lights up interactivity when configured.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -34,7 +34,7 @@
34
34
  "prepublishOnly": "npm run gen:llms && npm test"
35
35
  },
36
36
  "dependencies": {
37
- "@odla-ai/ui": "^0.2.2",
37
+ "@odla-ai/ui": "^0.3.0",
38
38
  "highlight.js": "^11.11.0",
39
39
  "marked": "^16.0.0",
40
40
  "yaml": "^2.8.0"
package/src/markdown.js CHANGED
@@ -32,6 +32,62 @@ export function slugify(text) {
32
32
  let footnoteNumbers = new Map(); // id → number, in first-reference order
33
33
  let footnoteBodies = new Map(); // id → rendered inline HTML
34
34
  let headingIds = new Map(); // base slug → occurrences in this document
35
+ const MAX_FOOTNOTE_ID_LENGTH = 256;
36
+ const footnoteWhitespace = /\s/u;
37
+
38
+ // Return one syntactically valid reference at or after `from`. Both the search
39
+ // cursor and every candidate cursor move only forward, while malformed IDs are
40
+ // capped, so adversarial runs of "[^" remain linear in the input size.
41
+ function findFootnoteReference(source, from = 0) {
42
+ let cursor = from;
43
+ while (cursor < source.length) {
44
+ const start = source.indexOf("[^", cursor);
45
+ if (start < 0) return;
46
+ const reference = parseFootnoteReference(source, start);
47
+ if (reference) return reference;
48
+ cursor = start + 2;
49
+ }
50
+ }
51
+
52
+ function parseFootnoteReference(source, start = 0) {
53
+ if (source[start] !== "[" || source[start + 1] !== "^") return;
54
+ const idEnd = footnoteIdEnd(source, start + 2);
55
+ if (idEnd === undefined || source[idEnd + 1] === ":") return;
56
+ return { index: start, id: source.slice(start + 2, idEnd), raw: source.slice(start, idEnd + 1) };
57
+ }
58
+
59
+ function footnoteIdEnd(source, start) {
60
+ for (let length = 0; start + length < source.length && length <= MAX_FOOTNOTE_ID_LENGTH; length++) {
61
+ const char = source[start + length];
62
+ if (char === "]") return length ? start + length : undefined;
63
+ if (footnoteWhitespace.test(char) || length === MAX_FOOTNOTE_ID_LENGTH) return;
64
+ }
65
+ }
66
+
67
+ // Parse a definition's first line and its ≥2-character horizontal-indent
68
+ // continuation lines without a nested, backtracking regular expression.
69
+ function parseFootnoteDefinition(source) {
70
+ if (!source.startsWith("[^")) return;
71
+ const idEnd = footnoteIdEnd(source, 2);
72
+ if (idEnd === undefined || source[idEnd + 1] !== ":") return;
73
+ let cursor = idEnd + 2;
74
+ while (source[cursor] === " " || source[cursor] === "\t") cursor++;
75
+ let lineEnd = source.indexOf("\n", cursor);
76
+ if (lineEnd < 0) lineEnd = source.length;
77
+ const body = [source.slice(cursor, lineEnd)];
78
+ let rawEnd = lineEnd;
79
+ while (lineEnd < source.length) {
80
+ const indentStart = lineEnd + 1;
81
+ let contentStart = indentStart;
82
+ while (source[contentStart] === " " || source[contentStart] === "\t") contentStart++;
83
+ if (contentStart - indentStart < 2) break;
84
+ lineEnd = source.indexOf("\n", contentStart);
85
+ if (lineEnd < 0) lineEnd = source.length;
86
+ body.push(source.slice(contentStart, lineEnd));
87
+ rawEnd = lineEnd;
88
+ }
89
+ return { id: source.slice(2, idEnd), raw: source.slice(0, rawEnd), text: body.join(" ").trim() };
90
+ }
35
91
 
36
92
  function uniqueHeadingId(text) {
37
93
  const base = slugify(text);
@@ -47,10 +103,12 @@ const footnotes = {
47
103
  footnoteBodies = new Map();
48
104
  headingIds = new Map();
49
105
  // Number by first reference (definitions like "[^id]:" excluded).
50
- for (const match of markdown.matchAll(/\[\^([^\]\s]+)\](?!:)/g)) {
51
- if (!footnoteNumbers.has(match[1])) {
52
- footnoteNumbers.set(match[1], footnoteNumbers.size + 1);
106
+ let reference = findFootnoteReference(markdown);
107
+ while (reference) {
108
+ if (!footnoteNumbers.has(reference.id)) {
109
+ footnoteNumbers.set(reference.id, footnoteNumbers.size + 1);
53
110
  }
111
+ reference = findFootnoteReference(markdown, reference.index + reference.raw.length);
54
112
  }
55
113
  return markdown;
56
114
  },
@@ -71,14 +129,13 @@ const footnotes = {
71
129
  level: "block",
72
130
  tokenizer(src) {
73
131
  // "[^id]: text" plus continuation lines indented ≥2 spaces.
74
- const match = /^\[\^([^\]\s]+)\]:[ \t]*([^\n]*(?:\n[ \t]{2,}[^\n]*)*)/.exec(src);
75
- if (!match) return;
76
- const text = match[2].replace(/\n[ \t]+/g, " ").trim();
132
+ const definition = parseFootnoteDefinition(src);
133
+ if (!definition) return;
77
134
  return {
78
135
  type: "footnoteDef",
79
- raw: match[0],
80
- id: match[1],
81
- tokens: this.lexer.inlineTokens(text),
136
+ raw: definition.raw,
137
+ id: definition.id,
138
+ tokens: this.lexer.inlineTokens(definition.text),
82
139
  };
83
140
  },
84
141
  renderer(token) {
@@ -95,10 +152,14 @@ const footnotes = {
95
152
  return src.indexOf("[^");
96
153
  },
97
154
  tokenizer(src) {
98
- const match = /^\[\^([^\]\s]+)\](?!:)/.exec(src);
99
- if (match && footnoteNumbers.has(match[1])) {
100
- return { type: "footnoteRef", raw: match[0], id: match[1] };
155
+ if (!src.startsWith("[^")) return;
156
+ const reference = parseFootnoteReference(src);
157
+ if (reference && footnoteNumbers.has(reference.id)) {
158
+ return { type: "footnoteRef", raw: reference.raw, id: reference.id };
101
159
  }
160
+ // Consume the introducer as ordinary text. Returning here prevents
161
+ // Marked from retrying every malformed prefix against the whole suffix.
162
+ return { type: "text", raw: "[^", text: "[^" };
102
163
  },
103
164
  renderer(token) {
104
165
  const n = footnoteNumbers.get(token.id);