@zvndev/darkmown 0.12.0 → 0.13.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/AGENTS.md +14 -7
- package/CHANGELOG.md +22 -0
- package/README.md +90 -6
- package/SECURITY.md +39 -0
- package/docs/spec-alignment.md +13 -2
- package/package.json +3 -2
- package/site/_/empty.json +1 -0
- package/site/_/og.png +0 -0
- package/site/pages/app.wd +1 -1
- package/site/pages/data.wd +41 -0
- package/site/pages/docs/index.wd +57 -7
- package/site/pages/index.wd +3 -2
- package/site/pages/reactive.wd +20 -7
- package/src/builder.js +32 -0
- package/src/cli.js +31 -8
- package/src/compiler.js +228 -28
- package/src/runtime.js +113 -5
- package/src/statics.js +1 -0
package/AGENTS.md
CHANGED
|
@@ -7,7 +7,7 @@ Darkmown is a Markdown-native web framework. You build sites by writing `.md` an
|
|
|
7
7
|
- `.md` files are plain CommonMark. Directives stay inert text.
|
|
8
8
|
- `.wd` files are the same Markdown **plus directives** (state, loops, conditionals, includes, forms).
|
|
9
9
|
- To make a `.md` page interactive, **rename it to `.wd`**. ⚠️ Renaming means the old `.md` is **gone** — never leave both `index.md` and `index.wd`, that is a fatal `Duplicate route` build error. Upgrade = delete the `.md`, create the `.wd`.
|
|
10
|
-
- Static pages ship **zero** JavaScript; a page loads the ~
|
|
10
|
+
- Static pages ship **zero** JavaScript; a page loads the ~5.7 KB gzipped runtime (CI-enforced under 6 KB) only if it declares reactive behavior.
|
|
11
11
|
|
|
12
12
|
## Project layout & routing
|
|
13
13
|
|
|
@@ -57,13 +57,15 @@ Button actions are a **fixed whitelist**: `x++`, `x--`, `x += <number>`, `list +
|
|
|
57
57
|
|
|
58
58
|
### Conditionals
|
|
59
59
|
```wd
|
|
60
|
-
:if
|
|
61
|
-
|
|
60
|
+
:if isPro
|
|
61
|
+
Pro plan.
|
|
62
|
+
:else if isTrial
|
|
63
|
+
Trial.
|
|
62
64
|
:else
|
|
63
|
-
|
|
65
|
+
Free plan.
|
|
64
66
|
:endif
|
|
65
67
|
```
|
|
66
|
-
`:if name.path` tests a dotted path. Conditionals nest, including per-row inside a loop.
|
|
68
|
+
`:if name.path` tests a dotted path for truthiness (a bare path — no operators). Chain with `:else if` (any number; a bare `:else` must be last). Conditionals nest, including per-row inside a loop.
|
|
67
69
|
|
|
68
70
|
### Loops — the only loop
|
|
69
71
|
```wd
|
|
@@ -120,8 +122,13 @@ Thanks, **{ profile.name }**!
|
|
|
120
122
|
:endif
|
|
121
123
|
|
|
122
124
|
:computed total = items.length * 4 ← derived state; arithmetic & comparisons only
|
|
125
|
+
|
|
126
|
+
:store session = { "Authorization": "Bearer …" } ← persisted token
|
|
127
|
+
:fetch feed from "/api/feed" headers=session refresh="/auth/refresh" ← auth header; 401 → renew token, retry once
|
|
128
|
+
|
|
129
|
+
:effect q -> searches++ ← run actions when watched state changes
|
|
123
130
|
```
|
|
124
|
-
Shelf `.json` files (in `site/_/`) publish to `/__wd/data/`. `:form action="/api/x" into reply` posts urlencoded and lands the JSON reply in state (without JS it degrades to a native POST). Darkmown owns no backend — point forms at your own API.
|
|
131
|
+
Shelf `.json` files (in `site/_/`) publish to `/__wd/data/`. `:form action="/api/x" into reply` posts urlencoded and lands the JSON reply in state (without JS it degrades to a native POST). Darkmown owns no backend — point forms at your own API. `:fetch`/`refresh=` URLs must be relative, `http(s)://`, or a leading `{ state }` interpolation. `:effect` actions are the `:button` vocabulary (`;`-chained); effects run on change, not on load, capped at 10 settle passes.
|
|
125
132
|
|
|
126
133
|
**Form-state rules (these cause most form failures):**
|
|
127
134
|
- `:form into x` declares `x` only at `:endform`. A `:if x` (or `{ x.field }`) that reads it must come **after `:endform`**, never inside the form body.
|
|
@@ -144,7 +151,7 @@ Your `.skin` selectors must match the **real** output. The emitted HTML is:
|
|
|
144
151
|
| reactive `@loop` of a list | `<ul>`/`<ol>` (or `<div>`) of items |
|
|
145
152
|
| `{ name }` | a text node |
|
|
146
153
|
|
|
147
|
-
So style with real selectors: `section`, `.card`, `button`, `input`, `form`, `h1`. **To add a class to a container, use `::: name .class`. For any other custom element, write raw HTML `<div class="…">`. There is NO `{.class}` attribute syntax.**
|
|
154
|
+
So style with real selectors: `section`, `.card`, `button`, `input`, `form`, `h1`. **To add a class to a container, use `::: name .class`. For any other custom element, write raw HTML `<div class="…">`. There is NO `{.class}` attribute syntax.** A container class can also be reactive: `::: card .on-sale when p.price < 50` toggles the class from a predicate (same whitelist as `@loop … where`).
|
|
148
155
|
|
|
149
156
|
## Styling with `.skin` — ship this on every page
|
|
150
157
|
|
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,28 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to Darkmown are documented here. Versions follow [semver](https://semver.org); pre-1.0 minor versions may contain breaking changes.
|
|
4
4
|
|
|
5
|
+
## 0.13.0 — 2026-06-18
|
|
6
|
+
|
|
7
|
+
Layered capabilities — four reactive features shaped as progressive disclosure: a simple default, with more power one layer down. The reactive runtime grew to ~5.7 KB gzipped; the CI budget moves from 5 KB to **6 KB** (still shipped un-minified, source fully commented).
|
|
8
|
+
|
|
9
|
+
- **Conditionals — `:else if` chains.** `:if A` / `:else if B` / … / `:else` / `:endif`. Any number of `:else if`; an optional trailing bare `:else` must come last (a later `:else if` is a compile error). Desugars to nested `:if` regions the runtime already drives — identical behavior for static, reactive, and loop-row conditionals, and no runtime change.
|
|
10
|
+
- **Styling — reactive classes (`::: … .class when <predicate>`).** A container class can be toggled by a predicate using the same whitelisted grammar as `@loop … where` / `:if` (`item.field`, `:state`, `==`/`!=`/`>`/`<`/`>=`/`<=`/`contains`, `and`/`or`). A fully-static predicate folds at build time; a state predicate becomes a global `data-wd-class` binding; a loop-item predicate reacts per row. Static `.class` tokens are unchanged.
|
|
11
|
+
- **Fetch — authenticated requests + token refresh (`:fetch … headers= refresh=`).** `headers=<stateKey>` (already shipped) spreads a state object into request headers; pair with `:store` to persist a bearer token. New `refresh="<url>"`: on an HTTP 401 the runtime POSTs the current headers to the refresh URL, writes the renewed token back to state (persisting if it is a `:store`), and retries the original request once. Concurrent 401s sharing a refresh URL are de-duplicated into a single in-flight refresh.
|
|
12
|
+
- **Effects — `:effect <state> -> <actions>`.** Run actions (the full `:button` vocabulary, `;`-chained) whenever a watched state path changes — for side effects beyond `:computed` (derive state) and fetch deps (auto-refetch). Effects run after a render against settled state, with a 10-pass settle cap guarding against effect→effect loops.
|
|
13
|
+
- **Assets — page-colocated static files.** Any non-page file under `site/pages/` (images, SVG, fonts — anything but `.md`/`.wd`/`.skin`/`.js`) is copied to `dist/` at its path: `site/pages/logo.svg` → `dist/logo.svg`, `site/pages/blog/cover.png` → `dist/blog/cover.png`. The shelf (`site/_/` → `/__wd/media`, `/__wd/data`) is unchanged; `.avif` joins the served content-types.
|
|
14
|
+
- **Security — `:fetch` URL scheme hardening.** `:fetch` (and `refresh=`) URLs are validated at compile time: relative paths, `http(s)://`, and a leading `{ state }` interpolation are allowed; a protocol-relative `//host` or any non-http(s) scheme (`file:`, `data:`, `javascript:`, …) is now a compile error with a corrective hint.
|
|
15
|
+
|
|
16
|
+
## 0.12.1 — 2026-06-18
|
|
17
|
+
|
|
18
|
+
Release-hygiene and DX polish (post-0.12.0 smoke audit).
|
|
19
|
+
|
|
20
|
+
- **Clean compile errors.** `darkmown build` prints a single `✗ <message>` line on a compile error instead of a raw Node.js stack trace (the dev rebuild log inherits the same clean output). The message still carries the file path and corrective hint.
|
|
21
|
+
- **Bare `darkmown` prints help.** Running the command with no arguments shows usage instead of silently running a build.
|
|
22
|
+
- **Social-share images.** A new `image:` frontmatter key sets `og:image` / `twitter:image` and upgrades the Twitter card to `summary_large_image`. The home page now ships an Open Graph card.
|
|
23
|
+
- **`SECURITY.md` ships in the package** so the README's in-package security link resolves for npm consumers.
|
|
24
|
+
- **Static assets documented.** README explains that non-page shelf files (`site/_/`) are copied to `/__wd/media/` (and `.json` to `/__wd/data/`).
|
|
25
|
+
- **README badges** added (npm version, CI, provenance, license).
|
|
26
|
+
|
|
5
27
|
## 0.12.0 — 2026-06-18
|
|
6
28
|
|
|
7
29
|
Security and deploy-hardening sprint.
|
package/README.md
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
# Darkmown
|
|
2
2
|
|
|
3
|
+
[](https://www.npmjs.com/package/@zvndev/darkmown)
|
|
4
|
+
[](https://github.com/ZVN-DEV/darkmown/actions/workflows/ci.yml)
|
|
5
|
+
[](https://www.npmjs.com/package/@zvndev/darkmown)
|
|
6
|
+
[](./LICENSE)
|
|
7
|
+
|
|
3
8
|
**[darkmown.com](https://darkmown.com)** · Markdown that runs.
|
|
4
9
|
|
|
5
|
-
Darkmown is a Markdown-native web framework. Two formats, one rule: `.md` stays plain CommonMark forever, and renaming a file to `.wd` ("whateverdown") is what unlocks directives — includes, loops, state, conditionals, and sections. Static pages ship **zero** framework JavaScript; reactive pages share one runtime around ~
|
|
10
|
+
Darkmown is a Markdown-native web framework. Two formats, one rule: `.md` stays plain CommonMark forever, and renaming a file to `.wd` ("whateverdown") is what unlocks directives — includes, loops, state, conditionals, and sections. Static pages ship **zero** framework JavaScript; reactive pages share one runtime around ~5.7 KB gzipped, CI-enforced under 6 KB.
|
|
6
11
|
|
|
7
12
|
## Quick start
|
|
8
13
|
|
|
@@ -47,7 +52,7 @@ npm run dev # live demo site — the same site that runs darkmown.com
|
|
|
47
52
|
- Files or folders starting with `.`, `-`, or `_` are hidden from routing.
|
|
48
53
|
- `site/_` is the include shelf for `@include /name.wd`.
|
|
49
54
|
- Matching `page.skin` and `page.js` colocate styling and behavior by basename.
|
|
50
|
-
- Static pages ship zero Darkmown runtime. Reactive pages share `/__wd/runtime.js` (currently ~
|
|
55
|
+
- Static pages ship zero Darkmown runtime. Reactive pages share `/__wd/runtime.js` (currently ~5.7 KB gzipped, CI-enforced under 6 KB).
|
|
51
56
|
- Shelf `.json` files are published at `/__wd/data/` so `:fetch` works on any static host.
|
|
52
57
|
|
|
53
58
|
## Interpolation
|
|
@@ -74,6 +79,24 @@ tags: [sales, revenue, "q1, q2"]
|
|
|
74
79
|
- `@loop meta.tags into tag` iterates an array field at build time (stays static, zero-JS).
|
|
75
80
|
- Arrays are inline flow only (`[a, b]`); quoted items keep internal commas (`"q1, q2"`). A value without a leading `[` stays a plain string.
|
|
76
81
|
|
|
82
|
+
Three keys also drive the document `<head>`: `title` sets `<title>`, `description` adds the meta description plus Open Graph / Twitter tags, and `image` (an absolute URL) sets the social-share preview (`og:image` / `twitter:image` and a `summary_large_image` card).
|
|
83
|
+
|
|
84
|
+
## Static assets
|
|
85
|
+
|
|
86
|
+
Images, fonts, icons, and other non-page files live on the include shelf at `site/_/` and are copied into the build untouched:
|
|
87
|
+
|
|
88
|
+
- Any non-`.md`/`.wd` file in `site/_/` → served at `/__wd/media/<path>` (e.g. `site/_/logo.svg` → `/__wd/media/logo.svg`).
|
|
89
|
+
- `.json` files → served at `/__wd/data/<name>` (this is what `:fetch` reads).
|
|
90
|
+
|
|
91
|
+
Reference them with a normal URL: ``. The preview/`serve` layer returns the correct `Content-Type` per extension.
|
|
92
|
+
|
|
93
|
+
**Or colocate an asset next to the page that uses it.** Any non-page file under `site/pages/` (anything but `.md`/`.wd` routes and the colocated `.skin`/`.js`) is copied to `dist/` at its own path, so a clean relative URL just works:
|
|
94
|
+
|
|
95
|
+
- `site/pages/logo.svg` → `dist/logo.svg` → ``
|
|
96
|
+
- `site/pages/blog/cover.png` → `dist/blog/cover.png` → ``
|
|
97
|
+
|
|
98
|
+
Use the shelf for assets shared across many pages; colocate the ones that belong to a single page or section. Both ship untouched with the correct content-type.
|
|
99
|
+
|
|
77
100
|
## Loops
|
|
78
101
|
|
|
79
102
|
`@loop <things> into <thing>` is the only loop. The source decides the behavior:
|
|
@@ -224,6 +247,20 @@ Cart has { count } items.
|
|
|
224
247
|
|
|
225
248
|
State declared inside a section is scoped to it — two sections can both own a `count`. Bindings and actions resolve to the nearest scope.
|
|
226
249
|
|
|
250
|
+
### Reactive classes — `.class when <predicate>`
|
|
251
|
+
|
|
252
|
+
A container class can be toggled by a predicate. Static `.class` tokens are unchanged; add `when <predicate>` to make one reactive:
|
|
253
|
+
|
|
254
|
+
```wd
|
|
255
|
+
@loop products into p
|
|
256
|
+
::: card .product .on-sale when p.price < 50 .featured when p.featured
|
|
257
|
+
**{ p.name }** — ${ p.price }
|
|
258
|
+
:::
|
|
259
|
+
@endloop
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
The predicate uses the same whitelist as `@loop … where` / `:if` — item fields, declared `:state`/`:store`, numbers, strings, the `==`/`!=`/`>`/`<`/`>=`/`<=`/`contains` operators, and `and`/`or`. A bare path (`.featured when p.featured`) reads as truthy. A predicate over only static values folds at build time into a plain class; one that reads state or the loop item stays reactive and ships with the runtime.
|
|
263
|
+
|
|
227
264
|
## Reactive directives
|
|
228
265
|
|
|
229
266
|
```wd
|
|
@@ -240,6 +277,20 @@ Count is still zero.
|
|
|
240
277
|
:endif
|
|
241
278
|
```
|
|
242
279
|
|
|
280
|
+
Conditionals chain with `:else if`. Each condition is a bare truthy path (the same form `:if` takes — no operators). Use any number of them; an optional bare `:else` must be the last branch:
|
|
281
|
+
|
|
282
|
+
```wd
|
|
283
|
+
:if isPro
|
|
284
|
+
Pro plan
|
|
285
|
+
:else if isTrial
|
|
286
|
+
Trial — { daysLeft } days left
|
|
287
|
+
:else
|
|
288
|
+
Free plan
|
|
289
|
+
:endif
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
A whole chain compiles to nested conditional regions, so it stays reactive (or folds at build time when the values are static) exactly like a single `:if`.
|
|
293
|
+
|
|
243
294
|
Directive actions are intentionally narrow and compile-time checked. Arbitrary JavaScript belongs in colocated `.js` files.
|
|
244
295
|
|
|
245
296
|
### Button actions
|
|
@@ -281,6 +332,19 @@ Values are literals: a `"string"`, number, `true`/`false`/`null`, or inline JSON
|
|
|
281
332
|
|
|
282
333
|
> **Pitfall:** `list toggle v` and `list remove v` match members by value (`===`). That is exact for strings, numbers, and booleans, but not reliable for object members — two equal-looking objects are different values. To remove a row object, loop the list and use the per-row `remove` action below.
|
|
283
334
|
|
|
335
|
+
### Effects — `:effect`
|
|
336
|
+
|
|
337
|
+
`:effect <watched> -> <actions>` runs actions whenever a watched state path changes. The actions are the same `:button` vocabulary (`;`-chained) — this is the escape hatch for side effects beyond `:computed` (which derives state) and `:fetch` deps (which auto-refetch):
|
|
338
|
+
|
|
339
|
+
```wd
|
|
340
|
+
:state q = ""
|
|
341
|
+
:state searches = 0
|
|
342
|
+
|
|
343
|
+
:effect q -> searches++
|
|
344
|
+
```
|
|
345
|
+
|
|
346
|
+
Effects run after a render, against settled state, and an effect that mutates state triggers another pass — bounded by a 10-pass settle cap that warns (and stops) if an effect never settles. They do not fire on the initial load, only on a real change.
|
|
347
|
+
|
|
284
348
|
## Fetching data
|
|
285
349
|
|
|
286
350
|
`:fetch name from "url"` declares state and fills it from JSON over the network:
|
|
@@ -307,8 +371,7 @@ Cover loading, errors, empty, and data — `@empty` (from the loops above) absor
|
|
|
307
371
|
|
|
308
372
|
:if roster_loading
|
|
309
373
|
Loading…
|
|
310
|
-
:else
|
|
311
|
-
:if roster_error
|
|
374
|
+
:else if roster_error
|
|
312
375
|
Couldn't load the team: { roster_error }
|
|
313
376
|
:else
|
|
314
377
|
@loop roster into member
|
|
@@ -317,7 +380,6 @@ Couldn't load the team: { roster_error }
|
|
|
317
380
|
No team members yet.
|
|
318
381
|
@endloop
|
|
319
382
|
:endif
|
|
320
|
-
:endif
|
|
321
383
|
```
|
|
322
384
|
|
|
323
385
|
### Options
|
|
@@ -328,6 +390,28 @@ No team members yet.
|
|
|
328
390
|
- `retry=<N>` — retry on network failure or a 5xx response before surfacing the error.
|
|
329
391
|
- `headers=<key>` — a `:state`/`:store` key holding an object, sent as request headers.
|
|
330
392
|
- `body=<key>` — a `:state`/`:store` key, JSON-serialized as the request body (for non-`GET`).
|
|
393
|
+
- `refresh=<url>` — a token-refresh endpoint; on a `401`, renew the `headers=` token and retry once (see below).
|
|
394
|
+
|
|
395
|
+
> **URL safety.** A `:fetch`/`refresh` URL must be a relative path, an `http(s)://` URL, or a leading `{ state }` interpolation. A protocol-relative `//host` or a non-http(s) scheme (`file:`, `data:`, `javascript:`, …) is a compile error.
|
|
396
|
+
|
|
397
|
+
### Authenticated requests and token refresh
|
|
398
|
+
|
|
399
|
+
`headers=<key>` sends a state object as request headers — pair it with `:store` to persist a bearer token across reloads:
|
|
400
|
+
|
|
401
|
+
```wd
|
|
402
|
+
:store session = { "Authorization": "Bearer …" }
|
|
403
|
+
:fetch feed from "/api/feed" headers=session
|
|
404
|
+
```
|
|
405
|
+
|
|
406
|
+
Add `refresh="<url>"` and Darkmown manages the token lifecycle: when a request comes back `401`, it POSTs the current `headers` object to the refresh URL, writes the returned headers (the new token) back into the `session` state — persisting it, since `session` is a `:store` — and retries the original request once. Concurrent `401`s sharing a refresh URL are de-duplicated into a single in-flight refresh.
|
|
407
|
+
|
|
408
|
+
```wd
|
|
409
|
+
:store session = { "Authorization": "Bearer …" }
|
|
410
|
+
|
|
411
|
+
:fetch feed from "/api/feed" headers=session refresh="/auth/refresh"
|
|
412
|
+
```
|
|
413
|
+
|
|
414
|
+
`refresh=` requires `headers=` (it needs a state key to renew). The refresh endpoint should accept the current headers as a JSON body and reply with the new headers object.
|
|
331
415
|
|
|
332
416
|
### Dynamic URLs and refetching
|
|
333
417
|
|
|
@@ -431,7 +515,7 @@ Darkmown is a **trusted-author** site generator: you compile content you wrote,
|
|
|
431
515
|
|
|
432
516
|
- **Compile only trusted, author-written content.** Do not compile `.md`/`.wd` files you did not write — user-generated content, third-party docs, form input — without sanitizing it first.
|
|
433
517
|
- **Raw HTML passes through by default.** Darkmown runs `markdown-it` with `html: true`, so raw HTML in your content is emitted verbatim — by design, like every Markdown site generator. There is no built-in sanitizer; a raw `<script>` or event-handler attribute in untrusted content would execute in the visitor's browser. A page can opt into strict mode with `html: false` frontmatter, which drops raw HTML entirely.
|
|
434
|
-
- **`:fetch` has no
|
|
518
|
+
- **`:fetch` has no host allowlist, and reactive pages need `unsafe-eval`.** A `:fetch` (or `refresh=`) URL is taken straight from the page source; the compiler rejects non-http(s) schemes but does not restrict which hosts you call, so SSRF protection is the author's responsibility. Reactive pages also require `script-src 'unsafe-eval'` in your Content-Security-Policy, because the runtime compiles validated `:computed` / `@loop … where` / `.class when` expressions via `new Function` — a strict CSP without `unsafe-eval` will break reactive pages (static pages are unaffected).
|
|
435
519
|
|
|
436
520
|
> **The single biggest footgun:** do not compile untrusted or user-submitted Markdown without sanitizing it first. There is no built-in sanitizer.
|
|
437
521
|
|
package/SECURITY.md
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# Security Policy
|
|
2
|
+
|
|
3
|
+
## Supported versions
|
|
4
|
+
|
|
5
|
+
Darkmown is pre-1.0. Only the latest published minor version receives security fixes.
|
|
6
|
+
|
|
7
|
+
## Reporting a vulnerability
|
|
8
|
+
|
|
9
|
+
Please report vulnerabilities privately via [GitHub Security Advisories](https://github.com/ZVN-DEV/darkmown/security/advisories/new). Do not open public issues for security reports.
|
|
10
|
+
|
|
11
|
+
You can expect an initial response within 72 hours. If the report is accepted, a fix ships as the next patch release and the advisory is published after the fix is available.
|
|
12
|
+
|
|
13
|
+
## Trust boundary / threat model
|
|
14
|
+
|
|
15
|
+
Darkmown is a **trusted-author** static site generator. The threat model assumes you compile content you wrote yourself, the same way you trust your own source code — it does not assume the content is hostile. Within that boundary the guarantees below hold; three assumptions define the boundary itself:
|
|
16
|
+
|
|
17
|
+
1. **Compile only trusted, author-written content.** Do not compile `.md`/`.wd` files you did not write — user-generated content, third-party docs, or form input — without applying your own sanitization first.
|
|
18
|
+
2. **Raw HTML passes through by default.** `markdown-it` runs with `html: true`, so raw HTML in content is emitted verbatim. There is no built-in sanitizer, so a raw `<script>` or event-handler attribute in untrusted content would execute in the visitor's browser. A page can opt into strict mode with `html: false` frontmatter, which strips raw HTML.
|
|
19
|
+
3. **`:fetch` has no host allowlist, and reactive pages require `unsafe-eval`.** A `:fetch` (or `refresh=`) URL is read directly from the page source; the compiler rejects non-http(s) schemes (`file:`, `data:`, `javascript:`, protocol-relative `//host`) but does not restrict which hosts you call, so SSRF protection is the author's responsibility. Reactive pages also need `script-src 'unsafe-eval'` in your Content-Security-Policy, because the runtime compiles validated `:computed` / `@loop … where` / `.class when` expressions through `new Function`; a strict CSP without `unsafe-eval` breaks reactive pages (static pages are unaffected).
|
|
20
|
+
|
|
21
|
+
This is the same trust posture as every Markdown SSG: the framework is safe for the trusted-author use case it targets, and unsafe content is the author's responsibility to sanitize before it reaches the compiler.
|
|
22
|
+
|
|
23
|
+
## Security model
|
|
24
|
+
|
|
25
|
+
Things Darkmown deliberately guards at compile time and runtime:
|
|
26
|
+
|
|
27
|
+
- **No arbitrary JavaScript in content files.** Directive actions (`:button -> …`), `:computed` expressions, and `@loop … where` predicates compile through strict whitelisted grammars — only item paths, declared `:state`, numbers, and strings are allowed. Assignment, function calls, and unknown syntax are compile errors. Raw user content is never `eval`'d; what runs at runtime is the *validated* expression, compiled to the whitelisted grammar and executed via `new Function` (see `src/runtime.js`).
|
|
28
|
+
- **Prototype-walk protection.** Path lookups (`{ a.b.c }`, computed expressions) reject `constructor`, `prototype`, and `__proto__` segments in both the compiler and the runtime.
|
|
29
|
+
- **Include sandboxing.** `@include` and `@loop` data sources must resolve inside `site/pages` or `site/_`; traversal outside the site tree is a compile error, and include cycles are detected.
|
|
30
|
+
- **Output escaping.** Interpolated values are HTML-escaped; state scripts escape `<` to prevent script-tag breakout.
|
|
31
|
+
- **Static server path containment.** The dev/preview servers resolve requests strictly inside `dist`.
|
|
32
|
+
|
|
33
|
+
## The biggest footgun: raw HTML passthrough
|
|
34
|
+
|
|
35
|
+
Darkmown configures markdown-it with `html: true`, so **raw HTML in `.md`/`.wd` files is passed through verbatim** — by design, like every Markdown site generator. This is the single most important thing to understand about Darkmown's security model.
|
|
36
|
+
|
|
37
|
+
- Treat all content files as **trusted input**, the same way you trust your own source code.
|
|
38
|
+
- **Do not compile untrusted or user-submitted Markdown** (comments, form input, third-party docs) without sanitizing it first. Darkmown ships no built-in sanitizer; raw `<script>` and event-handler attributes in untrusted content would execute in the visitor's browser.
|
|
39
|
+
- If you must render untrusted content, sanitize it (for example with a library like DOMPurify) before it reaches the compiler.
|
package/docs/spec-alignment.md
CHANGED
|
@@ -6,7 +6,7 @@ This audit compares the current Darkmown implementation with the original MARROW
|
|
|
6
6
|
|
|
7
7
|
- **Markdown-first authoring:** `.md` is strict CommonMark rendered by a real parser (markdown-it); `.wd` is the same Markdown plus first-party directives. Renaming the file is the upgrade path — extensions genuinely gate functionality.
|
|
8
8
|
- **Content tree over components:** routing, includes, and repeated fragments are file/document based instead of React-style components.
|
|
9
|
-
- **Tiered output:** static routes emit HTML/CSS and no Darkmown runtime; reactive routes opt into `/__wd/runtime.js` (~
|
|
9
|
+
- **Tiered output:** static routes emit HTML/CSS and no Darkmown runtime; reactive routes opt into `/__wd/runtime.js` (~5.7 KB gzipped, CI-enforced below the 6 KB target).
|
|
10
10
|
- **No virtual DOM:** state changes patch direct DOM bindings, conditional regions, and keyed loop regions.
|
|
11
11
|
- **Keyed list patching:** reactive loops reconcile by item key (`id`/`key`/value) instead of re-rendering the region.
|
|
12
12
|
- **Sections with scoped state:** `::: section #id .class` containers scope `:state`; bindings and actions resolve through the nearest scope chain.
|
|
@@ -69,9 +69,20 @@ Three capability gaps from the 2026-06-16 audit, closed together over a shared `
|
|
|
69
69
|
|
|
70
70
|
- **Array frontmatter + readable `meta`:** `parseFrontmatter` now parses inline flow arrays (`tags: [a, b, "x, y"]` → real array; quoted items keep internal commas; a value without a leading `[` stays a scalar — block sequences are intentionally out of scope to keep the parser single-pass). A page's frontmatter is exposed to its body under `meta`, so `{ meta.title }` prints a field, `{ meta.tags }` renders an array joined with `, `, and `@loop meta.tags into tag` iterates a frontmatter array at build time (stays `runtime: false`). Genuine correctness fix on its own, and the groundwork for reading/emitting OKF-style bundles (Google Cloud's Open Knowledge Format — markdown + `type`-bearing frontmatter + cross-links; tracked but deliberately not coupled to its v0.1 Draft).
|
|
71
71
|
|
|
72
|
+
## Stage 9 additions (2026-06-18, v0.13.0)
|
|
73
|
+
|
|
74
|
+
Four progressive-disclosure capabilities plus an assets and a security change. The reactive runtime grew to ~5.7 KB gzipped; the CI budget moved 5 KB → 6 KB (still un-minified).
|
|
75
|
+
|
|
76
|
+
- **`:else if` chains:** `:if … :else if … :else … :endif`, any number of `:else if`, optional trailing bare `:else` (a `:else if` after the bare `:else` is a compile error). Implemented by **desugaring** the chain tail into a nested `:if` inside the falsy branch, which re-enters the existing compile path — so static, reactive, and per-row (loop) conditionals all behave identically with no runtime change. **Honest caveat:** each condition is a bare truthy path, the same grammar `:if` accepts — comparisons (`==`, `<`, …) are not supported in a conditional (use `@loop … where` for those, or a `:computed` boolean).
|
|
77
|
+
- **Reactive classes — `::: … .class when <predicate>`:** a container class toggled by a predicate using the `@loop … where` / `:if` whitelist (item fields, `:state`/`:store`, numbers, strings, `==`/`!=`/`>`/`<`/`>=`/`<=`/`contains`, `and`/`or`, plus a bare truthy path). A fully-static predicate folds to a plain class at build time (`runtime: false` preserved); a predicate over `:state` emits a global `data-wd-class`; a loop-item predicate emits `data-wd-each-class` evaluated per row. The predicate compiles to the same whitelisted grammar over `I()`/`S()`/`C()` and runs via `new Function`.
|
|
78
|
+
- **Authenticated fetch + token refresh — `:fetch … headers= refresh=`:** `headers=<stateKey>` (existing) spreads a state object into request headers. New `refresh="<url>"`: on HTTP 401 the runtime POSTs the current headers to the refresh URL, writes the returned headers object back into the `headers` state (persisting if it is a `:store`), and retries the original request once; concurrent 401s sharing a refresh URL collapse to a single in-flight refresh. **Honest caveat:** this is bearer-token-style renewal only — no OAuth authorization-code flow, no refresh-token rotation beyond what the endpoint returns; `refresh=` requires `headers=`.
|
|
79
|
+
- **Effects — `:effect <watched> -> <actions>`:** run the `:button` action vocabulary (`;`-chained) whenever a watched state path changes. Emits a zero-output `data-wd-effect` marker; the runtime snapshots each watched value and, after a render against settled state, runs the actions on change, re-rendering and re-checking up to a 10-pass settle cap (a non-settling effect warns and stops). **Honest caveat:** effects do not fire on initial load (only on change), and row-scoped actions (`append-row`/`remove`) have no clicked row in an effect, so they no-op.
|
|
80
|
+
- **Page-colocated static assets:** any non-page file under `site/pages/` (anything but `.md`/`.wd` routes and colocated `.skin`/`.js`) is copied to `dist/` at its path (`site/pages/logo.svg` → `dist/logo.svg`). The shelf (`site/_/` → `/__wd/media`, `/__wd/data`) is unchanged; a name clash with an emitted route is skipped with a warning. `.avif` was added to the served content-types.
|
|
81
|
+
- **`:fetch` URL scheme hardening (security):** `:fetch`/`refresh=` URLs are validated at compile time — relative, `http(s)://`, or a leading `{ state }` interpolation are allowed; protocol-relative `//host` and non-http(s) schemes (`file:`, `data:`, `javascript:`, …) are rejected with a corrective hint. **This is scheme validation, not a host allowlist** — SSRF to arbitrary http(s) hosts remains the author's responsibility (see the trust boundary).
|
|
82
|
+
|
|
72
83
|
## Demo-only directives (not part of the public surface)
|
|
73
84
|
|
|
74
|
-
The compiler recognizes three directives — `:note`, `:try`, and `:sprint` — that exist **only to power the demo site** (darkmown.com). They are **not** part of the supported public directive set, are not documented for authors, and may change or be removed without notice. Do not build pages that depend on them. The supported public directives are the ones catalogued above: `:state`, `:store`, `:computed`, `:button`, `:bind`, `:if`/`:else`/`:endif`, `:fetch
|
|
85
|
+
The compiler recognizes three directives — `:note`, `:try`, and `:sprint` — that exist **only to power the demo site** (darkmown.com). They are **not** part of the supported public directive set, are not documented for authors, and may change or be removed without notice. Do not build pages that depend on them. The supported public directives are the ones catalogued above: `:state`, `:store`, `:computed`, `:effect`, `:button`, `:bind`, `:if`/`:else if`/`:else`/`:endif`, `:fetch` (with `headers`/`refresh`), `:form`/`:input`/`:submit`, `@loop`/`@empty`/`@endloop` (with `where`, `sort by`, `reverse`, `offset`, `limit`), `@include`, and `::: section` (with reactive `.class when`).
|
|
75
86
|
|
|
76
87
|
## Still missing from the full vision
|
|
77
88
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zvndev/darkmown",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"types": "./types/index.d.ts",
|
|
14
14
|
"scripts": {
|
|
15
15
|
"build": "node src/cli.js build",
|
|
16
|
-
"runtime:size": "node -e \"const fs=require('fs'),zlib=require('zlib'); const size=zlib.gzipSync(fs.readFileSync('dist/__wd/runtime.js')).length; console.log('shipped runtime gzipped: '+size+' bytes (budget:
|
|
16
|
+
"runtime:size": "node -e \"const fs=require('fs'),zlib=require('zlib'); const size=zlib.gzipSync(fs.readFileSync('dist/__wd/runtime.js')).length; console.log('shipped runtime gzipped: '+size+' bytes (budget: 6144)'); if (size >= 6144) process.exit(1)\"",
|
|
17
17
|
"dev": "node src/cli.js dev",
|
|
18
18
|
"test": "node --test tests/*.test.js",
|
|
19
19
|
"test:cov": "node scripts/test-coverage-gate.mjs 90",
|
|
@@ -34,6 +34,7 @@
|
|
|
34
34
|
"docs/spec-alignment.md",
|
|
35
35
|
"AGENTS.md",
|
|
36
36
|
"README.md",
|
|
37
|
+
"SECURITY.md",
|
|
37
38
|
"LICENSE",
|
|
38
39
|
"CHANGELOG.md"
|
|
39
40
|
],
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
[]
|
package/site/_/og.png
ADDED
|
Binary file
|
package/site/pages/app.wd
CHANGED
|
@@ -19,7 +19,7 @@ This whole section is plain Markdown. The list below is unrolled **at build time
|
|
|
19
19
|
- **{ feature.title }** — { feature.body }
|
|
20
20
|
@endloop
|
|
21
21
|
|
|
22
|
-
<aside class="boundary">If you deleted everything below this line, this page would ship <strong>zero</strong> bytes of JavaScript. Everything above is static HTML. Below is where the one ~
|
|
22
|
+
<aside class="boundary">If you deleted everything below this line, this page would ship <strong>zero</strong> bytes of JavaScript. Everything above is static HTML. Below is where the one ~5.7 KB gzipped runtime loads (CI-enforced under 6 KB) — and only because the document asks for it.</aside>
|
|
23
23
|
|
|
24
24
|
## Fetched data, looped, with nested conditions
|
|
25
25
|
|
package/site/pages/data.wd
CHANGED
|
@@ -33,6 +33,47 @@ Loading the team…
|
|
|
33
33
|
|
|
34
34
|
That loop also proves `:if` over loop items: the lead badge is decided per row.
|
|
35
35
|
|
|
36
|
+
## The four states of a fetch
|
|
37
|
+
|
|
38
|
+
Every `:fetch` tracks the whole lifecycle — `loading`, `error`, `empty`, and data — so a page can answer each one. Here the same primitive shows an **error** (a missing URL 404s) and an **empty** result (a file that is just `[]`):
|
|
39
|
+
|
|
40
|
+
:fetch broken from "/__wd/data/intentionally-missing.json"
|
|
41
|
+
|
|
42
|
+
:if broken_error
|
|
43
|
+
The request failed on purpose — `broken_error` holds: { broken_error }
|
|
44
|
+
:else if broken_loading
|
|
45
|
+
Trying the missing endpoint…
|
|
46
|
+
:else
|
|
47
|
+
Waiting…
|
|
48
|
+
:endif
|
|
49
|
+
|
|
50
|
+
:fetch roster from "/__wd/data/empty.json"
|
|
51
|
+
|
|
52
|
+
@loop roster into person
|
|
53
|
+
- { person.name }
|
|
54
|
+
@empty
|
|
55
|
+
The roster came back empty — `@empty` renders instead of the rows.
|
|
56
|
+
@endloop
|
|
57
|
+
|
|
58
|
+
The error branch uses an `:else if` chain; the empty branch uses the loop's `@empty`. No state machine to wire by hand.
|
|
59
|
+
|
|
60
|
+
## Authenticated requests
|
|
61
|
+
|
|
62
|
+
A real API usually wants a token. `:fetch … headers=<key>` spreads a state object into the request headers, so pair it with `:store` to persist that token across reloads:
|
|
63
|
+
|
|
64
|
+
:store session = { "Authorization": "Bearer demo-token" }
|
|
65
|
+
:fetch feed from "/__wd/data/team.json" headers=session
|
|
66
|
+
|
|
67
|
+
:if feed_error
|
|
68
|
+
The API rejected the token: { feed_error }
|
|
69
|
+
:else if feed
|
|
70
|
+
Authenticated fetch returned { feed.length } row(s). Open the network tab — the `Authorization` header rides along on the request.
|
|
71
|
+
:else
|
|
72
|
+
Loading the authenticated feed…
|
|
73
|
+
:endif
|
|
74
|
+
|
|
75
|
+
This demo points `from=` at a static file (which ignores the header), so it stays self-contained — point it at your real API and the bearer token travels with every request. When that token expires, add `refresh="/auth/refresh"` and Darkmown renews it on a `401` and retries once, automatically.
|
|
76
|
+
|
|
36
77
|
## Forms write state, no backend required
|
|
37
78
|
|
|
38
79
|
`:form into profile` captures the submit straight into state. With `action="/url"` instead, Darkmown emits a plain native form and stays out of the way entirely:
|
package/site/pages/docs/index.wd
CHANGED
|
@@ -170,7 +170,7 @@ tags: [sales, revenue, "q1, q2"]
|
|
|
170
170
|
|
|
171
171
|
## Reactive directives
|
|
172
172
|
|
|
173
|
-
Reactive pages opt into `/__wd/runtime.js` (~
|
|
173
|
+
Reactive pages opt into `/__wd/runtime.js` (~5.7 KB gzipped, under a CI-enforced 6 KB budget). Static pages do not.
|
|
174
174
|
|
|
175
175
|
```wd
|
|
176
176
|
:state count = 0
|
|
@@ -196,6 +196,49 @@ Count is still zero.
|
|
|
196
196
|
|
|
197
197
|
Directive actions are intentionally narrow and compile-time checked. Arbitrary JavaScript belongs in a colocated `.js` file.
|
|
198
198
|
|
|
199
|
+
### Multi-branch conditionals
|
|
200
|
+
|
|
201
|
+
Chain conditionals with `:else if`. Each condition is a bare truthy path (the same form `:if` takes). Use any number of branches; a bare `:else` must come last:
|
|
202
|
+
|
|
203
|
+
```wd
|
|
204
|
+
:if isPro
|
|
205
|
+
Pro plan
|
|
206
|
+
:else if isTrial
|
|
207
|
+
Trial — { daysLeft } days left
|
|
208
|
+
:else
|
|
209
|
+
Free plan
|
|
210
|
+
:endif
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
A whole chain compiles to nested conditional regions, so it folds at build time when the values are static and stays reactive otherwise — exactly like a single `:if`.
|
|
214
|
+
|
|
215
|
+
### Reactive classes — `.class when …`
|
|
216
|
+
|
|
217
|
+
A container class can react to state or the loop item. Static `.class` tokens stay as-is; add `when <predicate>` for a reactive one:
|
|
218
|
+
|
|
219
|
+
```wd
|
|
220
|
+
@loop products into p
|
|
221
|
+
::: card .product .on-sale when p.price < 50
|
|
222
|
+
**{ p.name }** — ${ p.price }
|
|
223
|
+
:::
|
|
224
|
+
@endloop
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
The predicate uses the `@loop … where` / `:if` whitelist (item fields, `:state`, numbers, strings, comparisons, `and`/`or`, `contains`). A static predicate folds to a plain class at build; a state or loop-item predicate stays reactive.
|
|
228
|
+
|
|
229
|
+
### Effects — `:effect`
|
|
230
|
+
|
|
231
|
+
`:effect <watched> -> <actions>` runs actions (the `:button` vocabulary, `;`-chained) whenever the watched state changes — for side effects beyond `:computed` and fetch deps:
|
|
232
|
+
|
|
233
|
+
```wd
|
|
234
|
+
:state q = ""
|
|
235
|
+
:state searches = 0
|
|
236
|
+
|
|
237
|
+
:effect q -> searches++
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
Effects run after a render against settled state, never on the initial load, with a 10-pass settle cap guarding against loops.
|
|
241
|
+
|
|
199
242
|
### Button actions
|
|
200
243
|
|
|
201
244
|
A `:button "Label" -> action` mutates one `:state` or `:store` value. The vocabulary is the same for both:
|
|
@@ -223,8 +266,7 @@ Values are literals — a `"string"`, number, `true`/`false`/`null`, or inline J
|
|
|
223
266
|
|
|
224
267
|
:if team_loading
|
|
225
268
|
Loading…
|
|
226
|
-
:else
|
|
227
|
-
:if team_error
|
|
269
|
+
:else if team_error
|
|
228
270
|
Couldn't load the team: { team_error }
|
|
229
271
|
:else
|
|
230
272
|
@loop team into member
|
|
@@ -233,10 +275,18 @@ Couldn't load the team: { team_error }
|
|
|
233
275
|
No team members yet.
|
|
234
276
|
@endloop
|
|
235
277
|
:endif
|
|
236
|
-
:endif
|
|
237
278
|
```
|
|
238
279
|
|
|
239
|
-
Options after the URL: `method=` (default `GET`), `when=load|visible`, `timeout=<ms>`, `retry=<N>`, `headers=<key>`, and `body=<key>` (the last two name a `:state`/`:store` key). A URL can interpolate state (`"/api/users/{ userId }"`) and re-fetches automatically when that state changes; trigger a reload by hand with `:button "Reload" -> team refetch`. Loop a sub-path of fetched data with a dotted source — `@loop team.members into member`.
|
|
280
|
+
Options after the URL: `method=` (default `GET`), `when=load|visible`, `timeout=<ms>`, `retry=<N>`, `headers=<key>`, and `body=<key>` (the last two name a `:state`/`:store` key). A URL can interpolate state (`"/api/users/{ userId }"`) and re-fetches automatically when that state changes; trigger a reload by hand with `:button "Reload" -> team refetch`. Loop a sub-path of fetched data with a dotted source — `@loop team.members into member`. URLs must be relative, `http(s)://`, or a leading `{ state }` interpolation — other schemes are rejected at compile time.
|
|
281
|
+
|
|
282
|
+
### Authenticated requests
|
|
283
|
+
|
|
284
|
+
`headers=<key>` sends a state object as request headers; pair it with `:store` to persist a bearer token. Add `refresh="<url>"` and a `401` triggers a token refresh: Darkmown POSTs the current headers to the refresh URL, writes the renewed token back into the `headers` state, and retries the request once (concurrent `401`s share one refresh).
|
|
285
|
+
|
|
286
|
+
```wd
|
|
287
|
+
:store session = { "Authorization": "Bearer …" }
|
|
288
|
+
:fetch feed from "/api/feed" headers=session refresh="/auth/refresh"
|
|
289
|
+
```
|
|
240
290
|
|
|
241
291
|
## Global state — `:store`
|
|
242
292
|
|
|
@@ -271,7 +321,7 @@ Darkmown is a trusted-author site generator: you compile content you wrote, the
|
|
|
271
321
|
|
|
272
322
|
- **Compile only content you authored.** Don't run `.md`/`.wd` you didn't write — user-generated content, third-party docs — through the compiler without sanitizing it first.
|
|
273
323
|
- **Raw HTML passes through by default.** Markdown renders with `html: true`, so raw HTML is emitted verbatim and there is no built-in sanitizer. Set `html: false` in a page's frontmatter to drop raw HTML for untrusted content.
|
|
274
|
-
- **`:fetch` has no
|
|
324
|
+
- **`:fetch` has no host allowlist, and reactive pages need `unsafe-eval`.** Fetch URLs come straight from the page source — the compiler rejects non-http(s) schemes but does not restrict which hosts you call, so SSRF is the author's responsibility. The runtime compiles `:computed` / `@loop … where` / `.class when` expressions via `new Function`, so a reactive page needs `script-src 'unsafe-eval'` in your CSP. Static pages need neither.
|
|
275
325
|
|
|
276
326
|
See [SECURITY.md](https://github.com/ZVN-DEV/darkmown/blob/main/SECURITY.md) in the package for the full security model.
|
|
277
327
|
|
|
@@ -283,6 +333,6 @@ See [SECURITY.md](https://github.com/ZVN-DEV/darkmown/blob/main/SECURITY.md) in
|
|
|
283
333
|
|
|
284
334
|
## Spec status
|
|
285
335
|
|
|
286
|
-
The implementation is faithful to the original core thesis: Markdown-first authoring, no component ceremony, zero runtime on static pages, and tiny direct-DOM reactivity only when declared. `:store`, the full `:fetch` lifecycle (loading/error/empty states, dynamic URLs, `refetch`,
|
|
336
|
+
The implementation is faithful to the original core thesis: Markdown-first authoring, no component ceremony, zero runtime on static pages, and tiny direct-DOM reactivity only when declared. `:store`, the full `:fetch` lifecycle (loading/error/empty states, dynamic URLs, `refetch`, dotted loop sources, authenticated `headers=` + `refresh=` token renewal), `:form` (including server round-trips), loop ergonomics (`sort by`/`limit`/`offset`/`reverse`/`@empty` and `$index`/`$number`/`$first`/`$last`/`$count`), `:if … :else if … :else`, reactive `.class when …`, `:effect`, `:computed`, and `persist` are all shipped and live — try them on the [Data & Forms page](/data/) and the [Reactive page](/reactive/). Still on the roadmap: a first-party server runtime (`site/api/`) and HTML-fragment swaps. See `docs/spec-alignment.md` in the package for the full audit.
|
|
287
337
|
|
|
288
338
|
</main>
|
package/site/pages/index.wd
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
title: Darkmown — Markdown that runs, not Markdown that needs React
|
|
3
3
|
description: A live store widget — search filter, add-to-cart, running total — written as one Markdown file that runs. The same outcome in Markdoc needs a React component, hydration, and a build step. Compare them side by side.
|
|
4
|
+
image: https://darkmown.com/__wd/media/og.png
|
|
4
5
|
---
|
|
5
6
|
|
|
6
7
|
@include /nav.wd
|
|
@@ -96,14 +97,14 @@ Markdoc.renderers.react(content, React, {
|
|
|
96
97
|
|
|
97
98
|
</section>
|
|
98
99
|
|
|
99
|
-
:note "Static pages ship zero JavaScript. The moment a page asks for reactivity — like this very homepage — one ~
|
|
100
|
+
:note "Static pages ship zero JavaScript. The moment a page asks for reactivity — like this very homepage — one ~5.7 KB gzipped runtime loads (CI-enforced under 6 KB), never before. JS optional, CSS optional, always."
|
|
100
101
|
|
|
101
102
|
<section class="props">
|
|
102
103
|
|
|
103
104
|
## Three rules, no escape hatch
|
|
104
105
|
|
|
105
106
|
- **Zero-JS static.** A page with no state ships no framework JavaScript. `/markdown/` and `/docs/` prove it — open them and check the network tab.
|
|
106
|
-
- **One runtime.** Every reactive page shares the same ~
|
|
107
|
+
- **One runtime.** Every reactive page shares the same ~5.7 KB gzipped runtime, CI-enforced under 6 KB. No per-component bundles, no hydration tax that scales with your UI.
|
|
107
108
|
- **One loop, one binding.** `@loop … into …` is the only loop; `{ name }` is the only interpolation. Nothing else to learn, nothing else to misuse.
|
|
108
109
|
|
|
109
110
|
</section>
|
package/site/pages/reactive.wd
CHANGED
|
@@ -39,30 +39,34 @@ The same `@loop` that unrolls static data also drives reactive lists. Items are
|
|
|
39
39
|
|
|
40
40
|
:button "Add todo" -> todos += {"id": 3, "title": "Live compile", "owner": "Testing"}
|
|
41
41
|
|
|
42
|
-
##
|
|
42
|
+
## Multi-branch conditionals + reactive classes
|
|
43
43
|
|
|
44
|
-
`:if`
|
|
44
|
+
`:if … :else if … :else … :endif` picks one of several branches per row, and a container class can react to the row too: `.class when <predicate>` toggles a class from the same whitelist `@loop … where` uses. Each card below picks one of three badges *and* tags itself `.is-done` / `.is-blocked`, all reactive:
|
|
45
|
+
|
|
46
|
+
<style>
|
|
47
|
+
.task-row { border-left: 4px solid #9991; padding-left: .6rem; }
|
|
48
|
+
.task-row.is-done { border-left-color: #2e9e5b; }
|
|
49
|
+
.task-row.is-blocked { border-left-color: #d2453f; }
|
|
50
|
+
</style>
|
|
45
51
|
|
|
46
52
|
:state tasks = [{"id": 1, "title": "Draft the spec", "done": true, "blocked": false}, {"id": 2, "title": "Wire the runtime", "done": false, "blocked": true}, {"id": 3, "title": "Write the demo", "done": false, "blocked": false}]
|
|
47
53
|
|
|
48
54
|
@loop tasks into task
|
|
49
|
-
::: card .task-row
|
|
55
|
+
::: card .task-row .is-done when task.done .is-blocked when task.blocked
|
|
50
56
|
**{ task.title }** —
|
|
51
57
|
:if task.done
|
|
52
58
|
done ✓
|
|
53
|
-
:else
|
|
54
|
-
:if task.blocked
|
|
59
|
+
:else if task.blocked
|
|
55
60
|
blocked ✗
|
|
56
61
|
:else
|
|
57
62
|
in progress …
|
|
58
63
|
:endif
|
|
59
|
-
:endif
|
|
60
64
|
:::
|
|
61
65
|
@endloop
|
|
62
66
|
|
|
63
67
|
:button "Add a finished task" -> tasks += {"id": 4, "title": "Ship it", "done": true, "blocked": false}
|
|
64
68
|
|
|
65
|
-
Each row picks one of three states from
|
|
69
|
+
Each row picks one of three states from a single `:else if` chain, and its left border color comes from a reactive `.class when …` — plain Markdown, no component, no ternary, no JavaScript.
|
|
66
70
|
|
|
67
71
|
## Live filtering — search in pure Markdown
|
|
68
72
|
|
|
@@ -83,6 +87,15 @@ Each row picks one of three states from two nested conditionals, all in plain Ma
|
|
|
83
87
|
|
|
84
88
|
The predicate whitelist is compile-time validated — item fields, declared state, numbers, and strings only. An item-only predicate (say `where p.price < 50`) would instead filter at build time and ship zero JavaScript.
|
|
85
89
|
|
|
90
|
+
### …and an effect that watches the search
|
|
91
|
+
|
|
92
|
+
`:effect <state> -> <actions>` runs actions whenever the watched state changes — for side effects past deriving state. This one counts how many times the search box above has changed:
|
|
93
|
+
|
|
94
|
+
:state searches = 0
|
|
95
|
+
:effect q -> searches++
|
|
96
|
+
|
|
97
|
+
The search has changed **{ searches }** time(s). Type in the box above and this updates on its own — no handler wired by hand.
|
|
98
|
+
|
|
86
99
|
### …and an editable cart
|
|
87
100
|
|
|
88
101
|
A `:button` inside a loop can act on its own row. **Add to cart** carries the row into another list; **Remove** drops a line — a whole add/remove flow with no JavaScript:
|