@mdrs/core 1.0.0-alpha1 → 1.0.0-alpha2

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
@@ -1,119 +1,96 @@
1
1
  # MDRS
2
2
 
3
- **MDRS (Markdown Rich Syntax)** is a superset of Markdown. It is meant as a drop-in replacement: any CommonMark or GitHub Flavored Markdown document should render the same way. On top of that it adds directives (`:::note`, `:::tabs`, `:::details`, `:::steps`, …), math, diagrams, charts, references and document variables (`:::define` with `${…}` interpolation).
3
+ [![CircleCI](https://dl.circleci.com/status-badge/img/circleci/stZqvYiNAK17m5zy7ERCb/EGBRyRQ9CWeyLiSDGguM5Z/tree/main.svg?style=svg)](https://dl.circleci.com/status-badge/redirect/circleci/stZqvYiNAK17m5zy7ERCb/EGBRyRQ9CWeyLiSDGguM5Z/tree/main) [![npm](https://img.shields.io/npm/v/@mdrs/core/alpha?label=npm)](https://www.npmjs.com/package/@mdrs/core) [![crates.io](https://img.shields.io/crates/v/mdrs?label=crates.io)](https://crates.io/crates/mdrs) [![docs.rs](https://img.shields.io/docsrs/mdrs)](https://docs.rs/mdrs) ![License](https://img.shields.io/badge/license-MIT%20OR%20Apache--2.0-blue)
4
+
5
+ **MDRS (Markdown Rich Syntax)** is a superset of Markdown. A CommonMark or GitHub Flavored Markdown document renders as it would anywhere else, and MDRS adds callouts, collapsible sections, steps, tabs, math, diagrams, extended task lists and document variables on top. This repository is the MDRS renderer: it turns MDRS into sanitized HTML, is written in Rust and is available as a crate and as an npm package for Node.js and Bun.
4
6
 
5
7
  MDRS files use the `.mdrs` extension.
6
8
 
7
- ## Status
9
+ > **Alpha.** The API may still change before 1.0.0. On npm, install the `alpha` tag.
8
10
 
9
- Alpha (`v1.0.0-alpha1`). The Rust renderer port is in progress. The original TypeScript engine at `idstead/packages/mdrs/core` remains intact and is the behavior reference.
11
+ ## A taste
10
12
 
11
- The Rust crate supports CommonMark/GFM rendering, sanitization, selected block directives, JSON-backed `:::define` expressions and conditionals, server-side KaTeX math, diagram/chart/embed markers, references, extended task states, icons, and verbatim blocks. It is not a byte-for-byte parity port: asynchronous JavaScript resolver callbacks and browser-side Mermaid/chart execution remain runtime integrations rather than Rust implementations.
13
+ ```mdrs
14
+ :::define
15
+ project: "MDRS"
16
+ :::
12
17
 
13
- | Registry | Name |
14
- | --- | --- |
15
- | crates.io | [`mdrs`](https://crates.io/crates/mdrs) |
16
- | npm | [`@mdrs/core`](https://www.npmjs.com/package/@mdrs/core) |
18
+ # Hello from ${project}
17
19
 
18
- The `napi` and `wasm` Cargo features expose `renderMarkdown`, `prepareMarkdownPage`, `resolveDefines` and `isMdrsPath`, plus `*WithData` variants that accept a JSON string for definitions, expressions and conditionals. Async JavaScript resolver callbacks are not exposed by the synchronous Rust ABI.
20
+ Plain **Markdown** works as usual.
19
21
 
20
- ## Install
22
+ :::tip
23
+ Directives open with `:::name` and close with a bare `:::`.
24
+ :::
21
25
 
22
- ```sh
23
- cargo add mdrs # Rust
24
- bun add @mdrs/core # JavaScript / TypeScript (or: npm install @mdrs/core)
26
+ :::details summary="What is rendered on the server?"
27
+ Everything except diagrams and charts, including math: $$ e^{i\pi} + 1 = 0 $$
28
+ :::
25
29
  ```
26
30
 
27
- The npm package ships prebuilt binaries for Linux (x64 and arm64, glibc and musl), macOS (x64 and arm64) and Windows (x64 and arm64) as optional dependencies. Math is rendered server-side through `katex-rs`; Mermaid and chart markers are left for browser-side execution.
31
+ The [MDRS syntax guide](https://github.com/farhnkrnapratma/idstead/tree/main/docs/008-mdrs) describes every construct. It is written for the original TypeScript engine; see [Limitations](#limitations) for what the Rust renderer does not support yet.
28
32
 
29
- ## Usage
30
-
31
- Rust:
33
+ ## Install
32
34
 
33
- ```rust
34
- use std::path::Path;
35
+ ```sh
36
+ npm install @mdrs/core@alpha # or: bun add @mdrs/core@alpha
37
+ cargo add mdrs # Rust
38
+ ```
35
39
 
36
- assert_eq!(mdrs::FILE_EXTENSION, "mdrs");
37
- assert!(mdrs::is_mdrs_path(Path::new("docs/intro.mdrs")));
40
+ The npm package ships prebuilt native addons for Linux (x64 and arm64, glibc and musl), macOS (x64 and arm64) and Windows (x64 and arm64), so nothing is compiled on install.
38
41
 
39
- let html = mdrs::render_markdown("# Hello\n\nA **rich** document.")?;
40
- ```
42
+ ## Usage
41
43
 
42
- JavaScript / TypeScript:
44
+ ### Node.js and Bun
43
45
 
44
46
  ```ts
45
- import { FILE_EXTENSION, isMdrsPath, renderMarkdown } from '@mdrs/core';
47
+ import { prepareMarkdownPage, renderMarkdown, renderMarkdownWithData } from "@mdrs/core";
46
48
 
47
- FILE_EXTENSION; // "mdrs"
48
- isMdrsPath('docs/intro.mdrs'); // true
49
- renderMarkdown('# Hello\n\nA **rich** document.');
50
- ```
49
+ const html = renderMarkdown("# Hello\n\nA **rich** document.");
51
50
 
52
- To render a `.mdrs` file to HTML, run the bundled example with the path of the file:
51
+ const page = prepareMarkdownPage(source, { internalOrigins: ["https://example.com"] });
52
+ page.html; // the rendered HTML
53
+ page.headings; // [{ id, text, level }] for a table of contents
53
54
 
54
- ```sh
55
- cargo run --example showcase_render -- docs/intro.mdrs > intro.html
55
+ renderMarkdownWithData("Hello ${name}!", JSON.stringify({ name: "Ada" }));
56
56
  ```
57
57
 
58
- ## Repository layout
58
+ | Function | Returns |
59
+ | --------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------- |
60
+ | `renderMarkdown(source, options?)` | HTML |
61
+ | `prepareMarkdownPage(source, options?)` | `{ html, headings }` |
62
+ | `resolveDefines(source)` | The source with `:::define` variables substituted |
63
+ | `renderMarkdownWithData`, `prepareMarkdownPageWithData`, `resolveDefinesWithData` | The same, with a JSON string of values that expressions can read |
64
+ | `isMdrsPath(path)`, `FILE_EXTENSION` | Whether a path ends in `.mdrs`, and the extension itself |
59
65
 
60
- ```
61
- src/
62
- lib.rs public API
63
- markdown.rs CommonMark / GFM rendering
64
- containers.rs block directives (:::note, :::tabs, …)
65
- define.rs :::define variables, expressions, conditionals
66
- headings.rs heading ids and structure
67
- sanitize.rs HTML sanitization
68
- bindings/ Node.js (napi) and WebAssembly (wasm) glue
69
- examples/ showcase_render: renders a .mdrs file to HTML
70
- benches/ rendering baseline
71
- scripts/ binding checks and parity tooling
72
- index.js JavaScript entry (re-exports the generated native loader)
73
- ```
66
+ `internalOrigins` lists origins whose links open in the same tab; other links get `target="_blank"`. Invalid definitions and expressions, such as a variable a `:::define` block does not declare, throw an error that names the problem.
74
67
 
75
- ## Development
68
+ ### Rust
76
69
 
77
- Requirements: Rust (stable) with the `wasm32-unknown-unknown` target, and [Bun](https://bun.sh) (`bun.lock` is the only lockfile).
70
+ ```rust
71
+ use mdrs::{RenderOptions, prepare_markdown_page, render_markdown};
78
72
 
79
- ```sh
80
- bun install # JS dependencies and git hooks
81
- cargo test --locked # Rust tests
82
- cargo check --features napi
83
- cargo check --target wasm32-unknown-unknown --features wasm
84
- bun run build:release # Node artifact for this platform
85
- bun run test:bindings # offline binding checks
86
- bun run test:native # build:release + test:bindings
73
+ let html = render_markdown("# Hello\n\nA **rich** document.")?;
74
+ let page = prepare_markdown_page("# Hello", &RenderOptions::default())?;
87
75
  ```
88
76
 
89
- `test:bindings` validates the TypeScript declarations against both binding modules and checks the `napi` and `wasm` Cargo features. It reports, without failing, when the local `napi` or `wasm-pack` packagers are unavailable.
77
+ The Rust API mirrors the JavaScript one with snake_case names. Documents are limited to 500,000 bytes of input and 2,000,000 bytes of output.
90
78
 
91
- Parity and performance checks:
79
+ ## Output
92
80
 
93
- ```sh
94
- bun scripts/showcase-parity.ts # compare the showcase with the TypeScript mirror (needs the idstead checkout)
95
- cargo bench --locked --offline --bench render
96
- ```
81
+ The HTML is sanitized: raw HTML is reduced to a safe subset, event handlers are stripped and unsafe URLs are removed. Generated classes start with `mdrs-`. Math is typeset to KaTeX HTML on the server. Mermaid diagrams and charts are emitted as placeholders that carry their source, for a browser-side script to render.
82
+
83
+ ## Limitations
97
84
 
98
- The parity command reports output hashes, marker counts and the first difference. The Rust output is intentionally not byte-for-byte identical to the mirror yet.
85
+ The Rust renderer is a port of the TypeScript engine described in the syntax guide and does not match it byte for byte yet. Known gaps:
99
86
 
100
- Releases are cut with git-flow (`git-flow release start/finish`). Pushing a `v*` tag makes CircleCI build the native binding for every platform and publish `@mdrs/core` to npm; the crate is published with `cargo publish`.
87
+ - GitHub alert blockquotes (`> [!NOTE]`) render as plain blockquotes; use `:::note` and the other callout directives.
88
+ - Live data (`get(url, path)`) and other asynchronous resolvers are not available, because the bindings are synchronous.
101
89
 
102
90
  ## Contributing
103
91
 
104
- This repository uses [git-flow-next](https://git-flow.sh/) (classic preset): `main` is release-only, work happens on `feature/*` and `bugfix/*` branches off `develop`. Commits are signed off (`git commit -s`) and follow [Conventional Commits](https://www.conventionalcommits.org), enforced by commitlint in a `commit-msg` hook and in CI. Install the hooks with `bash .githooks/install.sh` (`bun install` does it through the `prepare` script). CI runs on CircleCI: `reuse lint`, format and lint, tests, `cargo deny`, a TruffleHog secret scan and commitlint on every push. The branch rules are written out in [`CLAUDE.md`](CLAUDE.md).
92
+ Bug reports and pull requests are welcome. [`CONTRIBUTING.md`](https://github.com/farhnkrnapratma/mdrs/blob/main/CONTRIBUTING.md) explains how to build, test and submit changes.
105
93
 
106
94
  ## License
107
95
 
108
- Licensed under either of
109
-
110
- - Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or <https://www.apache.org/licenses/LICENSE-2.0>)
111
- - MIT License ([LICENSE-MIT](LICENSE-MIT) or <https://opensource.org/licenses/MIT>)
112
-
113
- at your option.
114
-
115
- Unless you explicitly state otherwise, any contribution intentionally submitted
116
- for inclusion in this project by you, as defined in the Apache-2.0 license,
117
- shall be dual licensed as above, without any additional terms or conditions.
118
-
119
- Copyright © 2026 Farhan Kurnia Pratama
96
+ Licensed under either of the [Apache License, Version 2.0](https://github.com/farhnkrnapratma/mdrs/blob/main/LICENSE-APACHE) or the [MIT License](https://github.com/farhnkrnapratma/mdrs/blob/main/LICENSE-MIT), at your option. Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this project by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
package/index.d.ts CHANGED
@@ -1,46 +1,49 @@
1
1
  /** The file extension used by MDRS documents, without the leading dot. */
2
- export declare const FILE_EXTENSION: 'mdrs';
2
+ export declare const FILE_EXTENSION: "mdrs";
3
3
 
4
4
  /** Returns `true` when `path` ends in the `.mdrs` extension (case-insensitive). */
5
5
  export declare function isMdrsPath(path: string): boolean;
6
6
 
7
7
  export interface RenderOptions {
8
- internalOrigins?: string[];
8
+ internalOrigins?: string[];
9
9
  }
10
10
 
11
11
  export interface HeadingItem {
12
- id: string;
13
- text: string;
14
- level: number;
12
+ id: string;
13
+ text: string;
14
+ level: number;
15
15
  }
16
16
 
17
17
  export interface PreparedMarkdownPage {
18
- html: string;
19
- headings: HeadingItem[];
18
+ html: string;
19
+ headings: HeadingItem[];
20
20
  }
21
21
 
22
22
  export declare function renderMarkdown(
23
- markdown: string,
24
- options?: RenderOptions
23
+ markdown: string,
24
+ options?: RenderOptions,
25
25
  ): string;
26
26
 
27
27
  export declare function renderMarkdownWithData(
28
- markdown: string,
29
- dataJson: string,
30
- options?: RenderOptions
28
+ markdown: string,
29
+ dataJson: string,
30
+ options?: RenderOptions,
31
31
  ): string;
32
32
 
33
33
  export declare function prepareMarkdownPage(
34
- markdown: string,
35
- options?: RenderOptions
34
+ markdown: string,
35
+ options?: RenderOptions,
36
36
  ): PreparedMarkdownPage;
37
37
 
38
38
  export declare function prepareMarkdownPageWithData(
39
- markdown: string,
40
- dataJson: string,
41
- options?: RenderOptions
39
+ markdown: string,
40
+ dataJson: string,
41
+ options?: RenderOptions,
42
42
  ): PreparedMarkdownPage;
43
43
 
44
44
  export declare function resolveDefines(markdown: string): string;
45
45
 
46
- export declare function resolveDefinesWithData(markdown: string, dataJson: string): string;
46
+ export declare function resolveDefinesWithData(
47
+ markdown: string,
48
+ dataJson: string,
49
+ ): string;
package/index.js CHANGED
@@ -1,16 +1,16 @@
1
- export const FILE_EXTENSION = 'mdrs';
1
+ export const FILE_EXTENSION = "mdrs";
2
2
 
3
3
  export function isMdrsPath(path) {
4
- const name = String(path).split(/[\\/]/).pop() ?? '';
5
- const dot = name.lastIndexOf('.');
6
- return dot > 0 && name.slice(dot + 1).toLowerCase() === FILE_EXTENSION;
4
+ const name = String(path).split(/[\\/]/).pop() ?? "";
5
+ const dot = name.lastIndexOf(".");
6
+ return dot > 0 && name.slice(dot + 1).toLowerCase() === FILE_EXTENSION;
7
7
  }
8
8
 
9
9
  export {
10
- prepareMarkdownPage,
11
- prepareMarkdownPageWithData,
12
- renderMarkdown,
13
- renderMarkdownWithData,
14
- resolveDefines,
15
- resolveDefinesWithData,
16
- } from './index.native.js';
10
+ prepareMarkdownPage,
11
+ prepareMarkdownPageWithData,
12
+ renderMarkdown,
13
+ renderMarkdownWithData,
14
+ resolveDefines,
15
+ resolveDefinesWithData,
16
+ } from "./index.native.js";
package/index.native.d.ts CHANGED
@@ -7,33 +7,51 @@
7
7
  * flavor napi-rs can build is listed, because `NAPI_RS_NATIVE_LIBRARY_PATH`
8
8
  * can point the loader at a WASI artifact this package does not build itself.
9
9
  */
10
- export declare const __napiBindingTarget: 'native' | 'wasm32-wasi' | 'wasm32-wasip1'
10
+ export declare const __napiBindingTarget:
11
+ "native" | "wasm32-wasi" | "wasm32-wasip1";
11
12
 
12
13
  export interface BindingHeadingItem {
13
- id: string
14
- text: string
15
- level: number
14
+ id: string;
15
+ text: string;
16
+ level: number;
16
17
  }
17
18
 
18
19
  export interface BindingPreparedMarkdownPage {
19
- html: string
20
- headings: Array<BindingHeadingItem>
20
+ html: string;
21
+ headings: Array<BindingHeadingItem>;
21
22
  }
22
23
 
23
24
  export interface BindingRenderOptions {
24
- internalOrigins?: Array<string>
25
+ internalOrigins?: Array<string>;
25
26
  }
26
27
 
27
- export declare function isMdrsPath(path: string): boolean
28
+ export declare function isMdrsPath(path: string): boolean;
28
29
 
29
- export declare function prepareMarkdownPage(markdown: string, options?: BindingRenderOptions | undefined | null): BindingPreparedMarkdownPage
30
+ export declare function prepareMarkdownPage(
31
+ markdown: string,
32
+ options?: BindingRenderOptions | undefined | null,
33
+ ): BindingPreparedMarkdownPage;
30
34
 
31
- export declare function prepareMarkdownPageWithData(markdown: string, dataJson: string, options?: BindingRenderOptions | undefined | null): BindingPreparedMarkdownPage
35
+ export declare function prepareMarkdownPageWithData(
36
+ markdown: string,
37
+ dataJson: string,
38
+ options?: BindingRenderOptions | undefined | null,
39
+ ): BindingPreparedMarkdownPage;
32
40
 
33
- export declare function renderMarkdown(markdown: string, options?: BindingRenderOptions | undefined | null): string
41
+ export declare function renderMarkdown(
42
+ markdown: string,
43
+ options?: BindingRenderOptions | undefined | null,
44
+ ): string;
34
45
 
35
- export declare function renderMarkdownWithData(markdown: string, dataJson: string, options?: BindingRenderOptions | undefined | null): string
46
+ export declare function renderMarkdownWithData(
47
+ markdown: string,
48
+ dataJson: string,
49
+ options?: BindingRenderOptions | undefined | null,
50
+ ): string;
36
51
 
37
- export declare function resolveDefines(markdown: string): string
52
+ export declare function resolveDefines(markdown: string): string;
38
53
 
39
- export declare function resolveDefinesWithData(markdown: string, dataJson: string): string
54
+ export declare function resolveDefinesWithData(
55
+ markdown: string,
56
+ dataJson: string,
57
+ ): string;