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 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, and top-level `await` are supported.
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 = [['cleye', '^2.3.0'], ['md-pen', '^0.0.2']];
85
- const depsTable = table(deps.map(([name, v]) => [
86
- link(`https://npm.im/${name}`, bold(name)), v
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 h=Object.defineProperty;var a=(r,o)=>h(r,"name",{value:o,configurable:!0});import{register as g}from"node:module";import u from"node:fs/promises";import w from"node:path";import{cli as E}from"cleye";import{pathToFileURL as y}from"node:url";import{p as M,b as $,E as R,M as b,C,a as S}from"./parse-markdown-ChGEvmW3.mjs";import"md4x";const k=a(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"?JSON.stringify(r):String(r)},"coerceValue"),v=a(async(r,o)=>{const{markers:e}=M(r);if(e.length===0)return r;const n=await import(y(o).href),f=$(e),m=new Map,d=a((t,l)=>{const i=m.get(t);if(i!==void 0)return i;const s=k(n[`${R}${t}`]);if(s.includes(b)||s.includes(`${C}
3
- `)||s.includes(S))throw new Error(`Expression "${l}" produced a value containing mdeval comment syntax, which would corrupt the document on re-parse`);return m.set(t,s),s},"resolveValue"),c=[];let p=0;for(const t of e){const l=f.get(t.expression),i=d(l,t.expression);c.push(r.slice(p,t.contentStart),i),p=t.contentEnd}return c.push(r.slice(p)),c.join("")},"processSource");g("#md-loader",import.meta.url),globalThis.block=r=>`
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
- `;const x=E({name:"mdeval",parameters:["<files...>"]});await Promise.all(x._.files.map(async r=>{try{const o=w.resolve(r),e=await u.readFile(o,"utf8"),n=await v(e,o);n!==e&&(await u.writeFile(o,n,"utf8"),console.log(`Updated: ${r}`))}catch(o){console.error(`Error processing ${r}:`,o instanceof Error?o.message:o),process.exitCode=1}}));
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.0.0",
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
  }