mdeval 1.1.0 → 1.2.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/README.md +3 -1
- package/dist/cli.mjs +3 -3
- package/package.json +2 -1
- package/skills/mdeval/SKILL.md +31 -1
package/README.md
CHANGED
|
@@ -40,7 +40,9 @@ The `1.0.0` between `-->` and `<!--/mdeval-->` is the current value — it gets
|
|
|
40
40
|
mdeval README.md
|
|
41
41
|
```
|
|
42
42
|
|
|
43
|
-
The file is updated in-place. You can pass multiple files
|
|
43
|
+
The file is updated in-place. You can pass multiple files or glob patterns: `mdeval README.md "docs/**/*.md"`.
|
|
44
|
+
|
|
45
|
+
`node_modules` and hidden directories are automatically excluded from glob expansion.
|
|
44
46
|
|
|
45
47
|
## Notes
|
|
46
48
|
|
package/dist/cli.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
var
|
|
3
|
-
`)||
|
|
2
|
+
var g=Object.defineProperty;var l=(r,o)=>g(r,"name",{value:o,configurable:!0});import m from"node:fs/promises";import h from"node:path";import{cli as w}from"cleye";import{glob as E}from"tinyglobby";import{$ as y}from"zx";import{register as $}from"node:module";import{pathToFileURL as b}from"node:url";import{p as x,b as M,E as S,M as P,C as R,a as _}from"./parse-markdown-ChGEvmW3.mjs";import"md4x";const T=l(r=>{if(r==null)throw new Error(`Cannot interpolate ${r} \u2014 this is likely a bug in your script`);return typeof r=="string"?r:typeof r=="object"?Symbol.toPrimitive in r?String(r):JSON.stringify(r):String(r)},"coerceValue");$("#md-loader",import.meta.url);const k=l(async(r,o)=>{const{markers:t}=x(r);if(t.length===0)return r;const s=await import(b(o).href),p=M(t),u=await Promise.all(Array.from(p).map(async([e,c])=>{const n=T(await s[`${S}${c}`]);if(n.includes(P)||n.includes(`${R}
|
|
3
|
+
`)||n.includes(_))throw new Error(`Expression "${e}" produced a value containing mdeval comment syntax, which would corrupt the document on re-parse`);return n})),i=[];let a=0;for(const e of t){const c=p.get(e.expression);i.push(r.slice(a,e.contentStart),u[c]),a=e.contentEnd}return i.push(r.slice(a)),i.join("")},"processSource");globalThis.block=r=>`
|
|
4
4
|
${String(r)}
|
|
5
|
-
`,globalThis.$=
|
|
5
|
+
`,globalThis.$=y;const C=w({name:"mdeval",parameters:["<files...>"]}),d=C._.files,N=d.some(r=>r.includes("node_modules")),f=await E(d,{ignore:N?[]:["**/node_modules/**"]});f.length===0&&(console.error("No files matched the given patterns"),process.exit(1)),await Promise.all(f.map(async r=>{try{const o=h.resolve(r),t=await m.readFile(o,"utf8"),s=await k(t,o);s!==t&&(await m.writeFile(o,s,"utf8"),console.log(`Updated: ${r}`))}catch(o){console.error(`Error processing ${r}:`,o instanceof Error?o.message:o),process.exitCode=1}}));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mdeval",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "Evaluate JavaScript in markdown HTML comments and interpolate results in-place",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"markdown",
|
|
@@ -30,6 +30,7 @@
|
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"cleye": "^2.3.0",
|
|
32
32
|
"md4x": "^0.0.25",
|
|
33
|
+
"tinyglobby": "^0.2.15",
|
|
33
34
|
"zx": "8.8.5-lite"
|
|
34
35
|
}
|
|
35
36
|
}
|
package/skills/mdeval/SKILL.md
CHANGED
|
@@ -14,7 +14,7 @@ Two types of HTML comments — invisible when rendered:
|
|
|
14
14
|
| Script block | `<!--mdeval\n...\n-->` | Define variables, imports, logic. Starts with `<!--mdeval` + newline |
|
|
15
15
|
| Value marker | `<!--mdeval EXPR-->value<!--/mdeval-->` | Interpolate expression result. Starts with `<!--mdeval ` + space |
|
|
16
16
|
|
|
17
|
-
Script blocks run as ESM with full Node.js access and top-level `await`. All blocks in a file merge into one module — imports and variables are shared across blocks and markers. `import.meta` points to the markdown file.
|
|
17
|
+
Script blocks run as ESM with full Node.js access and top-level `await`. All blocks in a file merge into one module — imports and variables are shared across blocks and markers. `import.meta` points to the markdown file. Marker expressions are auto-awaited, so promises resolve automatically.
|
|
18
18
|
|
|
19
19
|
## Marker Expressions
|
|
20
20
|
|
|
@@ -36,10 +36,38 @@ Duplicate expressions across markers are evaluated once and reused.
|
|
|
36
36
|
| `string` | As-is |
|
|
37
37
|
| `number`, `boolean`, `bigint` | `String(value)` |
|
|
38
38
|
| `object`, `array` | `JSON.stringify(value)` |
|
|
39
|
+
| object with `Symbol.toPrimitive` | `String(value)` (e.g. zx `ProcessOutput`) |
|
|
40
|
+
| `Promise` | Auto-awaited, then coerced |
|
|
39
41
|
| `undefined`, `null` | Error |
|
|
40
42
|
|
|
43
|
+
## Globals
|
|
44
|
+
|
|
45
|
+
| Global | Description |
|
|
46
|
+
|--------|-------------|
|
|
47
|
+
| `block(value)` | Wraps value with newlines for block-level rendering |
|
|
48
|
+
| `$` | [zx](https://google.github.io/zx/) shell — run commands via tagged templates: `` $`git branch` `` |
|
|
49
|
+
|
|
50
|
+
## CLI
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
mdeval README.md # single file
|
|
54
|
+
mdeval README.md docs/guide.md # multiple files
|
|
55
|
+
mdeval "docs/**/*.md" # glob pattern
|
|
56
|
+
mdeval "**/*.md" # recursive — node_modules and dotdirs auto-excluded
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Supports full glob syntax including `**` recursive, `{a,b}` brace expansion, and `!` negation.
|
|
60
|
+
|
|
61
|
+
`node_modules` and hidden directories (`.git`, `.next`, etc.) are automatically excluded from glob expansion. No need to manually negate them. To explicitly include `node_modules`, reference it in the pattern: `mdeval "node_modules/pkg/*.md"`.
|
|
62
|
+
|
|
41
63
|
## Patterns
|
|
42
64
|
|
|
65
|
+
### Shell commands
|
|
66
|
+
|
|
67
|
+
````markdown
|
|
68
|
+
<!--mdeval $`git branch --show-current`-->main<!--/mdeval-->
|
|
69
|
+
````
|
|
70
|
+
|
|
43
71
|
### Read package.json
|
|
44
72
|
|
|
45
73
|
````markdown
|
|
@@ -116,3 +144,5 @@ const x = String.fromCharCode(45, 45, 62);
|
|
|
116
144
|
**Use IIFEs to co-locate logic.** In large docs, keep marker-specific computation inline instead of in a distant script block: `<!--mdeval (() => { ... })()-->`.
|
|
117
145
|
|
|
118
146
|
**Markers in code blocks are safe.** Fenced, indented, and inline code won't be touched — safe to document mdeval syntax in your own README.
|
|
147
|
+
|
|
148
|
+
**Never create a .md file with only a script block and no real content.** Markdown files must contain actual prose/documentation. For shared logic or utilities, create a `.js` or `.ts` file and import it from your markdown instead.
|