mdeval 1.0.0 → 1.1.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 +20 -4
- package/dist/cli.mjs +3 -3
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -26,7 +26,7 @@ const pkg = JSON.parse(await fs.readFile('package.json', 'utf8'));
|
|
|
26
26
|
-->
|
|
27
27
|
```
|
|
28
28
|
|
|
29
|
-
Full Node.js, ESM imports,
|
|
29
|
+
Full Node.js, ESM imports, top-level `await`, and shell commands via [`$`](https://google.github.io/zx/) are supported.
|
|
30
30
|
|
|
31
31
|
A **value marker** is where the result appears. It starts with `<!--mdeval ` (with a space) followed by a JavaScript expression:
|
|
32
32
|
|
|
@@ -54,6 +54,14 @@ The file is updated in-place. You can pass multiple files at once: `mdeval READM
|
|
|
54
54
|
|
|
55
55
|
In large documents, this IIFE pattern lets you keep logic next to the marker it serves instead of in a distant script block.
|
|
56
56
|
|
|
57
|
+
- Marker expressions are **auto-awaited** — promises resolve automatically, so you can use `fetch()` or any async API directly in a marker without wrapping it in a script block.
|
|
58
|
+
|
|
59
|
+
- **`$`** from [zx](https://google.github.io/zx/) is available as a global — run shell commands directly in markers:
|
|
60
|
+
|
|
61
|
+
```markdown
|
|
62
|
+
<!--mdeval $`git branch --show-current`-->main<!--/mdeval-->
|
|
63
|
+
```
|
|
64
|
+
|
|
57
65
|
- If your value starts with a heading, list, or other block element, wrap it with **`block()`** so it renders on its own line. `block()` is a global helper that adds newlines before and after the value.
|
|
58
66
|
|
|
59
67
|
- You can **import from other `.md` files**. Only the script blocks are executed — no markers are processed:
|
|
@@ -81,9 +89,13 @@ The file is updated in-place. You can pass multiple files at once: `mdeval READM
|
|
|
81
89
|
```markdown
|
|
82
90
|
<!--mdeval
|
|
83
91
|
import { table, bold, link } from 'md-pen';
|
|
84
|
-
const deps = [
|
|
85
|
-
|
|
86
|
-
|
|
92
|
+
const deps = [
|
|
93
|
+
['cleye', '^2.3.0'],
|
|
94
|
+
['md-pen', '^0.0.2'],
|
|
95
|
+
];
|
|
96
|
+
const depsTable = table(deps.map(([name, version]) => [
|
|
97
|
+
link(`https://npm.im/${name}`, bold(name)),
|
|
98
|
+
version,
|
|
87
99
|
]));
|
|
88
100
|
-->
|
|
89
101
|
|
|
@@ -98,3 +110,7 @@ const depsTable = table(deps.map(([name, v]) => [
|
|
|
98
110
|
## Agent Skills
|
|
99
111
|
|
|
100
112
|
This package ships with a built-in [agent skill](./skills/mdeval/SKILL.md) for AI coding assistants. Set up [`skills-npm`](https://github.com/antfu/skills-npm) to automatically discover it.
|
|
113
|
+
|
|
114
|
+
## Related
|
|
115
|
+
|
|
116
|
+
- [comment-mark](https://github.com/privatenumber/comment-mark) — Same idea of using HTML comment placeholders, but you write the script externally and pass values in via a JavaScript API. Useful when you want to keep the logic separate from the Markdown.
|
package/dist/cli.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
var
|
|
3
|
-
`)||
|
|
2
|
+
var d=Object.defineProperty;var p=(r,o)=>d(r,"name",{value:o,configurable:!0});import{register as u}from"node:module";import l from"node:fs/promises";import g from"node:path";import{cli as h}from"cleye";import{$ as w}from"zx";import{pathToFileURL as E}from"node:url";import{p as y,b as $,E as b,M as x,C as M,a as S}from"./parse-markdown-ChGEvmW3.mjs";import"md4x";const P=p(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"),R=p(async(r,o)=>{const{markers:t}=y(r);if(t.length===0)return r;const s=await import(E(o).href),m=$(t),f=await Promise.all(Array.from(m).map(async([e,c])=>{const i=P(await s[`${b}${c}`]);if(i.includes(x)||i.includes(`${M}
|
|
3
|
+
`)||i.includes(S))throw new Error(`Expression "${e}" produced a value containing mdeval comment syntax, which would corrupt the document on re-parse`);return i})),n=[];let a=0;for(const e of t){const c=m.get(e.expression);n.push(r.slice(a,e.contentStart),f[c]),a=e.contentEnd}return n.push(r.slice(a)),n.join("")},"processSource");u("#md-loader",import.meta.url),globalThis.block=r=>`
|
|
4
4
|
${String(r)}
|
|
5
|
-
|
|
5
|
+
`,globalThis.$=w;const T=h({name:"mdeval",parameters:["<files...>"]});await Promise.all(T._.files.map(async r=>{try{const o=g.resolve(r),t=await l.readFile(o,"utf8"),s=await R(t,o);s!==t&&(await l.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.1.0",
|
|
4
4
|
"description": "Evaluate JavaScript in markdown HTML comments and interpolate results in-place",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"markdown",
|
|
@@ -29,6 +29,7 @@
|
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"cleye": "^2.3.0",
|
|
32
|
-
"md4x": "^0.0.25"
|
|
32
|
+
"md4x": "^0.0.25",
|
|
33
|
+
"zx": "8.8.5-lite"
|
|
33
34
|
}
|
|
34
35
|
}
|