remark-skeudo 0.0.0-stage → 0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 The Skeudo authors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,90 @@
1
- # Temporary Holding Version
1
+ # remark-skeudo
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ > Experimental, 0.x: the format and this API can change in any minor version. [CHANGELOG.md](https://github.com/wlezzar/skeudo/blob/main/CHANGELOG.md) lists the changes.
4
+
5
+ A [remark](https://github.com/remarkjs/remark) plugin that renders [Skeudo](https://github.com/wlezzar/skeudo) sketches in Markdown and MDX. A sketch is pseudocode for code review where every outside effect is tagged, or, when it starts with a `data` line, a data model drawn as tables and a story of how their rows change. The format is defined in [spec/spec.md](https://github.com/wlezzar/skeudo/blob/main/spec/spec.md).
6
+
7
+ - Every ` ```skeudo ` fence becomes a sketch (` ```sketch ` works too).
8
+ - Inline code made only of tags, such as `` `::read:postgres.users` ``, becomes pills.
9
+
10
+ The plugin builds the sketch as an HTML syntax tree (hast), not as an HTML string. MDX and the site generators built on remark use it as they would any other element, and plain unified pipelines need no `allowDangerousHtml` or rehype-raw.
11
+
12
+ ```sh
13
+ npm install remark-skeudo
14
+ ```
15
+
16
+ ## Use
17
+
18
+ With unified:
19
+
20
+ ```js
21
+ import rehypeStringify from 'rehype-stringify';
22
+ import remarkParse from 'remark-parse';
23
+ import remarkRehype from 'remark-rehype';
24
+ import remarkSkeudo from 'remark-skeudo';
25
+ import { unified } from 'unified';
26
+
27
+ const file = await unified()
28
+ .use(remarkParse)
29
+ .use(remarkSkeudo)
30
+ .use(remarkRehype)
31
+ .use(rehypeStringify)
32
+ .process(markdown);
33
+ ```
34
+
35
+ With MDX:
36
+
37
+ ```js
38
+ import { compile } from '@mdx-js/mdx';
39
+ import remarkSkeudo from 'remark-skeudo';
40
+
41
+ const js = await compile(mdx, { remarkPlugins: [remarkSkeudo] });
42
+ ```
43
+
44
+ Site generators built on remark take it in their list of remark plugins, such as `markdown.remarkPlugins` in Astro. To pass options, give the plugin and its options as a pair: `[remarkSkeudo, { inlineTags: false }]`.
45
+
46
+ The page needs the stylesheet, `@skeudo/html/skeudo.css`, and `enhance()` from `@skeudo/html`, called once in the browser for hovering names, explanations in a popover and stepping through data sketches. [`@skeudo/html`](https://www.npmjs.com/package/@skeudo/html) is installed with the plugin, and its README says what each one does.
47
+
48
+ ### Docusaurus
49
+
50
+ Add the plugin to the docs preset, and a client module, in `docusaurus.config.mjs`:
51
+
52
+ ```js
53
+ import remarkSkeudo from 'remark-skeudo';
54
+
55
+ export default {
56
+ // ...
57
+ presets: [['classic', { docs: { remarkPlugins: [remarkSkeudo] } }]],
58
+ clientModules: ['./src/skeudo.js'],
59
+ };
60
+ ```
61
+
62
+ The client module, `src/skeudo.js`, loads the stylesheet and calls `enhance()`:
63
+
64
+ ```js
65
+ import { enhance } from '@skeudo/html';
66
+ import '@skeudo/html/skeudo.css';
67
+
68
+ if (typeof document !== 'undefined') enhance(document);
69
+ ```
70
+
71
+ Sketches follow the site's light and dark mode. Checked with Docusaurus 3.10, in `.md` and `.mdx` pages.
72
+
73
+ ## Options
74
+
75
+ | Option | Default | |
76
+ | --- | --- | --- |
77
+ | `langs` | `['skeudo', 'sketch']` | Fence languages rendered as sketches. |
78
+ | `inlineTags` | `true` | Render inline code made only of tags as pills. |
79
+ | `srcHref` | links to `::repo` | Builds a link for a `::src` location, from `{ path, start, end }` and the parsed sketch. `srcBaseHref(base)` from `@skeudo/html` builds one for a base URL, such as `https://github.com/org/repo/blob/a1b2c3d/`. Without it, a sketch that names its repository with `::repo` links to the file there, on GitHub, GitLab or Bitbucket, and other locations are tooltips. |
80
+ | `gitHosts` | `{}` | Other GitHub, GitLab or Bitbucket servers, such as `{ 'git.example.com': 'gitlab' }`, so `::repo` links reach them too. |
81
+ | `kindColors` | `{}` | CSS colors for tag kinds, such as `{ todo: '#8b5cf6' }`. |
82
+ | `labelKinds` | `['untrusted', 'secret']` | Tag kinds whose value labels a variable. Every later use of a labeled variable is marked. |
83
+
84
+ ## Warnings
85
+
86
+ The parser's warnings, listed under Warnings in the spec, are reported as messages on the file, at their line in the document, with the source `remark-skeudo` and the rule `parse`. remark-cli prints them, and `file.messages` holds them in code.
87
+
88
+ ## In the syntax tree
89
+
90
+ Each sketch fence is replaced by a `skeudo` node that keeps the fence's `lang`, `meta` and source `value`, and carries the rendered element (`div.sketch`, or `div.skd` for a data sketch) in `data` for remark-rehype. TypeScript users get the node type from the plugin, as `Skeudo`. remark-stringify can't write a `skeudo` node back to Markdown, so use the plugin when the output is HTML or MDX.
@@ -0,0 +1,53 @@
1
+ import type { ElementContent, Properties } from 'hast';
2
+ import type { Data, Literal, Root } from 'mdast';
3
+ import { FENCE_LANGS } from '@skeudo/core';
4
+ import { type HtmlOptions } from '@skeudo/html';
5
+ export { FENCE_LANGS };
6
+ export interface Options extends HtmlOptions {
7
+ /** Fence languages rendered as sketches. Defaults to FENCE_LANGS. */
8
+ langs?: readonly string[];
9
+ /** Render inline code made only of tags, such as `::read:postgres`, as pills. Defaults to true. */
10
+ inlineTags?: boolean;
11
+ }
12
+ /**
13
+ * A rendered sketch, which replaces its ```skeudo fence in the tree. It keeps the fence's source as
14
+ * `value`, and carries the rendered `div.sketch` in `data`, which remark-rehype turns into that element.
15
+ */
16
+ export interface Skeudo extends Literal {
17
+ type: 'skeudo';
18
+ /** The fence language, such as `skeudo`. */
19
+ lang: string;
20
+ /** The rest of the fence's info string. */
21
+ meta?: string | null;
22
+ data: SkeudoData;
23
+ }
24
+ export interface SkeudoData extends Data {
25
+ hName: 'div';
26
+ hProperties: Properties;
27
+ hChildren: ElementContent[];
28
+ }
29
+ declare module 'mdast' {
30
+ interface BlockContentMap {
31
+ skeudo: Skeudo;
32
+ }
33
+ interface RootContentMap {
34
+ skeudo: Skeudo;
35
+ }
36
+ }
37
+ /** The part of a vfile the plugin uses: parser warnings become messages on the file. */
38
+ interface MessageSink {
39
+ message(reason: string, options?: {
40
+ place?: {
41
+ line: number;
42
+ column: number;
43
+ };
44
+ source?: string;
45
+ ruleId?: string;
46
+ }): unknown;
47
+ }
48
+ /**
49
+ * remark plugin: renders ```skeudo fences (and ```sketch) as sketches, and inline code made only of
50
+ * tags as pills. The output is a hast tree, so it works with remark-rehype, MDX, and the site
51
+ * generators built on them, with no raw HTML. Parser warnings are reported as messages on the file.
52
+ */
53
+ export default function remarkSkeudo(options?: Options): (tree: Root, file?: MessageSink) => undefined;
package/dist/index.js ADDED
@@ -0,0 +1,56 @@
1
+ import { FENCE_LANGS, parse, parseTagsOnly } from '@skeudo/core';
2
+ import { tagHast, toHast } from '@skeudo/html';
3
+ export { FENCE_LANGS };
4
+ /**
5
+ * remark plugin: renders ```skeudo fences (and ```sketch) as sketches, and inline code made only of
6
+ * tags as pills. The output is a hast tree, so it works with remark-rehype, MDX, and the site
7
+ * generators built on them, with no raw HTML. Parser warnings are reported as messages on the file.
8
+ */
9
+ export default function remarkSkeudo(options = {}) {
10
+ const langs = new Set(options.langs ?? FENCE_LANGS);
11
+ const inlineTags = options.inlineTags !== false;
12
+ function sketch(code, file) {
13
+ const parsed = parse(code.value, options);
14
+ const start = code.position?.start;
15
+ for (const d of parsed.diagnostics) {
16
+ // The sketch's first line is the one after the opening fence.
17
+ const place = start && { line: start.line + d.line, column: start.column };
18
+ file?.message(d.message, { place, source: 'remark-skeudo', ruleId: 'parse' });
19
+ }
20
+ const { properties, children } = toHast(parsed, options);
21
+ return {
22
+ type: 'skeudo',
23
+ lang: code.lang,
24
+ meta: code.meta,
25
+ value: code.value,
26
+ position: code.position,
27
+ data: { hName: 'div', hProperties: properties, hChildren: children },
28
+ };
29
+ }
30
+ function tags(code) {
31
+ const parsed = parseTagsOnly(code.value);
32
+ if (!parsed)
33
+ return;
34
+ const children = parsed.flatMap((tag, i) => [
35
+ ...(i ? [{ type: 'text', value: ' ' }] : []),
36
+ tagHast(tag, options),
37
+ ]);
38
+ // remark-rehype applies these to the element it makes for inline code. It becomes a span, since site
39
+ // generators such as Docusaurus render every `code` element through their code block component.
40
+ const data = code.data;
41
+ code.data = Object.assign({}, data, { hName: 'span', hProperties: { ...data?.hProperties, className: ['sk-inline'] }, hChildren: children });
42
+ }
43
+ function visit(parent, file) {
44
+ parent.children.forEach((node, i) => {
45
+ if (node.type === 'code' && node.lang && langs.has(node.lang))
46
+ parent.children[i] = sketch(node, file);
47
+ else if (node.type === 'inlineCode' && inlineTags)
48
+ tags(node);
49
+ else if ('children' in node)
50
+ visit(node, file);
51
+ });
52
+ }
53
+ return (tree, file) => {
54
+ visit(tree, file);
55
+ };
56
+ }
package/package.json CHANGED
@@ -1,6 +1,62 @@
1
1
  {
2
2
  "name": "remark-skeudo",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.0",
4
+ "description": "A remark plugin that renders Skeudo sketches in Markdown and MDX: pseudocode with every outside effect tagged, and data models drawn as tables with a story of how their rows change.",
5
+ "keywords": [
6
+ "skeudo",
7
+ "remark-plugin",
8
+ "remark",
9
+ "unified",
10
+ "mdx",
11
+ "markdown",
12
+ "pseudocode",
13
+ "code-review",
14
+ "data-model"
15
+ ],
16
+ "license": "MIT",
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "git+https://github.com/wlezzar/skeudo.git",
20
+ "directory": "packages/remark"
21
+ },
22
+ "bugs": "https://github.com/wlezzar/skeudo/issues",
23
+ "type": "module",
24
+ "sideEffects": false,
25
+ "exports": {
26
+ ".": {
27
+ "types": "./dist/index.d.ts",
28
+ "default": "./dist/index.js"
29
+ }
30
+ },
31
+ "publishConfig": {
32
+ "access": "public"
33
+ },
34
+ "files": [
35
+ "dist/**/*.js",
36
+ "dist/**/*.d.ts"
37
+ ],
38
+ "engines": {
39
+ "node": ">=22"
40
+ },
41
+ "dependencies": {
42
+ "@types/hast": "^3.0.5",
43
+ "@types/mdast": "^4.0.4",
44
+ "@skeudo/core": "0.1.0",
45
+ "@skeudo/html": "0.1.0"
46
+ },
47
+ "devDependencies": {
48
+ "@mdx-js/mdx": "^3.1.1",
49
+ "@types/react": "^19.3.0",
50
+ "@types/react-dom": "^19.3.0",
51
+ "react": "^19.3.1",
52
+ "react-dom": "^19.3.1",
53
+ "rehype-stringify": "^10.0.1",
54
+ "remark-parse": "^11.0.0",
55
+ "remark-rehype": "^11.1.2",
56
+ "unified": "^11.0.5"
57
+ },
58
+ "scripts": {
59
+ "build": "node ../../scripts/build-library.mts"
60
+ },
61
+ "types": "./dist/index.d.ts"
6
62
  }