@mdrs/core 0.0.0-stage → 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/LICENSE-APACHE ADDED
@@ -0,0 +1,73 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.
10
+
11
+ "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
12
+
13
+ "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
14
+
15
+ "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
16
+
17
+ "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
18
+
19
+ "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
20
+
21
+ "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).
22
+
23
+ "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
24
+
25
+ "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."
26
+
27
+ "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
28
+
29
+ 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
30
+
31
+ 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
32
+
33
+ 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
34
+
35
+ (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and
36
+
37
+ (b) You must cause any modified files to carry prominent notices stating that You changed the files; and
38
+
39
+ (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
40
+
41
+ (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License.
42
+
43
+ You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
44
+
45
+ 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
46
+
47
+ 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
48
+
49
+ 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
50
+
51
+ 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
52
+
53
+ 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
54
+
55
+ END OF TERMS AND CONDITIONS
56
+
57
+ APPENDIX: How to apply the Apache License to your work.
58
+
59
+ To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives.
60
+
61
+ Copyright [yyyy] [name of copyright owner]
62
+
63
+ Licensed under the Apache License, Version 2.0 (the "License");
64
+ you may not use this file except in compliance with the License.
65
+ You may obtain a copy of the License at
66
+
67
+ http://www.apache.org/licenses/LICENSE-2.0
68
+
69
+ Unless required by applicable law or agreed to in writing, software
70
+ distributed under the License is distributed on an "AS IS" BASIS,
71
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
72
+ See the License for the specific language governing permissions and
73
+ limitations under the License.
package/LICENSE-MIT ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Farhan Kurnia Pratama
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,96 @@
1
- # Temporary Holding Version
1
+ # MDRS
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
+ [![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.
6
+
7
+ MDRS files use the `.mdrs` extension.
8
+
9
+ > **Alpha.** The API may still change before 1.0.0. On npm, install the `alpha` tag.
10
+
11
+ ## A taste
12
+
13
+ ```mdrs
14
+ :::define
15
+ project: "MDRS"
16
+ :::
17
+
18
+ # Hello from ${project}
19
+
20
+ Plain **Markdown** works as usual.
21
+
22
+ :::tip
23
+ Directives open with `:::name` and close with a bare `:::`.
24
+ :::
25
+
26
+ :::details summary="What is rendered on the server?"
27
+ Everything except diagrams and charts, including math: $$ e^{i\pi} + 1 = 0 $$
28
+ :::
29
+ ```
30
+
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.
32
+
33
+ ## Install
34
+
35
+ ```sh
36
+ npm install @mdrs/core@alpha # or: bun add @mdrs/core@alpha
37
+ cargo add mdrs # Rust
38
+ ```
39
+
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.
41
+
42
+ ## Usage
43
+
44
+ ### Node.js and Bun
45
+
46
+ ```ts
47
+ import { prepareMarkdownPage, renderMarkdown, renderMarkdownWithData } from "@mdrs/core";
48
+
49
+ const html = renderMarkdown("# Hello\n\nA **rich** document.");
50
+
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
54
+
55
+ renderMarkdownWithData("Hello ${name}!", JSON.stringify({ name: "Ada" }));
56
+ ```
57
+
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 |
65
+
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.
67
+
68
+ ### Rust
69
+
70
+ ```rust
71
+ use mdrs::{RenderOptions, prepare_markdown_page, render_markdown};
72
+
73
+ let html = render_markdown("# Hello\n\nA **rich** document.")?;
74
+ let page = prepare_markdown_page("# Hello", &RenderOptions::default())?;
75
+ ```
76
+
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.
78
+
79
+ ## Output
80
+
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
84
+
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:
86
+
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.
89
+
90
+ ## Contributing
91
+
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.
93
+
94
+ ## License
95
+
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 ADDED
@@ -0,0 +1,49 @@
1
+ /** The file extension used by MDRS documents, without the leading dot. */
2
+ export declare const FILE_EXTENSION: "mdrs";
3
+
4
+ /** Returns `true` when `path` ends in the `.mdrs` extension (case-insensitive). */
5
+ export declare function isMdrsPath(path: string): boolean;
6
+
7
+ export interface RenderOptions {
8
+ internalOrigins?: string[];
9
+ }
10
+
11
+ export interface HeadingItem {
12
+ id: string;
13
+ text: string;
14
+ level: number;
15
+ }
16
+
17
+ export interface PreparedMarkdownPage {
18
+ html: string;
19
+ headings: HeadingItem[];
20
+ }
21
+
22
+ export declare function renderMarkdown(
23
+ markdown: string,
24
+ options?: RenderOptions,
25
+ ): string;
26
+
27
+ export declare function renderMarkdownWithData(
28
+ markdown: string,
29
+ dataJson: string,
30
+ options?: RenderOptions,
31
+ ): string;
32
+
33
+ export declare function prepareMarkdownPage(
34
+ markdown: string,
35
+ options?: RenderOptions,
36
+ ): PreparedMarkdownPage;
37
+
38
+ export declare function prepareMarkdownPageWithData(
39
+ markdown: string,
40
+ dataJson: string,
41
+ options?: RenderOptions,
42
+ ): PreparedMarkdownPage;
43
+
44
+ export declare function resolveDefines(markdown: string): string;
45
+
46
+ export declare function resolveDefinesWithData(
47
+ markdown: string,
48
+ dataJson: string,
49
+ ): string;
package/index.js ADDED
@@ -0,0 +1,16 @@
1
+ export const FILE_EXTENSION = "mdrs";
2
+
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;
7
+ }
8
+
9
+ export {
10
+ prepareMarkdownPage,
11
+ prepareMarkdownPageWithData,
12
+ renderMarkdown,
13
+ renderMarkdownWithData,
14
+ resolveDefines,
15
+ resolveDefinesWithData,
16
+ } from "./index.native.js";
@@ -0,0 +1,57 @@
1
+ /* auto-generated by NAPI-RS */
2
+ /* eslint-disable */
3
+
4
+ /**
5
+ * Which binding artifact the generated loader actually loaded: `'native'` for
6
+ * a native addon, otherwise the `platformArchABI` of the WASI flavor. Every
7
+ * flavor napi-rs can build is listed, because `NAPI_RS_NATIVE_LIBRARY_PATH`
8
+ * can point the loader at a WASI artifact this package does not build itself.
9
+ */
10
+ export declare const __napiBindingTarget:
11
+ "native" | "wasm32-wasi" | "wasm32-wasip1";
12
+
13
+ export interface BindingHeadingItem {
14
+ id: string;
15
+ text: string;
16
+ level: number;
17
+ }
18
+
19
+ export interface BindingPreparedMarkdownPage {
20
+ html: string;
21
+ headings: Array<BindingHeadingItem>;
22
+ }
23
+
24
+ export interface BindingRenderOptions {
25
+ internalOrigins?: Array<string>;
26
+ }
27
+
28
+ export declare function isMdrsPath(path: string): boolean;
29
+
30
+ export declare function prepareMarkdownPage(
31
+ markdown: string,
32
+ options?: BindingRenderOptions | undefined | null,
33
+ ): BindingPreparedMarkdownPage;
34
+
35
+ export declare function prepareMarkdownPageWithData(
36
+ markdown: string,
37
+ dataJson: string,
38
+ options?: BindingRenderOptions | undefined | null,
39
+ ): BindingPreparedMarkdownPage;
40
+
41
+ export declare function renderMarkdown(
42
+ markdown: string,
43
+ options?: BindingRenderOptions | undefined | null,
44
+ ): string;
45
+
46
+ export declare function renderMarkdownWithData(
47
+ markdown: string,
48
+ dataJson: string,
49
+ options?: BindingRenderOptions | undefined | null,
50
+ ): string;
51
+
52
+ export declare function resolveDefines(markdown: string): string;
53
+
54
+ export declare function resolveDefinesWithData(
55
+ markdown: string,
56
+ dataJson: string,
57
+ ): string;