@vchernoy/remark-active 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 +21 -0
- package/README.md +33 -2
- package/dist/index.d.ts +27 -0
- package/dist/index.js +48 -0
- package/dist/index.js.map +1 -0
- package/dist/plugin.d.ts +30 -0
- package/dist/plugin.js +257 -0
- package/dist/plugin.js.map +1 -0
- package/dist/rehype.d.ts +24 -0
- package/dist/rehype.js +65 -0
- package/dist/rehype.js.map +1 -0
- package/dist/sanitize.d.ts +6 -0
- package/dist/sanitize.js +26 -0
- package/dist/sanitize.js.map +1 -0
- package/dist/tex.d.ts +17 -0
- package/dist/tex.js +31 -0
- package/dist/tex.js.map +1 -0
- package/package.json +69 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 vchernoy
|
|
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,34 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @vchernoy/remark-active
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The Markdown side of [active-md](../../README.md): a remark plugin and a ready-made, sanitized pipeline.
|
|
4
|
+
|
|
5
|
+
```ts
|
|
6
|
+
import { renderActive } from '@vchernoy/remark-active';
|
|
7
|
+
|
|
8
|
+
const { html, messages } = renderActive(markdown, { locale: 'en-US' });
|
|
9
|
+
// html: sanitized HTML, complete with default values (no JavaScript needed to read it)
|
|
10
|
+
// messages: [{ message, line, column, severity }] for the author
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## What it handles
|
|
14
|
+
|
|
15
|
+
- ` ```calc ` blocks: collected in document order into one program (`@vchernoy/calc`), hidden from readers (`showCalc: true` shows them as code).
|
|
16
|
+
- `:input[name]` is a number box. Add `{widget=slider}` for a slider, with `min`, `max` and `step` (they may only narrow the input's range) and `label="…"`. An input may have several controls (say a number box and a slider): they stay in sync and must use the same range.
|
|
17
|
+
- `:value[expr]{format=fixed:2|percent:1|int}`: a read-only view of a value or expression.
|
|
18
|
+
- `{{expr}}` inside `$…$` and `$$…$$` inserts the value; formulas are typeset by KaTeX as MathML (`output: 'htmlAndMathml'` if the page loads KaTeX's CSS). `$$…$$` written inside a line is display math.
|
|
19
|
+
- GFM, plus callouts `:::note|tip|warning|danger|important|exercise` (optional `[Title]`) and `:::details[Summary]`.
|
|
20
|
+
- Unknown directives (`Note:this`, `:span[x]`) are put back as the text they came from.
|
|
21
|
+
|
|
22
|
+
Errors appear inline (`⚠ message`) and as `messages` with document line and column.
|
|
23
|
+
|
|
24
|
+
## Safety
|
|
25
|
+
|
|
26
|
+
Raw HTML in the Markdown is dropped. Output goes through `rehype-sanitize` (GitHub's schema plus the elements and `data-active-*` attributes this plugin emits) before KaTeX runs with `trust: false`. Calc has no access to anything but numbers.
|
|
27
|
+
|
|
28
|
+
## Output for the runtime
|
|
29
|
+
|
|
30
|
+
The document is wrapped in `<div class="active-doc" data-active-calc="[…calc sources…]">`. Controls carry `data-active-input`, views `data-active-value` (and `data-active-format`), and math `data-active-tex` with the `{{…}}` template. `@vchernoy/active-runtime` reads these to make the page live.
|
|
31
|
+
|
|
32
|
+
## Using the plugin in your own pipeline
|
|
33
|
+
|
|
34
|
+
`remarkActive(options)` goes after `remark-directive` and `remark-math`; add `rehypeActiveWrap` after `remark-rehype`, then your sanitizer (extend `activeSchema`), then `rehypeActiveKatex`. See `createProcessor` in `src/index.ts`.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { Program } from '@vchernoy/calc';
|
|
2
|
+
import { type ActiveOptions } from './plugin.js';
|
|
3
|
+
import { type ImageOptions, type KatexOptions } from './rehype.js';
|
|
4
|
+
export { remarkActive, type ActiveData, type ActiveOptions, type CalcBlock } from './plugin.js';
|
|
5
|
+
export { rehypeActiveKatex, rehypeActiveWrap, renderTex, type KatexOptions } from './rehype.js';
|
|
6
|
+
export { activeSchema } from './sanitize.js';
|
|
7
|
+
export { placeholders, substitute, texNumber, katexSettings, PLACEHOLDER, type MathOutput } from './tex.js';
|
|
8
|
+
export type RenderOptions = ActiveOptions & KatexOptions & ImageOptions;
|
|
9
|
+
export type RenderMessage = {
|
|
10
|
+
message: string;
|
|
11
|
+
line?: number;
|
|
12
|
+
column?: number;
|
|
13
|
+
severity: 'error' | 'warning';
|
|
14
|
+
};
|
|
15
|
+
export type RenderResult = {
|
|
16
|
+
/** Sanitized HTML, complete with default values; pass its root element to the runtime to make it live. */
|
|
17
|
+
html: string;
|
|
18
|
+
program: Program | undefined;
|
|
19
|
+
messages: RenderMessage[];
|
|
20
|
+
};
|
|
21
|
+
/** The full untrusted-safe pipeline: Markdown (GFM, directives, math, calc) to sanitized HTML. */
|
|
22
|
+
export declare function createProcessor(options?: RenderOptions): import("unified").Processor<import("mdast").Root, import("mdast").Root, import("hast").Root, import("hast").Root, string>;
|
|
23
|
+
/**
|
|
24
|
+
* Render a document. Raw HTML in the Markdown is dropped, images become links (unless `images: 'load'`),
|
|
25
|
+
* and output is sanitized before math is typeset.
|
|
26
|
+
*/
|
|
27
|
+
export declare function renderActive(markdown: string, options?: RenderOptions): RenderResult;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import rehypeSanitize from 'rehype-sanitize';
|
|
2
|
+
import rehypeStringify from 'rehype-stringify';
|
|
3
|
+
import remarkDirective from 'remark-directive';
|
|
4
|
+
import remarkGfm from 'remark-gfm';
|
|
5
|
+
import remarkMath from 'remark-math';
|
|
6
|
+
import remarkParse from 'remark-parse';
|
|
7
|
+
import remarkRehype from 'remark-rehype';
|
|
8
|
+
import { unified } from 'unified';
|
|
9
|
+
import { remarkActive } from './plugin.js';
|
|
10
|
+
import { rehypeActiveImages, rehypeActiveKatex, rehypeActiveWrap } from './rehype.js';
|
|
11
|
+
import { activeSchema } from './sanitize.js';
|
|
12
|
+
export { remarkActive } from './plugin.js';
|
|
13
|
+
export { rehypeActiveKatex, rehypeActiveWrap, renderTex } from './rehype.js';
|
|
14
|
+
export { activeSchema } from './sanitize.js';
|
|
15
|
+
export { placeholders, substitute, texNumber, katexSettings, PLACEHOLDER } from './tex.js';
|
|
16
|
+
/** The full untrusted-safe pipeline: Markdown (GFM, directives, math, calc) to sanitized HTML. */
|
|
17
|
+
export function createProcessor(options = {}) {
|
|
18
|
+
return unified()
|
|
19
|
+
.use(remarkParse)
|
|
20
|
+
.use(remarkGfm)
|
|
21
|
+
.use(remarkDirective)
|
|
22
|
+
.use(remarkMath)
|
|
23
|
+
.use(remarkActive, options)
|
|
24
|
+
.use(remarkRehype)
|
|
25
|
+
.use(rehypeActiveWrap)
|
|
26
|
+
.use(rehypeActiveImages, options)
|
|
27
|
+
.use(rehypeSanitize, activeSchema)
|
|
28
|
+
.use(rehypeActiveKatex, options)
|
|
29
|
+
.use(rehypeStringify, { allowDangerousHtml: true });
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Render a document. Raw HTML in the Markdown is dropped, images become links (unless `images: 'load'`),
|
|
33
|
+
* and output is sanitized before math is typeset.
|
|
34
|
+
*/
|
|
35
|
+
export function renderActive(markdown, options = {}) {
|
|
36
|
+
const file = createProcessor(options).processSync(markdown);
|
|
37
|
+
return {
|
|
38
|
+
html: String(file),
|
|
39
|
+
program: file.data.active?.program,
|
|
40
|
+
messages: file.messages.map(m => ({
|
|
41
|
+
message: m.reason,
|
|
42
|
+
...(m.line != null ? { line: m.line } : {}),
|
|
43
|
+
...(m.column != null ? { column: m.column } : {}),
|
|
44
|
+
severity: m.ruleId === 'warning' ? 'warning' : 'error',
|
|
45
|
+
})),
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,cAAc,MAAM,iBAAiB,CAAC;AAC7C,OAAO,eAAe,MAAM,kBAAkB,CAAC;AAC/C,OAAO,eAAe,MAAM,kBAAkB,CAAC;AAC/C,OAAO,SAAS,MAAM,YAAY,CAAC;AACnC,OAAO,UAAU,MAAM,aAAa,CAAC;AACrC,OAAO,WAAW,MAAM,cAAc,CAAC;AACvC,OAAO,YAAY,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,YAAY,EAAsB,MAAM,aAAa,CAAC;AAC/D,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,gBAAgB,EAAwC,MAAM,aAAa,CAAC;AAC5H,OAAO,EAAE,YAAY,EAAE,MAAM,eA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AAI,IAAI,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YAC3C,GAAG,CAAC,CAAC,CAAC,MAAM,IAAI,IAAI,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YACjD,QAAQ,EAAE,CAAC,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,OAAO;SACvD,CAAC,CAAC;KACJ,CAAC;AACJ,CAAC"}
|
package/dist/plugin.d.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { type Limits, type Program } from '@vchernoy/calc';
|
|
2
|
+
import type { Root } from 'mdast';
|
|
3
|
+
import type { VFile } from 'vfile';
|
|
4
|
+
export type ActiveOptions = {
|
|
5
|
+
/** Locale for formatting values (default: the runtime's). */
|
|
6
|
+
locale?: string;
|
|
7
|
+
/** Keep calc blocks in the output as code (an author's view). Default false: readers don't see them. */
|
|
8
|
+
showCalc?: boolean;
|
|
9
|
+
limits?: Limits;
|
|
10
|
+
};
|
|
11
|
+
export type CalcBlock = {
|
|
12
|
+
id: string;
|
|
13
|
+
text: string;
|
|
14
|
+
};
|
|
15
|
+
/** What the plugin leaves on `file.data.active`. */
|
|
16
|
+
export type ActiveData = {
|
|
17
|
+
blocks: CalcBlock[];
|
|
18
|
+
program: Program;
|
|
19
|
+
};
|
|
20
|
+
declare module 'vfile' {
|
|
21
|
+
interface DataMap {
|
|
22
|
+
active: ActiveData;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* remark plugin: collects ```calc blocks into one program, turns :input/:value directives into
|
|
27
|
+
* controls and views showing default values, marks {{…}} in math, and adds callouts and :::details.
|
|
28
|
+
* Use after remark-directive and remark-math. Diagnostics are vfile messages with document positions.
|
|
29
|
+
*/
|
|
30
|
+
export declare function remarkActive(options?: ActiveOptions): (tree: Root, file: VFile) => void;
|
package/dist/plugin.js
ADDED
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
import { createSession, formatNumber, parse, parseFormat } from '@vchernoy/calc';
|
|
2
|
+
import { toString } from 'mdast-util-to-string';
|
|
3
|
+
import { placeholders, substitute } from './tex.js';
|
|
4
|
+
const CALLOUTS = {
|
|
5
|
+
note: 'Note', tip: 'Tip', warning: 'Warning', danger: 'Danger', important: 'Important', exercise: 'Exercise',
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* remark plugin: collects ```calc blocks into one program, turns :input/:value directives into
|
|
9
|
+
* controls and views showing default values, marks {{…}} in math, and adds callouts and :::details.
|
|
10
|
+
* Use after remark-directive and remark-math. Diagnostics are vfile messages with document positions.
|
|
11
|
+
*/
|
|
12
|
+
export function remarkActive(options = {}) {
|
|
13
|
+
return (tree, file) => {
|
|
14
|
+
const blocks = [];
|
|
15
|
+
const blockStart = new Map();
|
|
16
|
+
/** Per block, the number of source characters (indentation, "> ") Markdown removed before each line. */
|
|
17
|
+
const blockIndent = new Map();
|
|
18
|
+
const sourceLines = String(file.value).split(/\r?\n/);
|
|
19
|
+
walk(tree, (node, parent, index) => {
|
|
20
|
+
if (node.type !== 'code' || node.lang !== 'calc')
|
|
21
|
+
return;
|
|
22
|
+
const id = `calc-${blocks.length + 1}`;
|
|
23
|
+
blocks.push({ id, text: node.value });
|
|
24
|
+
// The block's text starts on the line after the opening fence.
|
|
25
|
+
const first = (node.position?.start.line ?? 1) + 1;
|
|
26
|
+
blockStart.set(id, first);
|
|
27
|
+
blockIndent.set(id, node.value.split('\n').map((text, i) => {
|
|
28
|
+
const line = sourceLines[first - 1 + i] ?? '';
|
|
29
|
+
return text && line.endsWith(text) ? line.length - text.length : 0;
|
|
30
|
+
}));
|
|
31
|
+
// Shown as an ordinary `language-calc` code block.
|
|
32
|
+
if (options.showCalc)
|
|
33
|
+
return;
|
|
34
|
+
parent.children.splice(index, 1);
|
|
35
|
+
return index;
|
|
36
|
+
});
|
|
37
|
+
const program = parse(blocks, options.limits);
|
|
38
|
+
const session = createSession(program, options.limits);
|
|
39
|
+
file.data.active = { blocks, program };
|
|
40
|
+
const report = (d, place) => {
|
|
41
|
+
const m = file.message(d.message, place ? { place } : undefined);
|
|
42
|
+
m.source = 'active-md';
|
|
43
|
+
m.ruleId = d.severity;
|
|
44
|
+
};
|
|
45
|
+
for (const d of program.diagnostics) {
|
|
46
|
+
const start = blockStart.get(d.span.block);
|
|
47
|
+
const indent = blockIndent.get(d.span.block)?.[d.span.line - 1] ?? 0;
|
|
48
|
+
report(d, start === undefined ? undefined : { line: start + d.span.line - 1, column: d.span.column + indent });
|
|
49
|
+
}
|
|
50
|
+
/** The range of the first control of each input; later controls of the same input must match it. */
|
|
51
|
+
const controlled = new Map();
|
|
52
|
+
walk(tree, (node, parent, index) => {
|
|
53
|
+
if (node.type === 'textDirective' || node.type === 'leafDirective' || node.type === 'containerDirective') {
|
|
54
|
+
return directive(node, parent, index);
|
|
55
|
+
}
|
|
56
|
+
if (node.type === 'math' || node.type === 'inlineMath')
|
|
57
|
+
math(node);
|
|
58
|
+
return undefined;
|
|
59
|
+
});
|
|
60
|
+
function at(node) {
|
|
61
|
+
return node.position ? { line: node.position.start.line, column: node.position.start.column } : undefined;
|
|
62
|
+
}
|
|
63
|
+
function showError(node, message) {
|
|
64
|
+
report({ message, severity: 'error' }, at(node));
|
|
65
|
+
node.data = { hName: 'span', hProperties: { className: ['active-error'], role: 'note' }, hChildren: [{ type: 'text', value: `⚠ ${message}` }] };
|
|
66
|
+
}
|
|
67
|
+
function directive(node, parent, index) {
|
|
68
|
+
const attrs = node.attributes ?? {};
|
|
69
|
+
if (node.type === 'textDirective' && node.name === 'input') {
|
|
70
|
+
input(node, attrs);
|
|
71
|
+
return undefined;
|
|
72
|
+
}
|
|
73
|
+
if (node.type === 'textDirective' && node.name === 'value') {
|
|
74
|
+
value(node, attrs);
|
|
75
|
+
return undefined;
|
|
76
|
+
}
|
|
77
|
+
if (node.type === 'containerDirective' && (Object.hasOwn(CALLOUTS, node.name) || node.name === 'details')) {
|
|
78
|
+
container(node);
|
|
79
|
+
return undefined;
|
|
80
|
+
}
|
|
81
|
+
// Anything else (":30" in "10:30" is not a directive, but "Note:this" is) goes back to its source text.
|
|
82
|
+
const source = sourceOf(node, file);
|
|
83
|
+
const text = { type: 'text', value: source };
|
|
84
|
+
const replacement = node.type === 'textDirective' ? text : { type: 'paragraph', children: [{ type: 'text', value: source }] };
|
|
85
|
+
parent.children.splice(index, 1, replacement);
|
|
86
|
+
return index + 1;
|
|
87
|
+
}
|
|
88
|
+
function input(node, attrs) {
|
|
89
|
+
const name = labelSource(node, file).trim();
|
|
90
|
+
const def = program.inputs.find(i => i.name === name);
|
|
91
|
+
const fail = (message) => showError(node, message);
|
|
92
|
+
if (!def)
|
|
93
|
+
return fail(program.names.has(name) ? `"${name}" is not an input, so it can't have a control` : `unknown input "${name}"`);
|
|
94
|
+
const widget = attrs.widget ?? 'number';
|
|
95
|
+
if (widget !== 'number' && widget !== 'slider')
|
|
96
|
+
return fail(`unknown widget "${widget}" (use number or slider)`);
|
|
97
|
+
const num = (key) => {
|
|
98
|
+
const raw = attrs[key];
|
|
99
|
+
if (raw === undefined || raw === null || raw === '')
|
|
100
|
+
return undefined;
|
|
101
|
+
const n = Number(raw);
|
|
102
|
+
return Number.isFinite(n) ? n : `${key}="${raw}" is not a number`;
|
|
103
|
+
};
|
|
104
|
+
const min = num('min'), max = num('max'), step = num('step');
|
|
105
|
+
for (const v of [min, max, step])
|
|
106
|
+
if (typeof v === 'string')
|
|
107
|
+
return fail(v);
|
|
108
|
+
const lo = min ?? def.range?.min;
|
|
109
|
+
const hi = max ?? def.range?.max;
|
|
110
|
+
if (def.range && ((lo !== undefined && lo < def.range.min) || (hi !== undefined && hi > def.range.max)))
|
|
111
|
+
return fail(`min/max can only narrow ${name}'s range ${def.range.min}..${def.range.max}`);
|
|
112
|
+
if (widget === 'slider' && (lo === undefined || hi === undefined))
|
|
113
|
+
return fail(`a slider needs a range: give ${name} "in a..b" or min and max`);
|
|
114
|
+
if (lo !== undefined && hi !== undefined && lo > hi)
|
|
115
|
+
return fail(`min ${lo} is greater than max ${hi}`);
|
|
116
|
+
if (step !== undefined && step <= 0)
|
|
117
|
+
return fail('step must be positive');
|
|
118
|
+
// Several controls may edit one input (a number box and a slider); they stay in sync, so they must agree on the range.
|
|
119
|
+
const first = controlled.get(name);
|
|
120
|
+
if (first && (first.lo !== lo || first.hi !== hi)) {
|
|
121
|
+
const range = (a, b) => `${a ?? '…'}..${b ?? '…'}`;
|
|
122
|
+
return fail(`every control of ${name} must use the same range: ${range(first.lo, first.hi)}${first.line ? ` (line ${first.line})` : ''}, not ${range(lo, hi)}`);
|
|
123
|
+
}
|
|
124
|
+
const current = session.get(name);
|
|
125
|
+
const shown = current?.kind === 'value' ? current.value : def.default;
|
|
126
|
+
// The browser would silently clamp a value outside the control, and the page would disagree with the model.
|
|
127
|
+
if ((lo !== undefined && shown < lo) || (hi !== undefined && shown > hi))
|
|
128
|
+
return fail(`${name} starts at ${shown}, outside this control's range ${lo ?? '…'}..${hi ?? '…'}`);
|
|
129
|
+
// A control whose step can't land on the starting value would snap it, and the page would disagree
|
|
130
|
+
// with the model. An explicit step must fit; an inferred slider step falls back to "any".
|
|
131
|
+
// HTML measures steps from min, or from the value attribute when there is no min.
|
|
132
|
+
const base = lo ?? shown;
|
|
133
|
+
if (step !== undefined && !onStep(shown, base, step))
|
|
134
|
+
return fail(`${name} starts at ${shown}, which step ${step} from ${base} can't reach`);
|
|
135
|
+
const inferred = widget === 'slider' ? sliderStep(lo, hi) : undefined;
|
|
136
|
+
const controlStep = step ?? (inferred !== undefined && onStep(shown, base, inferred) ? inferred : 'any');
|
|
137
|
+
const label = attrs.label ?? undefined;
|
|
138
|
+
const props = {
|
|
139
|
+
type: widget === 'slider' ? 'range' : 'number', value: String(shown), dataActiveInput: name,
|
|
140
|
+
...(lo !== undefined ? { min: lo } : {}), ...(hi !== undefined ? { max: hi } : {}),
|
|
141
|
+
step: controlStep,
|
|
142
|
+
...(label ? {} : { ariaLabel: name }),
|
|
143
|
+
};
|
|
144
|
+
const children = [];
|
|
145
|
+
if (label)
|
|
146
|
+
children.push({ type: 'element', tagName: 'span', properties: { className: ['active-input-label'] }, children: [{ type: 'text', value: label }] });
|
|
147
|
+
children.push({ type: 'element', tagName: 'input', properties: props, children: [] });
|
|
148
|
+
if (widget === 'slider') {
|
|
149
|
+
children.push({ type: 'element', tagName: 'output', properties: { className: ['active-value'], dataActiveValue: name, ariaLive: 'polite' }, children: [{ type: 'text', value: formatNumber(shown, undefined, options.locale) }] });
|
|
150
|
+
}
|
|
151
|
+
if (!first)
|
|
152
|
+
controlled.set(name, { lo, hi, line: node.position?.start.line });
|
|
153
|
+
node.data = { hName: 'label', hProperties: { className: ['active-input', `active-input-${widget}`] }, hChildren: children };
|
|
154
|
+
}
|
|
155
|
+
function value(node, attrs) {
|
|
156
|
+
const expr = labelSource(node, file).trim();
|
|
157
|
+
const format = parseFormat(attrs.format ?? undefined);
|
|
158
|
+
const compiled = session.compile(expr, 'value');
|
|
159
|
+
const problem = typeof format === 'string' ? format : compiled.diagnostics[0]?.message;
|
|
160
|
+
if (problem)
|
|
161
|
+
return showError(node, problem);
|
|
162
|
+
const result = compiled.evaluate();
|
|
163
|
+
node.data = {
|
|
164
|
+
hName: 'output',
|
|
165
|
+
hProperties: { className: ['active-value', ...(result.kind === 'error' ? ['active-error'] : [])], dataActiveValue: expr, ...(attrs.format ? { dataActiveFormat: attrs.format } : {}), ariaLive: 'polite' },
|
|
166
|
+
hChildren: [{ type: 'text', value: show(result, format) }],
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
function show(result, format) {
|
|
170
|
+
return result.kind === 'value' ? formatNumber(result.value, format, options.locale) : `⚠ ${result.message}`;
|
|
171
|
+
}
|
|
172
|
+
function container(node) {
|
|
173
|
+
const first = node.children[0];
|
|
174
|
+
let title;
|
|
175
|
+
if (first?.type === 'paragraph' && first.data && first.data.directiveLabel) {
|
|
176
|
+
title = toString(first);
|
|
177
|
+
node.children.shift();
|
|
178
|
+
}
|
|
179
|
+
if (node.name === 'details') {
|
|
180
|
+
node.children.unshift({ type: 'paragraph', data: { hName: 'summary' }, children: [{ type: 'text', value: title ?? 'Details' }] });
|
|
181
|
+
node.data = { hName: 'details' };
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
node.children.unshift({ type: 'paragraph', data: { hProperties: { className: ['callout-title'] } }, children: [{ type: 'text', value: title ?? CALLOUTS[node.name] }] });
|
|
185
|
+
node.data = { hName: 'aside', hProperties: { className: ['callout', `callout-${node.name}`], role: 'note' } };
|
|
186
|
+
}
|
|
187
|
+
function math(node) {
|
|
188
|
+
// `$$…$$` written inside a line is inline math to remark-math, but authors mean display math.
|
|
189
|
+
const start = node.position?.start.offset;
|
|
190
|
+
const display = node.type === 'math' || (start !== undefined && String(file.value).startsWith('$$', start));
|
|
191
|
+
const exprs = placeholders(node.value);
|
|
192
|
+
const results = exprs.map(e => {
|
|
193
|
+
const c = session.compile(e, 'math');
|
|
194
|
+
const r = c.evaluate();
|
|
195
|
+
// The formula only shows a red "?", so the author needs the reason: a compile or an evaluation error.
|
|
196
|
+
const problem = c.diagnostics[0]?.message ?? (r.kind === 'error' ? r.message : undefined);
|
|
197
|
+
if (problem)
|
|
198
|
+
report({ message: `in {{${e}}}: ${problem}`, severity: 'error' }, at(node));
|
|
199
|
+
return r;
|
|
200
|
+
});
|
|
201
|
+
node.data = {
|
|
202
|
+
hName: node.type === 'math' ? 'div' : 'span',
|
|
203
|
+
hProperties: { className: ['active-math', display ? 'active-math-display' : 'active-math-inline'], dataActiveTex: node.value, ...(display ? { dataActiveDisplay: 'true' } : {}) },
|
|
204
|
+
hChildren: [{ type: 'text', value: substitute(node.value, results) }],
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
/** Whether value = base + k·step for a whole k (within floating-point noise). */
|
|
210
|
+
function onStep(value, base, step) {
|
|
211
|
+
const k = (value - base) / step;
|
|
212
|
+
return Math.abs(k - Math.round(k)) < 1e-9;
|
|
213
|
+
}
|
|
214
|
+
/** A slider step that gives about 100 positions, rounded to 1, 2 or 5 × 10^k. */
|
|
215
|
+
function sliderStep(min, max) {
|
|
216
|
+
const raw = (max - min) / 100;
|
|
217
|
+
if (!(raw > 0))
|
|
218
|
+
return 1;
|
|
219
|
+
const p = 10 ** Math.floor(Math.log10(raw));
|
|
220
|
+
const m = raw / p;
|
|
221
|
+
return Number(((m <= 1 ? 1 : m <= 2 ? 2 : m <= 5 ? 5 : 10) * p).toPrecision(12));
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* The directive label exactly as written. The label is parsed as Markdown, so `:value[2*3*4]` has an
|
|
225
|
+
* emphasis child; flattening it to text would drop the operators. Use the source between the children.
|
|
226
|
+
*/
|
|
227
|
+
function labelSource(node, file) {
|
|
228
|
+
const first = node.children[0]?.position?.start.offset;
|
|
229
|
+
const last = node.children[node.children.length - 1]?.position?.end.offset;
|
|
230
|
+
if (first === undefined || last === undefined)
|
|
231
|
+
return toString(node);
|
|
232
|
+
return String(file.value).slice(first, last);
|
|
233
|
+
}
|
|
234
|
+
function sourceOf(node, file) {
|
|
235
|
+
const start = node.position?.start.offset, end = node.position?.end.offset;
|
|
236
|
+
if (start !== undefined && end !== undefined)
|
|
237
|
+
return String(file.value).slice(start, end);
|
|
238
|
+
return `:${node.name}${toString(node) ? `[${toString(node)}]` : ''}`;
|
|
239
|
+
}
|
|
240
|
+
/** Depth-first walk over mdast parents; the visitor may splice and return the next index. */
|
|
241
|
+
function walk(tree, visit) {
|
|
242
|
+
const go = (parent) => {
|
|
243
|
+
for (let i = 0; i < parent.children.length;) {
|
|
244
|
+
const node = parent.children[i];
|
|
245
|
+
const next = visit(node, parent, i);
|
|
246
|
+
if (next !== undefined) {
|
|
247
|
+
i = next;
|
|
248
|
+
continue;
|
|
249
|
+
}
|
|
250
|
+
if ('children' in node)
|
|
251
|
+
go(node);
|
|
252
|
+
i++;
|
|
253
|
+
}
|
|
254
|
+
};
|
|
255
|
+
go(tree);
|
|
256
|
+
}
|
|
257
|
+
//# sourceMappingURL=plugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,KAAK,EAAE,WAAW,EAAwE,MAAM,gBAAgB,CAAC;AAKvJ,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAEhD,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAmBpD,MAAM,QAAQ,GAA2B;IACvC,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,WAAW,EAAE,QAAQ,EAAE,UAAU;CAC7G,CAAC;AAIF;;;;GAIG;AACH,MAAM,UAAU,YAAY,CAAC,UAAyB,EAAE;IACtD,OAAO,CAAC,IAAU,EAAE,IAAW,EAAQ,EAAE;QACvC,MAAM,MAAM,GAAgB,EAAE,CAAC;QAC/B,MAAM,UAAU,GAAG,IAAI,GAAG,EAAkB,CAAC;QAC7C,wGAAwG;QACxG,MAAM,WAAW,GAAG,IAAI,GAAG,EAAoB,CAAC;QAChD,MAAM,WAAW,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QACtD,IAAI,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,EAAE;YACjC,IAAI,IAAI,CAAC,IAAI,KAAK,MAAM,IAAK,IAAa,CAAC,IAAI,KAAK,MAAM;gBAAE,OAAO;YACnE,MAAM,EAAE,GAAG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AC;IAC3E,IAAI,KAAK,KAAK,SAAS,IAAI,GAAG,KAAK,SAAS;QAAE,OAAO,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;IAC1F,OAAO,IAAI,IAAI,CAAC,IAAI,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC;AACvE,CAAC;AAED,6FAA6F;AAC7F,SAAS,IAAI,CAAC,IAAU,EAAE,KAA+E;IACvG,MAAM,EAAE,GAAG,CAAC,MAAc,EAAQ,EAAE;QAClC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC;YAC5C,MAAM,IAAI,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAE,CAAC;YACjC,MAAM,IAAI,GAAG,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC;YACpC,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;gBAAC,CAAC,GAAG,IAAI,CAAC;gBAAC,SAAS;YAAC,CAAC;YAC/C,IAAI,UAAU,IAAI,IAAI;gBAAE,EAAE,CAAC,IAAc,CAAC,CAAC;YAC3C,CAAC,EAAE,CAAC;QACN,CAAC;IACH,CAAC,CAAC;IACF,EAAE,CAAC,IAAI,CAAC,CAAC;AACX,CAAC"}
|
package/dist/rehype.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { Root } from 'hast';
|
|
2
|
+
import type { VFile } from 'vfile';
|
|
3
|
+
import { type MathOutput } from './tex.js';
|
|
4
|
+
export type KatexOptions = {
|
|
5
|
+
output?: MathOutput;
|
|
6
|
+
};
|
|
7
|
+
/** Render TeX to an HTML string. Never throws; KaTeX shows parse errors in place. */
|
|
8
|
+
export declare function renderTex(tex: string, displayMode: boolean, output?: KatexOptions['output']): string;
|
|
9
|
+
export type ImageOptions = {
|
|
10
|
+
/**
|
|
11
|
+
* "link" (default): every Markdown image becomes a link to it, so nothing is fetched until the
|
|
12
|
+
* reader clicks; an author can't track readers with a remote image. "load": keep <img> (trusted hosts).
|
|
13
|
+
*/
|
|
14
|
+
images?: 'link' | 'load';
|
|
15
|
+
};
|
|
16
|
+
/** Replace images with links ("Image: alt") unless the host trusts the author. Runs before sanitizing. */
|
|
17
|
+
export declare function rehypeActiveImages(options?: ImageOptions): (tree: Root) => void;
|
|
18
|
+
/** Wrap the document in <div class="active-doc" data-active-calc="…"> so the runtime can find its program. */
|
|
19
|
+
export declare function rehypeActiveWrap(): (tree: Root, file: VFile) => void;
|
|
20
|
+
/**
|
|
21
|
+
* Typeset math marked by remarkActive. Runs after sanitizing: KaTeX output (with trust: false) is
|
|
22
|
+
* inserted as raw HTML, so rehype-stringify needs allowDangerousHtml; nothing else produces raw nodes.
|
|
23
|
+
*/
|
|
24
|
+
export declare function rehypeActiveKatex(options?: KatexOptions): (tree: Root) => void;
|
package/dist/rehype.js
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import katex from 'katex';
|
|
2
|
+
import { katexSettings } from './tex.js';
|
|
3
|
+
/** Render TeX to an HTML string. Never throws; KaTeX shows parse errors in place. */
|
|
4
|
+
export function renderTex(tex, displayMode, output) {
|
|
5
|
+
return katex.renderToString(tex, katexSettings(displayMode, output));
|
|
6
|
+
}
|
|
7
|
+
/** Replace images with links ("Image: alt") unless the host trusts the author. Runs before sanitizing. */
|
|
8
|
+
export function rehypeActiveImages(options = {}) {
|
|
9
|
+
return (tree) => {
|
|
10
|
+
if (options.images === 'load')
|
|
11
|
+
return;
|
|
12
|
+
const visit = (node) => {
|
|
13
|
+
node.children.forEach((child, i) => {
|
|
14
|
+
if (child.type !== 'element')
|
|
15
|
+
return;
|
|
16
|
+
if (child.tagName !== 'img') {
|
|
17
|
+
visit(child);
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
const src = typeof child.properties.src === 'string' ? child.properties.src : '';
|
|
21
|
+
const alt = typeof child.properties.alt === 'string' && child.properties.alt ? child.properties.alt : 'image';
|
|
22
|
+
const label = { type: 'text', value: `Image: ${alt}` };
|
|
23
|
+
node.children[i] = src
|
|
24
|
+
? { type: 'element', tagName: 'a', properties: { href: src, className: ['active-image'], rel: ['nofollow', 'noopener', 'noreferrer'] }, children: [label] }
|
|
25
|
+
: { type: 'element', tagName: 'span', properties: { className: ['active-image'] }, children: [label] };
|
|
26
|
+
});
|
|
27
|
+
};
|
|
28
|
+
visit(tree);
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
/** Wrap the document in <div class="active-doc" data-active-calc="…"> so the runtime can find its program. */
|
|
32
|
+
export function rehypeActiveWrap() {
|
|
33
|
+
return (tree, file) => {
|
|
34
|
+
const blocks = file.data.active?.blocks ?? [];
|
|
35
|
+
const doc = {
|
|
36
|
+
type: 'element', tagName: 'div',
|
|
37
|
+
properties: { className: ['active-doc'], ...(blocks.length ? { dataActiveCalc: JSON.stringify(blocks.map(b => b.text)) } : {}) },
|
|
38
|
+
children: tree.children,
|
|
39
|
+
};
|
|
40
|
+
tree.children = [doc];
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Typeset math marked by remarkActive. Runs after sanitizing: KaTeX output (with trust: false) is
|
|
45
|
+
* inserted as raw HTML, so rehype-stringify needs allowDangerousHtml; nothing else produces raw nodes.
|
|
46
|
+
*/
|
|
47
|
+
export function rehypeActiveKatex(options = {}) {
|
|
48
|
+
return (tree) => {
|
|
49
|
+
const visit = (node) => {
|
|
50
|
+
for (const child of node.children) {
|
|
51
|
+
if (child.type !== 'element')
|
|
52
|
+
continue;
|
|
53
|
+
const cls = child.properties.className;
|
|
54
|
+
if (Array.isArray(cls) && cls.includes('active-math')) {
|
|
55
|
+
const tex = child.children.map(c => (c.type === 'text' ? c.value : '')).join('');
|
|
56
|
+
child.children = [{ type: 'raw', value: renderTex(tex, child.properties.dataActiveDisplay === 'true', options.output) }];
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
visit(child);
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
visit(tree);
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=rehype.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rehype.js","sourceRoot":"","sources":["../src/rehype.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAE,aAAa,EAAmB,MAAM,UAAU,CAAC;AAI1D,qFAAqF;AACrF,MAAM,UAAU,SAAS,CAAC,GAAW,EAAE,WAAoB,EAAE,MAA+B;IAC1F,OAAO,KAAK,CAAC,cAAc,CAAC,GAAG,EAAE,aAAa,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC,CAAC;AACvE,CAAC;AAUD,0GAA0G;AAC1G,MAAM,UAAU,kBAAkB,CAAC,UAAwB,EAAE;IAC3D,OAAO,CAAC,IAAU,EAAQ,EAAE;QAC1B,IAAI,OAAO,CAAC,MAAM,KAAK,MAAM;YAAE,OAAO;QACtC,MAAM,KAAK,GAAG,CAAC,IAAoB,EAAQ,EAAE;YAC3C,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,CAAC,EAAE,EAAE;gBACjC,IAAI,KAAK,CAAC,IAAI,KAAK,SAAS;oBAAE,OAAO;gBACrC,IAAI,KAAK,CAAC,OAAO,KAAK,KAAK,EAAE,CAAC;oBAAC,KAAK,CAAC,KAAK,CAAC,CAAC;oBAAC,OAAO;gBAAC,CAAC;gBACtD,MAAM,GAAG,GAAG,OAAO,KAAK,CAAC,UAAU,CAAC,GAAG,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;gBACjF,MAAM,GA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H,CAAC,CAAC;QACF,KAAK,CAAC,IAAI,CAAC,CAAC;IACd,CAAC,CAAC;AACJ,CAAC"}
|
package/dist/sanitize.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { defaultSchema } from 'rehype-sanitize';
|
|
2
|
+
const ACTIVE = ['dataActiveInput', 'dataActiveValue', 'dataActiveFormat', 'dataActiveTex', 'dataActiveDisplay', 'dataActiveCalc', 'dataActiveFor', 'dataActiveWidget', 'dataActiveError'];
|
|
3
|
+
/**
|
|
4
|
+
* GitHub's sanitize schema plus the elements and attributes active-md emits.
|
|
5
|
+
* KaTeX output is added after sanitizing, so MathML isn't listed here.
|
|
6
|
+
*/
|
|
7
|
+
export const activeSchema = {
|
|
8
|
+
...defaultSchema,
|
|
9
|
+
// <picture>/<source> would fetch images on display; images become links instead (rehypeActiveImages).
|
|
10
|
+
tagNames: [...(defaultSchema.tagNames ?? []).filter(t => t !== 'picture' && t !== 'source'), 'input', 'output', 'aside', 'label'],
|
|
11
|
+
attributes: {
|
|
12
|
+
...defaultSchema.attributes,
|
|
13
|
+
'*': [...(defaultSchema.attributes?.['*'] ?? []), ...ACTIVE, 'className', 'role', 'ariaLive', 'ariaLabel', 'title'],
|
|
14
|
+
// Image links (rehypeActiveImages); GitHub's schema otherwise allows only footnote classes on <a>.
|
|
15
|
+
a: [
|
|
16
|
+
...(defaultSchema.attributes?.['a'] ?? []).filter(a => !(Array.isArray(a) && a[0] === 'className')),
|
|
17
|
+
['className', 'data-footnote-backref', 'active-image'],
|
|
18
|
+
'rel',
|
|
19
|
+
],
|
|
20
|
+
// Task-list checkboxes keep GitHub's rule (disabled checkbox) through remark-gfm; our inputs are number/range.
|
|
21
|
+
input: [['disabled', true], ['type', 'checkbox', 'number', 'range'], 'checked', 'value', 'min', 'max', 'step', 'inputMode'],
|
|
22
|
+
},
|
|
23
|
+
// GitHub's schema forces every <input> to be a disabled checkbox; ours are live number boxes and sliders.
|
|
24
|
+
required: Object.fromEntries(Object.entries(defaultSchema.required ?? {}).filter(([tag]) => tag !== 'input')),
|
|
25
|
+
};
|
|
26
|
+
//# sourceMappingURL=sanitize.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sanitize.js","sourceRoot":"","sources":["../src/sanitize.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAGhD,MAAM,MAAM,GAAG,CAAC,iBAAiB,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,eAAe,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,eAAe,EAAE,kBAAkB,EAAE,iBAAiB,CAAC,CAAC;AAE1L;;;GAGG;AACH,MAAM,CAAC,MAAM,YAAY,GAAW;IAClC,GAAG,aAAa;IAChB,sGAAsG;IACtG,QAAQ,EAAE,CAAC,GAAG,CAAC,aAAa,CAAC,QAAQ,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,KAAK,SAAS,IAAI,CAAC,KAAK,QAAQ,CAAC,EAAE,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,CAAC;IACjI,UAAU,EAAE;QACV,GAAG,aAAa,CAAC,UAAU;QAC3B,GAAG,EAAE,CAAC,GAAG,CAAC,aAAa,CAAC,UAAU,EAAE,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,EAAE,GAAG,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,UAAU,EAAE,WAAW,EAAE,OAAO,CAAC;QACnH,mGAAmG;QACnG,CAAC,EAAE;YACD,GAAG,CAAC,aAAa,CAAC,UAAU,EAAE,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,WAAW,CAAC,CAAC;YACnG,CAAC,WAAW,EAAE,uBAAuB,EAAE,cAAc,CAAC;YACtD,KAAK;SACN;QACD,+GAA+G;QAC/G,KAAK,EAAE,CAAC,CAAC,UAAU,EAAE,IAAI,CAAC,EAAE,CAAC,MAAM,EAAE,UAAU,EAAE,QAAQ,EAAE,OAAO,CAAC,EAAE,SAAS,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,WAAW,CAAC;KAC5H;IACD,0GAA0G;IAC1G,QAAQ,EAAE,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,aAAa,CAAC,QAAQ,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC,GAAG,KAAK,OAAO,CAAC,CAAC;CAC9G,CAAC"}
|
package/dist/tex.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Result } from '@vchernoy/calc';
|
|
2
|
+
import type { KatexOptions as KatexSettings } from 'katex';
|
|
3
|
+
/** `{{expr}}` inside TeX. An expression ends at the first "}}". */
|
|
4
|
+
export declare const PLACEHOLDER: RegExp;
|
|
5
|
+
/** The expressions used in a TeX template, in order. */
|
|
6
|
+
export declare function placeholders(tex: string): string[];
|
|
7
|
+
/** A number as TeX: no grouping, "." as decimal point, at most 6 decimals. */
|
|
8
|
+
export declare function texNumber(value: number): string;
|
|
9
|
+
/**
|
|
10
|
+
* Substitute results into a template. Every value is one TeX group, so `x^{{n}}` and `\\sqrt{{n}}`
|
|
11
|
+
* keep the whole number as the argument. Errors show as a red "?"; the message stays out of TeX.
|
|
12
|
+
*/
|
|
13
|
+
export declare function substitute(tex: string, results: readonly Result[]): string;
|
|
14
|
+
/** "mathml" (default) needs no CSS or fonts; "htmlAndMathml" needs the host to load KaTeX's CSS. */
|
|
15
|
+
export type MathOutput = 'mathml' | 'htmlAndMathml';
|
|
16
|
+
/** KaTeX options that are always safe for untrusted documents. */
|
|
17
|
+
export declare function katexSettings(displayMode: boolean, output?: MathOutput): KatexSettings;
|
package/dist/tex.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/** `{{expr}}` inside TeX. An expression ends at the first "}}". */
|
|
2
|
+
export const PLACEHOLDER = /\{\{([^{}]*?)\}\}/g;
|
|
3
|
+
/** The expressions used in a TeX template, in order. */
|
|
4
|
+
export function placeholders(tex) {
|
|
5
|
+
return [...tex.matchAll(PLACEHOLDER)].map(m => m[1].trim());
|
|
6
|
+
}
|
|
7
|
+
/** A number as TeX: no grouping, "." as decimal point, at most 6 decimals. */
|
|
8
|
+
export function texNumber(value) {
|
|
9
|
+
const s = Number.isInteger(value) ? String(value) : String(Number(value.toFixed(6)));
|
|
10
|
+
if (/e/i.test(s)) {
|
|
11
|
+
const [m, e] = s.split(/e/i);
|
|
12
|
+
return `${m}\\times 10^{${Number(e)}}`;
|
|
13
|
+
}
|
|
14
|
+
return s;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Substitute results into a template. Every value is one TeX group, so `x^{{n}}` and `\\sqrt{{n}}`
|
|
18
|
+
* keep the whole number as the argument. Errors show as a red "?"; the message stays out of TeX.
|
|
19
|
+
*/
|
|
20
|
+
export function substitute(tex, results) {
|
|
21
|
+
let i = 0;
|
|
22
|
+
return tex.replace(PLACEHOLDER, () => {
|
|
23
|
+
const r = results[i++];
|
|
24
|
+
return r?.kind === 'value' ? `{${texNumber(r.value)}}` : '{\\color{red}?}';
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
/** KaTeX options that are always safe for untrusted documents. */
|
|
28
|
+
export function katexSettings(displayMode, output = 'mathml') {
|
|
29
|
+
return { displayMode, output, throwOnError: false, trust: false, strict: 'ignore', maxSize: 50, maxExpand: 1000 };
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=tex.js.map
|
package/dist/tex.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tex.js","sourceRoot":"","sources":["../src/tex.ts"],"names":[],"mappings":"AAGA,mEAAmE;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AoB,EAAE,SAAqB,QAAQ;IAC/E,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,YAAY,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;AACpH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,71 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vchernoy/remark-active",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "A remark plugin for active-md: calc blocks, :input, :value and {{…}} in math",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"remark",
|
|
7
|
+
"remark-plugin",
|
|
8
|
+
"markdown",
|
|
9
|
+
"katex",
|
|
10
|
+
"calculator",
|
|
11
|
+
"active-md"
|
|
12
|
+
],
|
|
13
|
+
"license": "MIT",
|
|
14
|
+
"homepage": "https://github.com/vchernoy/active-md/tree/main/packages/remark#readme",
|
|
15
|
+
"bugs": {
|
|
16
|
+
"url": "https://github.com/vchernoy/active-md/issues"
|
|
17
|
+
},
|
|
18
|
+
"repository": {
|
|
19
|
+
"type": "git",
|
|
20
|
+
"url": "git+https://github.com/vchernoy/active-md.git",
|
|
21
|
+
"directory": "packages/remark"
|
|
22
|
+
},
|
|
23
|
+
"type": "module",
|
|
24
|
+
"main": "./dist/index.js",
|
|
25
|
+
"types": "./dist/index.d.ts",
|
|
26
|
+
"exports": {
|
|
27
|
+
".": {
|
|
28
|
+
"types": "./dist/index.d.ts",
|
|
29
|
+
"import": "./dist/index.js"
|
|
30
|
+
},
|
|
31
|
+
"./tex": {
|
|
32
|
+
"types": "./dist/tex.d.ts",
|
|
33
|
+
"import": "./dist/tex.js"
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
"files": [
|
|
37
|
+
"dist"
|
|
38
|
+
],
|
|
39
|
+
"sideEffects": false,
|
|
40
|
+
"engines": {
|
|
41
|
+
"node": ">=18"
|
|
42
|
+
},
|
|
43
|
+
"publishConfig": {
|
|
44
|
+
"access": "public",
|
|
45
|
+
"provenance": true
|
|
46
|
+
},
|
|
47
|
+
"scripts": {
|
|
48
|
+
"build": "tsc -p tsconfig.build.json"
|
|
49
|
+
},
|
|
50
|
+
"dependencies": {
|
|
51
|
+
"@types/hast": "3.0.5",
|
|
52
|
+
"@types/mdast": "4.0.4",
|
|
53
|
+
"@vchernoy/calc": "0.1.0",
|
|
54
|
+
"katex": "0.19.1",
|
|
55
|
+
"mdast-util-to-string": "4.0.0",
|
|
56
|
+
"rehype-sanitize": "6.0.0",
|
|
57
|
+
"rehype-stringify": "10.0.1",
|
|
58
|
+
"remark-directive": "4.0.0",
|
|
59
|
+
"remark-gfm": "4.0.1",
|
|
60
|
+
"remark-math": "6.0.0",
|
|
61
|
+
"remark-parse": "11.0.0",
|
|
62
|
+
"remark-rehype": "11.1.2",
|
|
63
|
+
"unified": "11.0.5",
|
|
64
|
+
"unist-util-visit": "5.2.0",
|
|
65
|
+
"vfile": "6.0.3"
|
|
66
|
+
},
|
|
67
|
+
"devDependencies": {
|
|
68
|
+
"mdast-util-directive": "3.2.0",
|
|
69
|
+
"mdast-util-math": "3.0.0"
|
|
70
|
+
}
|
|
71
|
+
}
|