markdown-it-skeudo 0.0.0-stage → 0.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/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,79 @@
1
- # Temporary Holding Version
1
+ # markdown-it-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
+ > **Alpha.** The format and this API will change in ways that break existing sketches and code. Until 1.0, breaking changes come in minor versions (0.1 to 0.2), never in patches, and the [release notes](https://github.com/wlezzar/skeudo/releases) list each one.
4
+
5
+ A [markdown-it](https://github.com/markdown-it/markdown-it) plugin that renders [Skeudo](https://github.com/wlezzar/skeudo) sketches. A sketch is pseudocode for code review where every outside effect is tagged, or a data model drawn as tables and a story of how their rows change, and its first line says which: `view: code` or `view: data`. 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
+ ```sh
11
+ npm install markdown-it-skeudo
12
+ ```
13
+
14
+ ## Use
15
+
16
+ ```js
17
+ import MarkdownIt from 'markdown-it';
18
+ import markdownItSkeudo from 'markdown-it-skeudo';
19
+
20
+ const md = new MarkdownIt().use(markdownItSkeudo);
21
+ const html = md.render(markdown);
22
+ ```
23
+
24
+ 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, folding blocks 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.
25
+
26
+ ### VitePress
27
+
28
+ Add the plugin in `.vitepress/config.mts`:
29
+
30
+ ```js
31
+ import { defineConfig } from 'vitepress';
32
+ import markdownItSkeudo from 'markdown-it-skeudo';
33
+
34
+ export default defineConfig({
35
+ markdown: {
36
+ config: (md) => {
37
+ md.use(markdownItSkeudo);
38
+ },
39
+ },
40
+ });
41
+ ```
42
+
43
+ Load the stylesheet and `enhance()` in `.vitepress/theme/index.ts`:
44
+
45
+ ```js
46
+ import DefaultTheme from 'vitepress/theme';
47
+ import { enhance } from '@skeudo/html';
48
+ import '@skeudo/html/skeudo.css';
49
+
50
+ export default {
51
+ extends: DefaultTheme,
52
+ enhanceApp() {
53
+ if (typeof document !== 'undefined') enhance(document);
54
+ },
55
+ };
56
+ ```
57
+
58
+ Checked with VitePress 1.6.
59
+
60
+ ## Options
61
+
62
+ | Option | Default | |
63
+ | --- | --- | --- |
64
+ | `langs` | `['skeudo', 'sketch']` | Fence languages rendered as sketches. |
65
+ | `inlineTags` | `true` | Render inline code made only of tags as pills. |
66
+ | `srcHref` | links to `::repo` | Builds a link for a `::src` location, from `{ path, start, end }`, the parsed sketch, and the `env` given to `md.render`. `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. |
67
+ | `gitHosts` | `{}` | Other GitHub, GitLab or Bitbucket servers, such as `{ 'git.example.com': 'gitlab' }`, so `::repo` links reach them too. |
68
+ | `kindColors` | `{}` | CSS colors for tag kinds, such as `{ todo: '#8b5cf6' }`. |
69
+ | `labelKinds` | `['untrusted', 'secret']` | Tag kinds whose value labels a variable. Every later use of a labeled variable is marked. |
70
+
71
+ ## Other exports
72
+
73
+ - `FENCE_LANGS`: the default fence languages.
74
+ - `sketchFences(md, source)`: the sketch fences in a Markdown document, each with its content and the line it starts on, for tools that check sketches.
75
+ - `frontMatter(source)`: splits simple `key: value` front matter from a document.
76
+
77
+ ## License
78
+
79
+ MIT
@@ -0,0 +1,32 @@
1
+ import type { MarkdownIt } from 'markdown-it';
2
+ import { FENCE_LANGS, type CodeSketch, type ResolvedSrc } from '@skeudo/core';
3
+ import { type HtmlOptions, type SrcLink } from '@skeudo/html';
4
+ export { FENCE_LANGS };
5
+ export interface SkeudoPluginOptions extends Omit<HtmlOptions, 'srcHref'> {
6
+ /**
7
+ * Builds a link for a source location, as in HtmlOptions. It also gets the env given to markdown-it's
8
+ * render, such as the `currentDocument` VS Code's preview passes.
9
+ */
10
+ srcHref?: (loc: ResolvedSrc, sketch: CodeSketch, env: Record<string, unknown>) => string | SrcLink | undefined;
11
+ /** Fence languages rendered as sketches. Defaults to FENCE_LANGS. */
12
+ langs?: string[];
13
+ /** Render inline code made only of tags, such as `::read:postgres`, as pills. Defaults to true. */
14
+ inlineTags?: boolean;
15
+ }
16
+ /** markdown-it plugin: renders ```skeudo fences (and ```sketch) with the Skeudo renderer. */
17
+ export default function markdownItSkeudo(md: MarkdownIt, options?: SkeudoPluginOptions): void;
18
+ export interface FrontMatter {
19
+ /** `key: value` pairs, as plain strings. */
20
+ data: Record<string, string>;
21
+ /** The document after the front matter. */
22
+ body: string;
23
+ /** Lines the front matter takes, to map a line of `body` back to the document. */
24
+ lines: number;
25
+ }
26
+ /** Splits simple front matter, `key: value` lines between `---` lines, from a Markdown document. */
27
+ export declare function frontMatter(source: string): FrontMatter;
28
+ /** Extracts the source of every sketch fence in a Markdown document. */
29
+ export declare function sketchFences(md: MarkdownIt, source: string, langs?: readonly string[]): {
30
+ content: string;
31
+ line: number;
32
+ }[];
package/dist/index.js ADDED
@@ -0,0 +1,49 @@
1
+ import { FENCE_LANGS, parseTagsOnly } from '@skeudo/core';
2
+ import { tagHtml, toHtml } from '@skeudo/html';
3
+ export { FENCE_LANGS };
4
+ /** markdown-it plugin: renders ```skeudo fences (and ```sketch) with the Skeudo renderer. */
5
+ export default function markdownItSkeudo(md, options = {}) {
6
+ const langs = new Set(options.langs ?? FENCE_LANGS);
7
+ const fence = md.renderer.rules.fence;
8
+ md.renderer.rules.fence = (tokens, idx, opts, env, self) => {
9
+ const token = tokens[idx];
10
+ const lang = token.info.trim().split(/\s+/)[0];
11
+ if (!langs.has(lang))
12
+ return fence(tokens, idx, opts, env, self);
13
+ const { srcHref } = options;
14
+ const html = toHtml(token.content, { ...options, srcHref: srcHref && ((loc, sketch) => srcHref(loc, sketch, env ?? {})) });
15
+ // Keep attributes other plugins put on the fence, such as the source line an editor's preview scrolls to.
16
+ return (token.attrs?.length ? `<div${self.renderAttrs(token)}>${html}</div>` : html) + '\n';
17
+ };
18
+ if (options.inlineTags !== false) {
19
+ const inline = md.renderer.rules.code_inline;
20
+ md.renderer.rules.code_inline = (tokens, idx, opts, env, self) => {
21
+ const tags = parseTagsOnly(tokens[idx].content);
22
+ if (!tags)
23
+ return inline(tokens, idx, opts, env, self);
24
+ // Pills have no source links.
25
+ const { srcHref: _srcHref, ...pillOptions } = options;
26
+ return `<span class="sk-inline">${tags.map((t) => tagHtml(t, pillOptions)).join(' ')}</span>`;
27
+ };
28
+ }
29
+ }
30
+ /** Splits simple front matter, `key: value` lines between `---` lines, from a Markdown document. */
31
+ export function frontMatter(source) {
32
+ const match = /^---\r?\n([\s\S]*?)\r?\n---[ \t]*(?:\r?\n|$)/.exec(source);
33
+ if (!match)
34
+ return { data: {}, body: source, lines: 0 };
35
+ const data = {};
36
+ for (const line of match[1].split(/\r?\n/)) {
37
+ const kv = /^(\w+):\s*(.*)$/.exec(line.trim());
38
+ if (kv)
39
+ data[kv[1]] = kv[2].replace(/^(["'])(.*)\1$/, '$2');
40
+ }
41
+ return { data, body: source.slice(match[0].length), lines: match[0].split('\n').length - 1 };
42
+ }
43
+ /** Extracts the source of every sketch fence in a Markdown document. */
44
+ export function sketchFences(md, source, langs = FENCE_LANGS) {
45
+ return md
46
+ .parse(source, {})
47
+ .filter((t) => t.type === 'fence' && langs.includes(t.info.trim().split(/\s+/)[0]))
48
+ .map((t) => ({ content: t.content, line: (t.map?.[0] ?? 0) + 1 }));
49
+ }
package/package.json CHANGED
@@ -1,6 +1,53 @@
1
1
  {
2
2
  "name": "markdown-it-skeudo",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.2.0",
4
+ "description": "A markdown-it plugin that renders Skeudo sketches: 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
+ "markdown-it-plugin",
8
+ "markdown-it",
9
+ "markdown",
10
+ "pseudocode",
11
+ "code-review",
12
+ "data-model"
13
+ ],
14
+ "license": "MIT",
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "git+https://github.com/wlezzar/skeudo.git",
18
+ "directory": "packages/markdown-it"
19
+ },
20
+ "bugs": "https://github.com/wlezzar/skeudo/issues",
21
+ "type": "module",
22
+ "sideEffects": false,
23
+ "exports": {
24
+ ".": {
25
+ "types": "./dist/index.d.ts",
26
+ "default": "./dist/index.js"
27
+ }
28
+ },
29
+ "publishConfig": {
30
+ "access": "public"
31
+ },
32
+ "files": [
33
+ "dist/**/*.js",
34
+ "dist/**/*.d.ts"
35
+ ],
36
+ "engines": {
37
+ "node": ">=22"
38
+ },
39
+ "dependencies": {
40
+ "@skeudo/core": "0.2.0",
41
+ "@skeudo/html": "0.2.0"
42
+ },
43
+ "peerDependencies": {
44
+ "markdown-it": ">=14"
45
+ },
46
+ "devDependencies": {
47
+ "markdown-it": "^15.0.3"
48
+ },
49
+ "scripts": {
50
+ "build": "node ../../scripts/build-library.mts"
51
+ },
52
+ "types": "./dist/index.d.ts"
6
53
  }