@molecule/app-markdown 1.0.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,115 @@
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,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work.
38
+
39
+ "Derivative Works" shall mean any work, whether in Source or Object
40
+ form, that is based on (or derived from) the Work and for which the
41
+ editorial revisions, annotations, elaborations, or other modifications
42
+ represent, as a whole, an original work of authorship.
43
+
44
+ "Contribution" shall mean any work of authorship, including the
45
+ original version of the Work and any modifications or additions
46
+ to that Work, that is intentionally submitted to the Licensor for
47
+ inclusion in the Work by the copyright owner or by an individual or
48
+ Legal Entity authorized to submit on behalf of the copyright owner.
49
+
50
+ "Contributor" shall mean Licensor and any individual or Legal Entity
51
+ on behalf of whom a Contribution has been received by the Licensor and
52
+ subsequently incorporated within the Work.
53
+
54
+ 2. Grant of Copyright License. Subject to the terms and conditions of
55
+ this License, each Contributor hereby grants to You a perpetual,
56
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
57
+ copyright license to reproduce, prepare Derivative Works of,
58
+ publicly display, publicly perform, sublicense, and distribute the
59
+ Work and such Derivative Works in Source or Object form.
60
+
61
+ 3. Grant of Patent License. Subject to the terms and conditions of
62
+ this License, each Contributor hereby grants to You a perpetual,
63
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
64
+ patent license to make, have made, use, offer to sell, sell, import,
65
+ and otherwise transfer the Work.
66
+
67
+ 4. Redistribution. You may reproduce and distribute copies of the
68
+ Work or Derivative Works thereof in any medium, with or without
69
+ modifications, and in Source or Object form, provided that You
70
+ meet the following conditions:
71
+
72
+ (a) You must give any other recipients of the Work or
73
+ Derivative Works a copy of this License; and
74
+
75
+ (b) You must cause any modified files to carry prominent notices
76
+ stating that You changed the files; and
77
+
78
+ (c) You must retain, in the Source form of any Derivative Works
79
+ that You distribute, all copyright, patent, trademark, and
80
+ attribution notices from the Source form of the Work,
81
+ excluding those notices that do not pertain to any part of
82
+ the Derivative Works; and
83
+
84
+ (d) If the Work includes a "NOTICE" text file as part of its
85
+ distribution, then any Derivative Works that You distribute must
86
+ include a readable copy of the attribution notices contained
87
+ within such NOTICE file.
88
+
89
+ 5. Submission of Contributions.
90
+
91
+ 6. Trademarks. This License does not grant permission to use the trade
92
+ names, trademarks, service marks, or product names of the Licensor.
93
+
94
+ 7. Disclaimer of Warranty. Unless required by applicable law or
95
+ agreed to in writing, Licensor provides the Work on an "AS IS" BASIS,
96
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND.
97
+
98
+ 8. Limitation of Liability. In no event and under no legal theory shall
99
+ any Contributor be liable to You for damages.
100
+
101
+ 9. Accepting Warranty or Additional Liability.
102
+
103
+ Copyright 2026 Molecule Dev, Inc.
104
+
105
+ Licensed under the Apache License, Version 2.0 (the "License");
106
+ you may not use this file except in compliance with the License.
107
+ You may obtain a copy of the License at
108
+
109
+ http://www.apache.org/licenses/LICENSE-2.0
110
+
111
+ Unless required by applicable law or agreed to in writing, software
112
+ distributed under the License is distributed on an "AS IS" BASIS,
113
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
114
+ See the License for the specific language governing permissions and
115
+ limitations under the License.
@@ -0,0 +1,64 @@
1
+ /**
2
+ * Markdown rendering core interface for molecule.dev.
3
+ *
4
+ * Provides a standardized API for rendering markdown content into HTML,
5
+ * with support for GFM and table of contents extraction.
6
+ * Bond a provider (e.g. `@molecule/app-markdown-react-markdown`) to supply
7
+ * the concrete implementation.
8
+ *
9
+ * @example
10
+ * ```typescript
11
+ * import { requireProvider, setProvider } from '@molecule/app-markdown'
12
+ * import { provider } from '@molecule/app-markdown-react-markdown'
13
+ *
14
+ * setProvider(provider) // once, at startup (bonds.ts)
15
+ *
16
+ * const result = requireProvider().render('# Hello World', { gfm: true })
17
+ * console.log(result.html) // sanitized HTML string
18
+ * ```
19
+ *
20
+ * @remarks
21
+ * - **Wire a bond at startup** — {@link requireProvider} throws until
22
+ * `setProvider(provider)` has been called.
23
+ * - **`sanitize` defaults to `true` and is the XSS gate.** The result is an
24
+ * HTML STRING you inject via your framework's raw-HTML mechanism — that is
25
+ * only safe because it was sanitized. NEVER pass `sanitize: false` for
26
+ * user-supplied or model-generated markdown (chat replies, comments, notes);
27
+ * reserve it for fully trusted, app-authored content.
28
+ * - Options are per-call (`gfm`, `breaks`, `linkTarget`); `result.toc` carries
29
+ * extracted headings when the provider supports it. Syntax highlighting is a
30
+ * provider concern — e.g. the react-markdown bond wires a rehype highlighter
31
+ * via its `rehypePlugins` config rather than a generic option.
32
+ *
33
+ * @e2e
34
+ * Integration checklist — drive the real UI (live preview, no mocks), adapt
35
+ * each item to this app's actual screens/flows, and check every box off one
36
+ * by one. A box you can't check is an integration bug to fix — not a skip:
37
+ * - [ ] Common markdown renders as real HTML wherever the app shows it (chat
38
+ * reply, comment, note, README preview): `#`..`######` become `<h1>`..`<h6>`,
39
+ * `**bold**` a `<strong>`, `*italic*` an `<em>`, `-`/`1.` lists become
40
+ * `<ul>`/`<ol>` of `<li>`, `[text](url)` an `<a>` anchor, and a fenced code
41
+ * block a `<pre><code>` — not the raw `*`/backticks shown as literal text.
42
+ * - [ ] GFM extras render when enabled (`gfm`, default on): a pipe table
43
+ * `| a | b |` becomes a real `<table>` with header + rows, and `![alt](src)`
44
+ * an `<img>`.
45
+ * - [ ] The output tracks the source: editing the markdown updates the preview
46
+ * live — change a heading's text and its `<h#>` updates; add a list item and
47
+ * a new `<li>` appears. No stale or one-shot render.
48
+ * - [ ] SECURITY (XSS) — user- or model-supplied markdown is sanitized
49
+ * (`sanitize`, default on, the XSS gate): markdown containing a raw
50
+ * `<script>alert(1)</script>`, an `<img src=x onerror=alert(1)>`, or a
51
+ * `[click](javascript:alert(1))` link must NOT execute and must NOT produce
52
+ * active markup — the script is stripped, the `onerror` is gone, and the
53
+ * link's `href` is neutralized. Verify in the browser: no alert fires, and
54
+ * DevTools shows no `<script>`, `onerror`, or `javascript:` in the rendered
55
+ * DOM. Never render untrusted content with `sanitize: false`.
56
+ * - [ ] Malformed markdown degrades gracefully — an unclosed `**`, a broken
57
+ * `[link](`, or a half-open code fence renders as readable text and never
58
+ * throws, blanks the view, or breaks the surrounding page.
59
+ *
60
+ * @module
61
+ */
62
+ export * from './provider.js';
63
+ export * from './types.js';
64
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4DG;AAEH,cAAc,eAAe,CAAA;AAC7B,cAAc,YAAY,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,63 @@
1
+ /**
2
+ * Markdown rendering core interface for molecule.dev.
3
+ *
4
+ * Provides a standardized API for rendering markdown content into HTML,
5
+ * with support for GFM and table of contents extraction.
6
+ * Bond a provider (e.g. `@molecule/app-markdown-react-markdown`) to supply
7
+ * the concrete implementation.
8
+ *
9
+ * @example
10
+ * ```typescript
11
+ * import { requireProvider, setProvider } from '@molecule/app-markdown'
12
+ * import { provider } from '@molecule/app-markdown-react-markdown'
13
+ *
14
+ * setProvider(provider) // once, at startup (bonds.ts)
15
+ *
16
+ * const result = requireProvider().render('# Hello World', { gfm: true })
17
+ * console.log(result.html) // sanitized HTML string
18
+ * ```
19
+ *
20
+ * @remarks
21
+ * - **Wire a bond at startup** — {@link requireProvider} throws until
22
+ * `setProvider(provider)` has been called.
23
+ * - **`sanitize` defaults to `true` and is the XSS gate.** The result is an
24
+ * HTML STRING you inject via your framework's raw-HTML mechanism — that is
25
+ * only safe because it was sanitized. NEVER pass `sanitize: false` for
26
+ * user-supplied or model-generated markdown (chat replies, comments, notes);
27
+ * reserve it for fully trusted, app-authored content.
28
+ * - Options are per-call (`gfm`, `breaks`, `linkTarget`); `result.toc` carries
29
+ * extracted headings when the provider supports it. Syntax highlighting is a
30
+ * provider concern — e.g. the react-markdown bond wires a rehype highlighter
31
+ * via its `rehypePlugins` config rather than a generic option.
32
+ *
33
+ * @e2e
34
+ * Integration checklist — drive the real UI (live preview, no mocks), adapt
35
+ * each item to this app's actual screens/flows, and check every box off one
36
+ * by one. A box you can't check is an integration bug to fix — not a skip:
37
+ * - [ ] Common markdown renders as real HTML wherever the app shows it (chat
38
+ * reply, comment, note, README preview): `#`..`######` become `<h1>`..`<h6>`,
39
+ * `**bold**` a `<strong>`, `*italic*` an `<em>`, `-`/`1.` lists become
40
+ * `<ul>`/`<ol>` of `<li>`, `[text](url)` an `<a>` anchor, and a fenced code
41
+ * block a `<pre><code>` — not the raw `*`/backticks shown as literal text.
42
+ * - [ ] GFM extras render when enabled (`gfm`, default on): a pipe table
43
+ * `| a | b |` becomes a real `<table>` with header + rows, and `![alt](src)`
44
+ * an `<img>`.
45
+ * - [ ] The output tracks the source: editing the markdown updates the preview
46
+ * live — change a heading's text and its `<h#>` updates; add a list item and
47
+ * a new `<li>` appears. No stale or one-shot render.
48
+ * - [ ] SECURITY (XSS) — user- or model-supplied markdown is sanitized
49
+ * (`sanitize`, default on, the XSS gate): markdown containing a raw
50
+ * `<script>alert(1)</script>`, an `<img src=x onerror=alert(1)>`, or a
51
+ * `[click](javascript:alert(1))` link must NOT execute and must NOT produce
52
+ * active markup — the script is stripped, the `onerror` is gone, and the
53
+ * link's `href` is neutralized. Verify in the browser: no alert fires, and
54
+ * DevTools shows no `<script>`, `onerror`, or `javascript:` in the rendered
55
+ * DOM. Never render untrusted content with `sanitize: false`.
56
+ * - [ ] Malformed markdown degrades gracefully — an unclosed `**`, a broken
57
+ * `[link](`, or a half-open code fence renders as readable text and never
58
+ * throws, blanks the view, or breaks the surrounding page.
59
+ *
60
+ * @module
61
+ */
62
+ export * from './provider.js';
63
+ export * from './types.js';
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Markdown provider wiring.
3
+ *
4
+ * Delegates to the shared `@molecule/app-bond` registry under the `'markdown'`
5
+ * category, so `setProvider(provider)` and `bond('markdown', provider)` write
6
+ * the same slot — either bonds the provider. Bond packages call `setProvider()`
7
+ * during setup; application code calls `getProvider()` / `requireProvider()` at
8
+ * runtime.
9
+ *
10
+ * @module
11
+ */
12
+ import type { MarkdownProvider } from './types.js';
13
+ /**
14
+ * Registers a markdown provider as the active singleton.
15
+ *
16
+ * @param provider - The markdown provider implementation to bond.
17
+ */
18
+ export declare function setProvider(provider: MarkdownProvider): void;
19
+ /**
20
+ * Retrieves the bonded markdown provider, or `null` if none is bonded.
21
+ *
22
+ * @returns The active markdown provider, or `null`.
23
+ */
24
+ export declare function getProvider(): MarkdownProvider | null;
25
+ /**
26
+ * Checks whether a markdown provider has been bonded.
27
+ *
28
+ * @returns `true` if a markdown provider is available.
29
+ */
30
+ export declare function hasProvider(): boolean;
31
+ /**
32
+ * Retrieves the bonded markdown provider, throwing if none is configured.
33
+ *
34
+ * @returns The active markdown provider.
35
+ * @throws {Error} if no provider has been bonded.
36
+ */
37
+ export declare function requireProvider(): MarkdownProvider;
38
+ //# sourceMappingURL=provider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAIH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAIlD;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,QAAQ,EAAE,gBAAgB,GAAG,IAAI,CAE5D;AAED;;;;GAIG;AACH,wBAAgB,WAAW,IAAI,gBAAgB,GAAG,IAAI,CAErD;AAED;;;;GAIG;AACH,wBAAgB,WAAW,IAAI,OAAO,CAErC;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,IAAI,gBAAgB,CAMlD"}
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Markdown provider wiring.
3
+ *
4
+ * Delegates to the shared `@molecule/app-bond` registry under the `'markdown'`
5
+ * category, so `setProvider(provider)` and `bond('markdown', provider)` write
6
+ * the same slot — either bonds the provider. Bond packages call `setProvider()`
7
+ * during setup; application code calls `getProvider()` / `requireProvider()` at
8
+ * runtime.
9
+ *
10
+ * @module
11
+ */
12
+ import { bond, get, isBonded } from '@molecule/app-bond';
13
+ const BOND_TYPE = 'markdown';
14
+ /**
15
+ * Registers a markdown provider as the active singleton.
16
+ *
17
+ * @param provider - The markdown provider implementation to bond.
18
+ */
19
+ export function setProvider(provider) {
20
+ bond(BOND_TYPE, provider);
21
+ }
22
+ /**
23
+ * Retrieves the bonded markdown provider, or `null` if none is bonded.
24
+ *
25
+ * @returns The active markdown provider, or `null`.
26
+ */
27
+ export function getProvider() {
28
+ return get(BOND_TYPE) ?? null;
29
+ }
30
+ /**
31
+ * Checks whether a markdown provider has been bonded.
32
+ *
33
+ * @returns `true` if a markdown provider is available.
34
+ */
35
+ export function hasProvider() {
36
+ return isBonded(BOND_TYPE);
37
+ }
38
+ /**
39
+ * Retrieves the bonded markdown provider, throwing if none is configured.
40
+ *
41
+ * @returns The active markdown provider.
42
+ * @throws {Error} if no provider has been bonded.
43
+ */
44
+ export function requireProvider() {
45
+ const provider = get(BOND_TYPE);
46
+ if (!provider) {
47
+ throw new Error('Markdown provider not configured. Bond a markdown provider first.');
48
+ }
49
+ return provider;
50
+ }
@@ -0,0 +1,63 @@
1
+ /**
2
+ * Markdown rendering types for molecule.dev.
3
+ *
4
+ * Defines the provider interface and configuration options for
5
+ * rendering markdown content into HTML with optional features
6
+ * like GFM support and table of contents extraction.
7
+ *
8
+ * @module
9
+ */
10
+ /**
11
+ * Table of contents entry extracted from markdown headings.
12
+ */
13
+ export interface TocEntry {
14
+ /** Unique identifier for the heading (slug). */
15
+ id: string;
16
+ /** Text content of the heading. */
17
+ text: string;
18
+ /** Heading level (1-6). */
19
+ level: number;
20
+ }
21
+ /**
22
+ * Result of rendering markdown content.
23
+ */
24
+ export interface RenderedMarkdown {
25
+ /** The rendered HTML string. */
26
+ html: string;
27
+ /** Optional table of contents extracted from headings. */
28
+ toc?: TocEntry[];
29
+ }
30
+ /**
31
+ * Options for markdown rendering.
32
+ */
33
+ export interface MarkdownOptions {
34
+ /** Whether to sanitize the rendered HTML to prevent XSS. Defaults to `true`. */
35
+ sanitize?: boolean;
36
+ /** Whether to enable GitHub Flavored Markdown extensions. Defaults to `true`. */
37
+ gfm?: boolean;
38
+ /** Whether to convert line breaks to `<br>` elements. Defaults to `false`. */
39
+ breaks?: boolean;
40
+ /** Custom component overrides keyed by HTML element name. */
41
+ components?: Record<string, unknown>;
42
+ /** Target attribute for rendered links. */
43
+ linkTarget?: '_blank' | '_self';
44
+ }
45
+ /**
46
+ * Markdown rendering provider interface.
47
+ *
48
+ * All markdown providers must implement this interface to render
49
+ * markdown strings into HTML output with optional features.
50
+ */
51
+ export interface MarkdownProvider {
52
+ /** Provider name identifier. */
53
+ readonly name: string;
54
+ /**
55
+ * Renders a markdown string into HTML.
56
+ *
57
+ * @param markdown - The markdown source string to render.
58
+ * @param options - Optional rendering configuration.
59
+ * @returns The rendered HTML and optional table of contents.
60
+ */
61
+ render(markdown: string, options?: MarkdownOptions): RenderedMarkdown;
62
+ }
63
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH;;GAEG;AACH,MAAM,WAAW,QAAQ;IACvB,gDAAgD;IAChD,EAAE,EAAE,MAAM,CAAA;IAEV,mCAAmC;IACnC,IAAI,EAAE,MAAM,CAAA;IAEZ,2BAA2B;IAC3B,KAAK,EAAE,MAAM,CAAA;CACd;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,gCAAgC;IAChC,IAAI,EAAE,MAAM,CAAA;IAEZ,0DAA0D;IAC1D,GAAG,CAAC,EAAE,QAAQ,EAAE,CAAA;CACjB;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,gFAAgF;IAChF,QAAQ,CAAC,EAAE,OAAO,CAAA;IAElB,iFAAiF;IACjF,GAAG,CAAC,EAAE,OAAO,CAAA;IAEb,8EAA8E;IAC9E,MAAM,CAAC,EAAE,OAAO,CAAA;IAEhB,6DAA6D;IAC7D,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAEpC,2CAA2C;IAC3C,UAAU,CAAC,EAAE,QAAQ,GAAG,OAAO,CAAA;CAChC;AAED;;;;;GAKG;AACH,MAAM,WAAW,gBAAgB;IAC/B,gCAAgC;IAChC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IAErB;;;;;;OAMG;IACH,MAAM,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,eAAe,GAAG,gBAAgB,CAAA;CACtE"}
package/dist/types.js ADDED
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Markdown rendering types for molecule.dev.
3
+ *
4
+ * Defines the provider interface and configuration options for
5
+ * rendering markdown content into HTML with optional features
6
+ * like GFM support and table of contents extraction.
7
+ *
8
+ * @module
9
+ */
10
+ export {};
package/package.json ADDED
@@ -0,0 +1,36 @@
1
+ {
2
+ "name": "@molecule/app-markdown",
3
+ "version": "1.0.0",
4
+ "description": "",
5
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "scripts": {
9
+ "build": "tsc",
10
+ "test": "vitest run",
11
+ "test:watch": "vitest"
12
+ },
13
+ "exports": {
14
+ ".": {
15
+ "types": "./dist/index.d.ts",
16
+ "import": "./dist/index.js"
17
+ }
18
+ },
19
+ "files": [
20
+ "dist"
21
+ ],
22
+ "keywords": [
23
+ "molecule",
24
+ "markdown"
25
+ ],
26
+ "license": "Apache-2.0",
27
+ "peerDependencies": {
28
+ "@molecule/app-bond": "^1.0.0"
29
+ },
30
+ "devDependencies": {
31
+ "@molecule/app-bond": "1.0.0",
32
+ "@types/node": "26.1.2",
33
+ "typescript": "6.0.3",
34
+ "vitest": "4.1.10"
35
+ }
36
+ }