@riebeckite/plugin-marp 0.0.1

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,201 @@
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
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright Rerurate_514
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,101 @@
1
+ # @riebeckite/plugin-marp
2
+
3
+ Render `marp` code blocks as Marp slide decks at build time.
4
+
5
+ [日本語](./README_ja.md)
6
+
7
+ ## Usage
8
+
9
+ ```ts
10
+ import { defineConfig } from "@riebeckite/core";
11
+ import { marp } from "@riebeckite/plugin-marp";
12
+
13
+ export default defineConfig({
14
+ // ...
15
+ plugins: [
16
+ marp({
17
+ theme: "default",
18
+ allowHtml: true,
19
+ math: true,
20
+ caption: true,
21
+ }),
22
+ ],
23
+ });
24
+ ```
25
+
26
+ In a note, write a fenced code block whose info string is `marp`. Slides are separated by `---`, exactly like Marp. Setting the code block `title` renders a caption.
27
+
28
+ ````markdown
29
+ ```marp title="Intro deck"
30
+ # First slide
31
+
32
+ - a bullet
33
+
34
+ ---
35
+
36
+ # Second slide
37
+ ```
38
+ ````
39
+
40
+ ## How it renders
41
+
42
+ The plugin dynamically imports `@marp-team/marp-core` at build time and calls `Marp#render`. Marp Core never enters the client bundle. Each code block becomes:
43
+
44
+ ```html
45
+ <figure class="rb-marp" role="group" data-marp data-marp-slides="2">
46
+ <style>/* CSS generated at build time, scoped under .rb-marp */</style>
47
+ <figcaption class="rb-marp__caption">…</figcaption>
48
+ <div class="rb-marp__deck">
49
+ <svg data-marpit-svg>…</svg>
50
+ …
51
+ </div>
52
+ <details class="rb-marp__fallback">
53
+ <summary>Marp source</summary>
54
+ <pre><code>…original Markdown…</code></pre>
55
+ </details>
56
+ </figure>
57
+ ```
58
+
59
+ ### CSS scoping and inlining
60
+
61
+ Plugins cannot inject into `<head>`, so the CSS generated by Marp is inlined into the `<figure class="rb-marp">` as a `<style>` element. To keep it from leaking, the plugin:
62
+
63
+ - fixes Marp's `container` option to the `rb-marp__deck` class so every generated selector stays under that container;
64
+ - constrains the container selector to a `.rb-marp` descendant (for example `.rb-marp div.rb-marp__deck > svg > foreignObject > section`);
65
+ - removes the global `@page` rule and rewrites `html, body` inside `@media print` to `.rb-marp`.
66
+
67
+ When several decks on one page use the same theme their generated CSS is identical, so the `<style>` element is emitted only once.
68
+
69
+ ### Build-time rendering
70
+
71
+ - Rendering uses `script: false`, so a deck never ships client JavaScript. SVG slide sizing is handled by `style.css`;
72
+ - captions come from the code block `title`;
73
+ - `data-marp-slides` carries the slide count and `data-marp` marks the deck.
74
+
75
+ ## Options
76
+
77
+ | Option | Default | Description |
78
+ | --- | --- | --- |
79
+ | `theme` | `"default"` | A theme name registered in Marp Core (`"default"`, `"gaia"`, `"uncover"`, …) |
80
+ | `allowHtml` | `true` | Allow raw HTML in the Marp Markdown |
81
+ | `math` | `true` | Enable Marp math support |
82
+ | `inlineSVG` | unset | Marp's `inlineSVG` option. When unset, SVG slides are emitted |
83
+ | `caption` | `true` | Show the code block `title` as a caption |
84
+ | `className` | `"rb-marp"` | Wrapper class name |
85
+
86
+ An unknown theme falls back to the default theme and emits a diagnostic with `source: "@riebeckite/plugin-marp"`. A render failure keeps the original code block and emits the same kind of diagnostic.
87
+
88
+ ## Limitations
89
+
90
+ - No client-side slide editing or paging UI; this only produces static HTML/CSS at build time.
91
+ - Only themes registered in Marp Core are available; loading arbitrary theme CSS is not supported.
92
+ - `inlineSVG: false` emits bare `<section>` elements without the SVG wrapper, and the generated CSS changes to match that structure.
93
+
94
+ ## Exports
95
+
96
+ - `marp(options?)` / `marpPlugin(options?)` — plugin factory
97
+ - Types: `MarpOptions`, `MarpDeck`, `MarpBuildRenderResult`
98
+
99
+ ## See also
100
+
101
+ - [Plugin guide](../../docs/plugins_en.md)
package/README_ja.md ADDED
@@ -0,0 +1,101 @@
1
+ # @riebeckite/plugin-marp
2
+
3
+ `marp` コードブロックを Marp のスライドデッキとしてビルド時に描画するプラグインです。
4
+
5
+ [English](./README.md)
6
+
7
+ ## 設定する
8
+
9
+ ```ts
10
+ import { defineConfig } from "@riebeckite/core";
11
+ import { marp } from "@riebeckite/plugin-marp";
12
+
13
+ export default defineConfig({
14
+ // ...
15
+ plugins: [
16
+ marp({
17
+ theme: "default",
18
+ allowHtml: true,
19
+ math: true,
20
+ caption: true,
21
+ }),
22
+ ],
23
+ });
24
+ ```
25
+
26
+ ノートでは、情報文字列に `marp` を付けたコードブロックを書きます。スライドの区切りは Marp と同じく `---` です。コードブロックの `title` を付けるとキャプションになります。
27
+
28
+ ````markdown
29
+ ```marp title="導入スライド"
30
+ # 1 枚目のスライド
31
+
32
+ - 箇条書き
33
+
34
+ ---
35
+
36
+ # 2 枚目のスライド
37
+ ```
38
+ ````
39
+
40
+ ## どのように描画されるか
41
+
42
+ `@marp-team/marp-core` をビルド時に動的 import して `Marp#render` を呼び出します。Marp Core はクライアントバンドルには含まれません。1 つのコードブロックは次の HTML に置き換わります。
43
+
44
+ ```html
45
+ <figure class="rb-marp" role="group" data-marp data-marp-slides="2">
46
+ <style>/* ビルド時に生成し、.rb-marp 配下へスコープした CSS */</style>
47
+ <figcaption class="rb-marp__caption">…</figcaption>
48
+ <div class="rb-marp__deck">
49
+ <svg data-marpit-svg>…</svg>
50
+ …
51
+ </div>
52
+ <details class="rb-marp__fallback">
53
+ <summary>Marp source</summary>
54
+ <pre><code>…元の Markdown…</code></pre>
55
+ </details>
56
+ </figure>
57
+ ```
58
+
59
+ ### 生成 CSS のスコープとインライン化
60
+
61
+ プラグインは `<head>` へ注入できないため、Marp が生成した CSS は `<figure class="rb-marp">` の中へ `<style>` 要素としてインライン展開します。漏れを防ぐため次の処理を行います。
62
+
63
+ - Marp の `container` オプションでデッキのコンテナクラスを `rb-marp__deck` に固定し、生成 CSS の全セレクタがそのコンテナ配下に来るようにする
64
+ - コンテナセレクタを `.rb-marp` の子孫に限定する(例: `.rb-marp div.rb-marp__deck > svg > foreignObject > section`)
65
+ - グローバルに漏れる `@page` ルールを削除し、`@media print` 内の `html, body` を `.rb-marp` に置き換える
66
+
67
+ 同じテーマのデッキが 1 ページに複数ある場合、生成 CSS が同一になるため `<style>` は 1 回だけ出力します。
68
+
69
+ ### ビルド時のレンダリング
70
+
71
+ - `script: false` でレンダリングするため、デッキにクライアントスクリプトは含まれません。SVG スライドのサイズは `style.css` 側で調整します
72
+ - キャプションはコードブロックの `title` から取得します
73
+ - `data-marp-slides` にスライド枚数、`data-marp` にデッキであることを示す属性を付けます
74
+
75
+ ## オプション
76
+
77
+ | 項目 | 既定値 | 説明 |
78
+ | --- | --- | --- |
79
+ | `theme` | `"default"` | Marp Core に登録済みのテーマ名(`"default"`、`"gaia"`、`"uncover"` など) |
80
+ | `allowHtml` | `true` | Marp Markdown 内の生 HTML を許可する |
81
+ | `math` | `true` | Marp の数式サポートを有効にする |
82
+ | `inlineSVG` | 未指定 | Marp の `inlineSVG` オプション。未指定なら SVG スライドを出力する |
83
+ | `caption` | `true` | コードブロックの `title` をキャプションとして表示する |
84
+ | `className` | `"rb-marp"` | ラッパー要素のクラス名 |
85
+
86
+ 存在しないテーマを指定した場合は既定テーマへフォールバックし、`@riebeckite/plugin-marp` を `source` とする診断を出します。描画自体に失敗した場合は元のコードブロックを残し、同じく診断を出します。
87
+
88
+ ## 制約
89
+
90
+ - クライアント側でのスライド編集やページ送り UI は提供しません。ビルド時に静的な HTML/CSS を生成するだけです
91
+ - 利用できるテーマは Marp Core に登録済みのものに限られます。任意のテーマ CSS の読み込みには対応していません
92
+ - `inlineSVG: false` を指定すると SVG ラッパーなしの `<section>` を出力します。生成 CSS もその構造に合わせて変わります
93
+
94
+ ## 主なエクスポート
95
+
96
+ - `marp(options?)` / `marpPlugin(options?)`: プラグインを作成する
97
+ - 型: `MarpOptions`、`MarpDeck`、`MarpBuildRenderResult`
98
+
99
+ ## 関連資料
100
+
101
+ - [プラグインシステム](../../../docs/ja/plugin-system.md)
@@ -0,0 +1,11 @@
1
+ import type { MarpOptions } from "./src/types.js";
2
+ export type { MarpBuildRenderResult, MarpDeck, MarpOptions, } from "./src/types.js";
3
+ /**
4
+ * Renders ` ```marp ` code blocks as static Marp slide decks at build time.
5
+ *
6
+ * Marp Core is loaded through a dynamic import inside the HTML pipeline, so it
7
+ * never becomes part of the client bundle.
8
+ */
9
+ export declare function marp(options?: MarpOptions): import("@riebeckite/core").RiebeckitePlugin<MarpOptions>;
10
+ /** Alias matching the `*Plugin` naming used by other Riebeckite plugins. */
11
+ export declare const marpPlugin: typeof marp;
package/dist/index.js ADDED
@@ -0,0 +1,350 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropNames = Object.getOwnPropertyNames;
3
+ var __esm = (fn, res, err) => function __init() {
4
+ if (err) throw err[0];
5
+ try {
6
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
7
+ } catch (e) {
8
+ throw err = [e], e;
9
+ }
10
+ };
11
+ var __export = (target, all) => {
12
+ for (var name in all)
13
+ __defProp(target, name, { get: all[name], enumerable: true });
14
+ };
15
+
16
+ // src/css.ts
17
+ function scopeMarpCss(css, wrapperClass, deckClass) {
18
+ const containerSelector = `div.${deckClass}`;
19
+ const wrapperSelector = `.${wrapperClass}`;
20
+ const scoped = css.split(containerSelector).join(`${wrapperSelector} ${containerSelector}`).split(PRINT_GLOBAL_SELECTOR).join(wrapperSelector);
21
+ return removeAtRule(scoped, "@page");
22
+ }
23
+ function removeAtRule(css, atRuleName) {
24
+ const start = css.indexOf(atRuleName);
25
+ if (start === -1) return css;
26
+ const brace = css.indexOf("{", start);
27
+ if (brace === -1) return css;
28
+ let depth = 0;
29
+ let end = brace;
30
+ for (; end < css.length; end += 1) {
31
+ if (css[end] === "{") depth += 1;
32
+ else if (css[end] === "}") {
33
+ depth -= 1;
34
+ if (depth === 0) {
35
+ end += 1;
36
+ break;
37
+ }
38
+ }
39
+ }
40
+ return `${css.slice(0, start)}${css.slice(end)}`;
41
+ }
42
+ var PRINT_GLOBAL_SELECTOR;
43
+ var init_css = __esm({
44
+ "src/css.ts"() {
45
+ PRINT_GLOBAL_SELECTOR = "html, body";
46
+ }
47
+ });
48
+
49
+ // src/hast.ts
50
+ function visitElements(node, visitor, parent, index) {
51
+ if (isElementNode(node)) visitor(node, parent, index);
52
+ for (const [childIndex, child] of [...getChildren(node)].entries()) {
53
+ visitElements(
54
+ child,
55
+ visitor,
56
+ hasChildren(node) ? node : parent,
57
+ childIndex
58
+ );
59
+ }
60
+ }
61
+ function element(tagName, properties = {}, children = []) {
62
+ return { type: "element", tagName, properties, children };
63
+ }
64
+ function text(value) {
65
+ return { type: "text", value };
66
+ }
67
+ function raw(value) {
68
+ return { type: "raw", value };
69
+ }
70
+ function getTextContent(node) {
71
+ if (node.type === "text" && "value" in node && typeof node.value === "string") {
72
+ return node.value;
73
+ }
74
+ return getChildren(node).map(getTextContent).join("");
75
+ }
76
+ function getStringProperty(node, key) {
77
+ const value = node.properties?.[key];
78
+ if (typeof value === "string") return value;
79
+ if (Array.isArray(value)) return value.join(" ");
80
+ return null;
81
+ }
82
+ function hasClass(node, className) {
83
+ const value = node.properties?.className;
84
+ const classes = Array.isArray(value) ? value.map(String) : typeof value === "string" ? value.split(/\s+/) : [];
85
+ return classes.includes(className);
86
+ }
87
+ function isElementNode(node) {
88
+ return node.type === "element";
89
+ }
90
+ function hasChildren(node) {
91
+ return Array.isArray(node.children);
92
+ }
93
+ function getChildren(node) {
94
+ const children = node.children;
95
+ return Array.isArray(children) ? children : [];
96
+ }
97
+ var init_hast = __esm({
98
+ "src/hast.ts"() {
99
+ }
100
+ });
101
+
102
+ // src/render.ts
103
+ async function renderMarpDeck(markdown, request) {
104
+ try {
105
+ const Marp = await loadMarpCore();
106
+ const marpOptions = {
107
+ html: request.allowHtml,
108
+ math: request.math,
109
+ // Slides are emitted as static HTML: no client script is required.
110
+ script: false,
111
+ minifyCSS: true,
112
+ container: { tag: "div", class: request.deckClassName }
113
+ };
114
+ if (request.inlineSVG !== void 0) {
115
+ marpOptions.inlineSVG = request.inlineSVG;
116
+ }
117
+ const marp2 = new Marp(marpOptions);
118
+ let warning;
119
+ if (request.theme && request.theme !== DEFAULT_THEME) {
120
+ const theme = marp2.themeSet.get(request.theme);
121
+ if (theme) {
122
+ marp2.themeSet.default = theme;
123
+ } else {
124
+ warning = `Unknown Marp theme "${request.theme}"; using the default theme.`;
125
+ }
126
+ }
127
+ const { html, css } = marp2.render(markdown);
128
+ return {
129
+ ok: true,
130
+ deck: { html, css, slides: countSlides(html) },
131
+ ...warning === void 0 ? {} : { warning }
132
+ };
133
+ } catch (error) {
134
+ return { ok: false, message: formatError(error) };
135
+ }
136
+ }
137
+ async function loadMarpCore() {
138
+ const module = await importMarpCore();
139
+ const Marp = module.Marp ?? module.default;
140
+ if (typeof Marp !== "function") {
141
+ throw new Error("Marp Core did not expose a Marp constructor.");
142
+ }
143
+ return Marp;
144
+ }
145
+ function importMarpCore() {
146
+ const importModule = new Function(
147
+ "specifier",
148
+ "return import(specifier)"
149
+ );
150
+ return importModule("@marp-team/marp-core");
151
+ }
152
+ function countSlides(html) {
153
+ const slides = html.match(/data-marpit-svg/g);
154
+ if (slides) return slides.length;
155
+ return html.match(/<section\b/g)?.length ?? 0;
156
+ }
157
+ function formatError(error) {
158
+ if (error instanceof Error) return error.message;
159
+ return String(error);
160
+ }
161
+ var DEFAULT_THEME;
162
+ var init_render = __esm({
163
+ "src/render.ts"() {
164
+ DEFAULT_THEME = "default";
165
+ }
166
+ });
167
+
168
+ // src/rehype.ts
169
+ var rehype_exports = {};
170
+ __export(rehype_exports, {
171
+ rehypeMarp: () => rehypeMarp
172
+ });
173
+ function rehypeMarp(options = {}) {
174
+ const className = normalizeClassName(options.className);
175
+ const deckClassName = `${className}__deck`;
176
+ return async (tree, file) => {
177
+ const blocks = [];
178
+ visitElements(tree, (node, parent, index) => {
179
+ if (!parent || index === void 0 || !isMarpCodeBlock(node)) return;
180
+ blocks.push({ parent, index, pre: node });
181
+ });
182
+ if (blocks.length === 0) return;
183
+ const emittedCss = /* @__PURE__ */ new Set();
184
+ for (const block of blocks) {
185
+ const code = findDirectChild(block.pre, "code");
186
+ const source = (code ? getTextContent(code) : getTextContent(block.pre)).trim();
187
+ const caption = options.caption === false ? null : extractCaption(block.pre, code);
188
+ const result = await renderMarpDeck(source, {
189
+ theme: options.theme?.trim() || "default",
190
+ allowHtml: options.allowHtml !== false,
191
+ math: options.math !== false,
192
+ inlineSVG: options.inlineSVG,
193
+ deckClassName
194
+ });
195
+ if (result.ok === false) {
196
+ reportDiagnostic(
197
+ file,
198
+ `Marp rendering failed: ${result.message}`,
199
+ "render-error"
200
+ );
201
+ console.warn(`[marp] rendering failed: ${result.message}`);
202
+ continue;
203
+ }
204
+ if (result.warning) {
205
+ reportDiagnostic(file, result.warning, "theme-fallback");
206
+ console.warn(`[marp] ${result.warning}`);
207
+ }
208
+ const scopedCss = scopeMarpCss(result.deck.css, className, deckClassName);
209
+ const includeCss = !emittedCss.has(scopedCss);
210
+ if (includeCss) emittedCss.add(scopedCss);
211
+ const parent = block.parent;
212
+ parent.children = parent.children ?? [];
213
+ parent.children[block.index] = buildFigure({
214
+ className,
215
+ deckClassName,
216
+ caption,
217
+ source,
218
+ slides: result.deck.slides,
219
+ deckHtml: result.deck.html,
220
+ scopedCss: includeCss ? scopedCss : null
221
+ });
222
+ }
223
+ };
224
+ }
225
+ function buildFigure(input) {
226
+ const children = [];
227
+ if (input.scopedCss) {
228
+ children.push(element("style", {}, [text(input.scopedCss)]));
229
+ }
230
+ if (input.caption) {
231
+ children.push(
232
+ element("figcaption", { className: `${input.className}__caption` }, [
233
+ text(input.caption)
234
+ ])
235
+ );
236
+ }
237
+ children.push(raw(input.deckHtml));
238
+ children.push(
239
+ element("details", { className: `${input.className}__fallback` }, [
240
+ element("summary", {}, [text("Marp source")]),
241
+ element("pre", {}, [element("code", {}, [text(input.source)])])
242
+ ])
243
+ );
244
+ return element(
245
+ "figure",
246
+ {
247
+ className: input.className,
248
+ role: "group",
249
+ ariaLabel: input.caption ?? "Marp slide deck",
250
+ dataMarp: true,
251
+ dataMarpSlides: String(input.slides)
252
+ },
253
+ children
254
+ );
255
+ }
256
+ function isMarpCodeBlock(node) {
257
+ if (node.tagName !== "pre") return false;
258
+ const code = findDirectChild(node, "code");
259
+ return Boolean(code && hasClass(code, LANGUAGE_CLASS));
260
+ }
261
+ function findDirectChild(node, tagName) {
262
+ return node.children?.find(
263
+ (child) => child.type === "element" && child.tagName === tagName
264
+ ) ?? null;
265
+ }
266
+ function extractCaption(pre, code) {
267
+ const title = getStringProperty(pre, "title") ?? getStringProperty(code ?? pre, "title");
268
+ return title?.trim() || null;
269
+ }
270
+ function normalizeClassName(value) {
271
+ return value?.trim() || DEFAULT_CLASS_NAME;
272
+ }
273
+ function reportDiagnostic(file, message, ruleId) {
274
+ const reporter = file?.message;
275
+ if (typeof reporter !== "function") return;
276
+ const diagnostic = reporter.call(file, message);
277
+ if (diagnostic && typeof diagnostic === "object") {
278
+ Object.assign(diagnostic, {
279
+ source: "@riebeckite/plugin-marp",
280
+ ruleId
281
+ });
282
+ }
283
+ }
284
+ var DEFAULT_CLASS_NAME, LANGUAGE_CLASS;
285
+ var init_rehype = __esm({
286
+ "src/rehype.ts"() {
287
+ init_css();
288
+ init_hast();
289
+ init_render();
290
+ DEFAULT_CLASS_NAME = "rb-marp";
291
+ LANGUAGE_CLASS = "language-marp";
292
+ }
293
+ });
294
+
295
+ // index.ts
296
+ import {
297
+ createStyleAsset,
298
+ definePlugin
299
+ } from "@riebeckite/core";
300
+ var CLASS_NAME_PATTERN = /^[A-Za-z][A-Za-z0-9_-]*$/;
301
+ function marp(options = {}) {
302
+ return definePlugin({
303
+ name: "marp",
304
+ order: -10,
305
+ options,
306
+ validateOptions: validateMarpOptions,
307
+ extendHtmlPipeline: (pipeline) => {
308
+ pipeline.use(rehypeMarpLazy, options);
309
+ },
310
+ assets: [createStyleAsset("marp")]
311
+ });
312
+ }
313
+ var marpPlugin = marp;
314
+ function validateMarpOptions(options) {
315
+ if (!options) return [];
316
+ const issues = [];
317
+ if (options.theme !== void 0) {
318
+ if (typeof options.theme !== "string" || options.theme.trim() === "") {
319
+ issues.push({
320
+ path: "theme",
321
+ message: 'Expected a non-empty theme name such as "default".'
322
+ });
323
+ }
324
+ }
325
+ for (const key of ["allowHtml", "math", "inlineSVG", "caption"]) {
326
+ if (options[key] !== void 0 && typeof options[key] !== "boolean") {
327
+ issues.push({ path: key, message: "Expected a boolean." });
328
+ }
329
+ }
330
+ if (options.className !== void 0) {
331
+ if (typeof options.className !== "string" || !CLASS_NAME_PATTERN.test(options.className.trim())) {
332
+ issues.push({
333
+ path: "className",
334
+ message: "Expected a CSS class name beginning with a letter (letters, digits, `_`, `-`)."
335
+ });
336
+ }
337
+ }
338
+ return issues;
339
+ }
340
+ function rehypeMarpLazy(options = {}) {
341
+ return async (tree, file) => {
342
+ const { rehypeMarp: rehypeMarp2 } = await Promise.resolve().then(() => (init_rehype(), rehype_exports));
343
+ const transformer = rehypeMarp2(options);
344
+ await transformer(tree, file);
345
+ };
346
+ }
347
+ export {
348
+ marp,
349
+ marpPlugin
350
+ };
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Scopes Marp Core's generated CSS so it can be inlined anywhere on a page
3
+ * without leaking.
4
+ *
5
+ * Marp renders every structural rule under the deck container class (set via
6
+ * the `container` Marp option), so the only globals left to fix are the
7
+ * `@page` rule and the `html, body` selector inside `@media print`. The deck
8
+ * container is additionally required to sit inside the wrapper class.
9
+ */
10
+ export declare function scopeMarpCss(css: string, wrapperClass: string, deckClass: string): string;
@@ -0,0 +1,8 @@
1
+ import type { ElementNode, HastNode, ParentNode, TextNode } from "./types.js";
2
+ export declare function visitElements(node: HastNode, visitor: (node: ElementNode, parent?: ParentNode, index?: number) => void, parent?: ParentNode, index?: number): void;
3
+ export declare function element(tagName: string, properties?: Record<string, unknown>, children?: HastNode[]): ElementNode;
4
+ export declare function text(value: string): TextNode;
5
+ export declare function raw(value: string): HastNode;
6
+ export declare function getTextContent(node: HastNode): string;
7
+ export declare function getStringProperty(node: ElementNode, key: string): string | null;
8
+ export declare function hasClass(node: ElementNode, className: string): boolean;
@@ -0,0 +1,2 @@
1
+ import type { HastNode, MarpOptions } from "./types.js";
2
+ export declare function rehypeMarp(options?: MarpOptions): (tree: HastNode, file: unknown) => Promise<void>;
@@ -0,0 +1,14 @@
1
+ import type { MarpBuildRenderResult } from "./types.js";
2
+ export type MarpRenderRequest = {
3
+ theme: string;
4
+ allowHtml: boolean;
5
+ math: boolean;
6
+ /** Only forwarded to Marp Core when the user set it explicitly. */
7
+ inlineSVG?: boolean;
8
+ deckClassName: string;
9
+ };
10
+ /**
11
+ * Explicit build-time boundary for the Marp renderer. Markdown/HTML pipeline
12
+ * code depends only on this contract, never on `@marp-team/marp-core` types.
13
+ */
14
+ export declare function renderMarpDeck(markdown: string, request: MarpRenderRequest): Promise<MarpBuildRenderResult>;
@@ -0,0 +1,52 @@
1
+ export type MarpOptions = {
2
+ /** Marp theme name registered in Marp Core (for example `"default"`, `"gaia"`, `"uncover"`). */
3
+ theme?: string;
4
+ /** Allow raw HTML inside the Marp Markdown (default `true`). */
5
+ allowHtml?: boolean;
6
+ /** Enable Marp math support (default `true`). */
7
+ math?: boolean;
8
+ /** Use inline SVG output for Marp slides when the renderer supports it. */
9
+ inlineSVG?: boolean;
10
+ /** Render the code block title as a caption (default `true`). */
11
+ caption?: boolean;
12
+ /** Wrapper class name (default `"rb-marp"`). */
13
+ className?: string;
14
+ };
15
+ export type MarpDeck = {
16
+ /** Rendered slide deck markup, including the deck container element. */
17
+ html: string;
18
+ /** Generated Marp CSS for the deck. */
19
+ css: string;
20
+ /** Number of rendered slides. */
21
+ slides: number;
22
+ };
23
+ export type MarpBuildRenderResult = {
24
+ ok: true;
25
+ deck: MarpDeck;
26
+ /** Non-fatal issue such as an unknown theme that fell back to default. */
27
+ warning?: string;
28
+ } | {
29
+ ok: false;
30
+ message: string;
31
+ };
32
+ export type ElementNode = {
33
+ type: string;
34
+ tagName?: string;
35
+ properties?: Record<string, unknown>;
36
+ children?: HastNode[];
37
+ };
38
+ export type ParentNode = HastNode & {
39
+ children?: HastNode[];
40
+ };
41
+ export type TextNode = {
42
+ type: "text";
43
+ value: string;
44
+ };
45
+ export type RawNode = {
46
+ type: "raw";
47
+ value: string;
48
+ };
49
+ export type HastNode = ElementNode | TextNode | RawNode | {
50
+ type: string;
51
+ [key: string]: unknown;
52
+ };
package/package.json ADDED
@@ -0,0 +1,56 @@
1
+ {
2
+ "name": "@riebeckite/plugin-marp",
3
+ "version": "0.0.1",
4
+ "license": "Apache-2.0",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js",
12
+ "source": "./index.ts",
13
+ "default": "./dist/index.js"
14
+ },
15
+ "./style.css": "./style.css"
16
+ },
17
+ "dependencies": {
18
+ "@marp-team/marp-core": "^4.4.0",
19
+ "@riebeckite/core": "0.0.1"
20
+ },
21
+ "publishConfig": {
22
+ "access": "public"
23
+ },
24
+ "files": [
25
+ "LICENSE",
26
+ "README.md",
27
+ "README_ja.md",
28
+ "dist",
29
+ "style.css"
30
+ ],
31
+ "repository": {
32
+ "type": "git",
33
+ "url": "https://github.com/Rerurate514/riebeckite.git",
34
+ "directory": "packages/plugins/marp"
35
+ },
36
+ "homepage": "https://github.com/Rerurate514/riebeckite#readme",
37
+ "bugs": {
38
+ "url": "https://github.com/Rerurate514/riebeckite/issues"
39
+ },
40
+ "description": "Build-time Marp slide deck rendering for Riebeckite.",
41
+ "keywords": [
42
+ "riebeckite",
43
+ "plugin",
44
+ "marp",
45
+ "slides"
46
+ ],
47
+ "engines": {
48
+ "node": "^20.19.0 || >=22.12.0"
49
+ },
50
+ "sideEffects": [
51
+ "./style.css"
52
+ ],
53
+ "scripts": {
54
+ "build": "node ../../../scripts/build_package.mjs"
55
+ }
56
+ }
package/style.css ADDED
@@ -0,0 +1,65 @@
1
+ .rb-marp {
2
+ --rr-marp-paper: var(--rb-color-paper, #ffffff);
3
+ --rr-marp-ink: var(--rb-color-ink, #000000);
4
+ --rr-marp-muted: var(--rb-color-muted, #69645c);
5
+ --rr-marp-rule: var(
6
+ --rb-color-border,
7
+ color-mix(in srgb, var(--rr-marp-ink) 18%, transparent)
8
+ );
9
+ margin: 2rem 0;
10
+ border: 1px solid var(--rr-marp-rule);
11
+ background: color-mix(in srgb, var(--rr-marp-paper) 97%, var(--rr-marp-ink));
12
+ color: var(--rr-marp-ink);
13
+ }
14
+
15
+ .rb-marp__caption {
16
+ padding: 0.625rem 0.75rem;
17
+ border-bottom: 1px solid var(--rr-marp-rule);
18
+ color: var(--rr-marp-muted);
19
+ font-size: 0.875rem;
20
+ }
21
+
22
+ .rb-marp__deck {
23
+ overflow: auto;
24
+ padding: 1rem;
25
+ }
26
+
27
+ /* Marp emits SVG slides without the runtime polyfill script, so the deck is
28
+ sized here instead. The generated slide CSS controls the content inside. */
29
+ .rb-marp__deck > svg[data-marpit-svg] {
30
+ display: block;
31
+ width: 100%;
32
+ max-width: 100%;
33
+ height: auto;
34
+ margin: 0 auto 1rem;
35
+ }
36
+
37
+ .rb-marp__deck > svg[data-marpit-svg]:last-child {
38
+ margin-bottom: 0;
39
+ }
40
+
41
+ .rb-marp__fallback {
42
+ border-top: 1px solid var(--rr-marp-rule);
43
+ color: var(--rr-marp-muted);
44
+ font-size: 0.8125rem;
45
+ }
46
+
47
+ .rb-marp__fallback summary {
48
+ cursor: pointer;
49
+ padding: 0.5rem 0.75rem;
50
+ }
51
+
52
+ .rb-marp__fallback pre {
53
+ overflow: auto;
54
+ margin: 0 1rem 0.75rem;
55
+ padding: 0.75rem;
56
+ border-top: 1px solid var(--rr-marp-rule);
57
+ color: var(--rr-marp-ink);
58
+ background: color-mix(in srgb, var(--rr-marp-ink) 6%, transparent);
59
+ }
60
+
61
+ html[data-theme="dark"] .rb-marp,
62
+ html.dark .rb-marp {
63
+ --rr-marp-paper: var(--rb-color-ink, #000000);
64
+ --rr-marp-ink: var(--rb-color-paper, #ffffff);
65
+ }