novelaid-markdown 0.2.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/README.md +6 -0
- package/dist/blank-line-ClJSvRAu.js +129 -0
- package/dist/esm-Psdhd_27.js +1293 -0
- package/dist/index.d.ts +85 -0
- package/dist/index.js +195 -0
- package/dist/index.umd.cjs +30 -0
- package/dist/lib-DWIu06lZ.js +99 -0
- package/dist/react-markdown-BXmDW998.js +4220 -0
- package/dist/rehype-raw-_yRr8ewB.js +5224 -0
- package/dist/remark-gfm-Cfc5YeEq.js +1890 -0
- package/package.json +56 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { default as default_2 } from 'react';
|
|
2
|
+
import { JSX } from 'react/jsx-runtime';
|
|
3
|
+
|
|
4
|
+
export declare const defaultProcessor: NovelaidMarkdownProcessor;
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* コードブロック・プレプロセッサ: 特定の言語のコードブロックを解析・変換するプラグイン
|
|
8
|
+
* 言語名、コード本体、解析済みの属性を受け取り、それらを更新して返す
|
|
9
|
+
*/
|
|
10
|
+
export declare interface MarkdownCodePreprocessor {
|
|
11
|
+
languages: string[];
|
|
12
|
+
preprocess: (args: {
|
|
13
|
+
language: string;
|
|
14
|
+
code: string;
|
|
15
|
+
attributes: Record<string, any>;
|
|
16
|
+
}) => {
|
|
17
|
+
language: string;
|
|
18
|
+
code: string;
|
|
19
|
+
attributes: Record<string, any>;
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* コードプロセッサ: 特定の言語のコードブロックをレンダリングするプラグイン
|
|
25
|
+
*/
|
|
26
|
+
export declare interface MarkdownCodeProcessor {
|
|
27
|
+
language: string;
|
|
28
|
+
component: default_2.ComponentType<{
|
|
29
|
+
value: string;
|
|
30
|
+
language?: string;
|
|
31
|
+
attributes?: Record<string, any>;
|
|
32
|
+
}>;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* マークダウンプラグインの定義
|
|
37
|
+
*/
|
|
38
|
+
export declare interface MarkdownPlugin {
|
|
39
|
+
name: string;
|
|
40
|
+
preprocessors?: MarkdownPreprocessor[];
|
|
41
|
+
codePreprocessors?: MarkdownCodePreprocessor[];
|
|
42
|
+
codeProcessors?: MarkdownCodeProcessor[];
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* プレプロセッサ: マークダウン解析前に文字列を変換するプラグイン
|
|
47
|
+
*/
|
|
48
|
+
export declare type MarkdownPreprocessor = (text: string) => string;
|
|
49
|
+
|
|
50
|
+
export declare function NovelaidMarkdown({ content, filePath, className, onLinkClick, }: NovelaidMarkdownProps): JSX.Element;
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* 日本語小説執筆向けに最適化されたマークダウンプロセッサ
|
|
54
|
+
*/
|
|
55
|
+
export declare class NovelaidMarkdownProcessor {
|
|
56
|
+
private registry;
|
|
57
|
+
constructor();
|
|
58
|
+
/**
|
|
59
|
+
* 追加のプラグインを登録
|
|
60
|
+
*/
|
|
61
|
+
registerPlugin(plugin: any): void;
|
|
62
|
+
/**
|
|
63
|
+
* マークダウン解析前の処理(プリプロセッサ)を実行
|
|
64
|
+
*/
|
|
65
|
+
preprocess(content: string): string;
|
|
66
|
+
/**
|
|
67
|
+
* コードブロックプレプロセッサを取得
|
|
68
|
+
*/
|
|
69
|
+
getCodePreprocessors(): MarkdownCodePreprocessor[];
|
|
70
|
+
/**
|
|
71
|
+
* コードブロックプロセッサを取得
|
|
72
|
+
*/
|
|
73
|
+
getCodeProcessors(): MarkdownCodeProcessor[];
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
declare interface NovelaidMarkdownProps {
|
|
77
|
+
content: string;
|
|
78
|
+
filePath?: string;
|
|
79
|
+
className?: string;
|
|
80
|
+
onLinkClick?: (url: string, options?: {
|
|
81
|
+
newTab?: boolean;
|
|
82
|
+
}) => void;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export { }
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
import e, { useEffect as t, useMemo as n, useState as r } from "react";
|
|
2
|
+
import { jsx as i, jsxs as a } from "react/jsx-runtime";
|
|
3
|
+
//#region src/registry.ts
|
|
4
|
+
var o = class e {
|
|
5
|
+
plugins = [];
|
|
6
|
+
register(e) {
|
|
7
|
+
this.plugins.push(e);
|
|
8
|
+
}
|
|
9
|
+
getPreprocessors() {
|
|
10
|
+
return this.plugins.flatMap((e) => e.preprocessors || []);
|
|
11
|
+
}
|
|
12
|
+
getCodePreprocessors() {
|
|
13
|
+
return this.plugins.flatMap((e) => e.codePreprocessors || []);
|
|
14
|
+
}
|
|
15
|
+
getCodeProcessors() {
|
|
16
|
+
return this.plugins.flatMap((e) => e.codeProcessors || []);
|
|
17
|
+
}
|
|
18
|
+
static getDefault() {
|
|
19
|
+
return new e();
|
|
20
|
+
}
|
|
21
|
+
}, s = {
|
|
22
|
+
RUBY_WITH_PIPE: /[||]([^||\n《》]+)《([^《》\n]+)》/g,
|
|
23
|
+
RUBY_WITHOUT_PIPE: /([々〇\u4e00-\u9fcf\u3400-\u4dbf]+)《([^《》\n]+)》/g,
|
|
24
|
+
BOUTEN: /《《([^《》\n]+)》》/g,
|
|
25
|
+
DIALOGUE: /「(.*?)」/g,
|
|
26
|
+
DIALOGUE_DOUBLE: /『(.*?)』/g,
|
|
27
|
+
FULL_WIDTH_SPACE: /\u3000/g
|
|
28
|
+
}, c = {
|
|
29
|
+
name: "novel-syntax",
|
|
30
|
+
preprocessors: [(e) => {
|
|
31
|
+
if (!e) return "";
|
|
32
|
+
let t = e;
|
|
33
|
+
return t = t.replace(s.RUBY_WITH_PIPE, "<ruby>$1<rt>$2</rt></ruby>"), t = t.replace(s.RUBY_WITHOUT_PIPE, "<ruby>$1<rt>$2</rt></ruby>"), t = t.replace(s.BOUTEN, "<span class=\"bouten\">$1</span>"), t;
|
|
34
|
+
}]
|
|
35
|
+
}, l = class {
|
|
36
|
+
registry;
|
|
37
|
+
constructor() {
|
|
38
|
+
this.registry = new o(), this.registry.register(c);
|
|
39
|
+
}
|
|
40
|
+
registerPlugin(e) {
|
|
41
|
+
this.registry.register(e);
|
|
42
|
+
}
|
|
43
|
+
preprocess(e) {
|
|
44
|
+
let t = e, n = this.registry.getPreprocessors();
|
|
45
|
+
for (let e of n) t = e(t);
|
|
46
|
+
return t;
|
|
47
|
+
}
|
|
48
|
+
getCodePreprocessors() {
|
|
49
|
+
return this.registry.getCodePreprocessors();
|
|
50
|
+
}
|
|
51
|
+
getCodeProcessors() {
|
|
52
|
+
return this.registry.getCodeProcessors();
|
|
53
|
+
}
|
|
54
|
+
}, u = new l();
|
|
55
|
+
//#endregion
|
|
56
|
+
//#region src/utils/attribute-parser.ts
|
|
57
|
+
function d(e) {
|
|
58
|
+
return e.replace(/-([a-z])/g, (e) => e[1].toUpperCase());
|
|
59
|
+
}
|
|
60
|
+
function f(e) {
|
|
61
|
+
let t = {};
|
|
62
|
+
if (!e) return t;
|
|
63
|
+
let n = e.trim();
|
|
64
|
+
n.startsWith("{") && n.endsWith("}") ? n = n.substring(1, n.length - 1).trim() : n.startsWith("{") && (n = n.substring(1).trim());
|
|
65
|
+
let r = /([a-zA-Z0-9_-]+)(?:=([^"'\r\n\t ,{}]+|"(?:\\"|[^"])*"|'(?:\\'|[^'])*'))?/g, i;
|
|
66
|
+
for (; (i = r.exec(n)) !== null;) {
|
|
67
|
+
let e = i[1], n = i[2], r = d(e);
|
|
68
|
+
n === void 0 ? t[r] = !0 : ((n.startsWith("\"") && n.endsWith("\"") || n.startsWith("'") && n.endsWith("'")) && (n = n.substring(1, n.length - 1)), (r === "width" || r === "height") && /^\d+$/.test(n) && (n = `${n}px`), t[r] = n);
|
|
69
|
+
}
|
|
70
|
+
return t;
|
|
71
|
+
}
|
|
72
|
+
//#endregion
|
|
73
|
+
//#region src/renderer/NovelaidMarkdown.tsx
|
|
74
|
+
function p({ src: e, alt: t, filePath: n, title: r }) {
|
|
75
|
+
let a = e, o = t, s, c;
|
|
76
|
+
if (o && o.includes("|")) {
|
|
77
|
+
let e = o.lastIndexOf("|"), t = o.substring(e + 1).trim();
|
|
78
|
+
if (/^\d+$/.test(t)) s = parseInt(t, 10), o = o.substring(0, e);
|
|
79
|
+
else if (/^\d+x\d+$/.test(t)) {
|
|
80
|
+
let [n, r] = t.split("x");
|
|
81
|
+
s = parseInt(n, 10), c = parseInt(r, 10), o = o.substring(0, e);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
if (e && !e.startsWith("http") && !e.startsWith("data:") && !e.startsWith("nvfs:") && n) try {
|
|
85
|
+
let t = decodeURIComponent(e), r = t.startsWith("/") || /^[a-zA-Z]:/.test(t), i = t;
|
|
86
|
+
r || (i = `${n.replace(/[\\/][^\\/]+$/, "")}${n.includes("\\") ? "\\" : "/"}${t}`), a = `nvfs://local/${i.replace(/\\/g, "/").split("/").map((e) => encodeURIComponent(e)).join("/")}`;
|
|
87
|
+
} catch (e) {
|
|
88
|
+
console.error("Failed to resolve image path synchronously:", e);
|
|
89
|
+
}
|
|
90
|
+
return /* @__PURE__ */ i("img", {
|
|
91
|
+
src: a,
|
|
92
|
+
alt: o,
|
|
93
|
+
title: r,
|
|
94
|
+
width: s,
|
|
95
|
+
height: c
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
var m = class extends e.Component {
|
|
99
|
+
constructor(e) {
|
|
100
|
+
super(e), this.state = { hasError: !1 };
|
|
101
|
+
}
|
|
102
|
+
static getDerivedStateFromError() {
|
|
103
|
+
return { hasError: !0 };
|
|
104
|
+
}
|
|
105
|
+
componentDidCatch(e, t) {
|
|
106
|
+
console.group("Markdown Rendering Error"), console.log(t), console.error("Error:", e), console.error("File Path:", this.props.filePath), console.groupCollapsed("Original Content"), console.log(this.props.content), console.groupEnd(), console.groupEnd();
|
|
107
|
+
}
|
|
108
|
+
render() {
|
|
109
|
+
return this.state.hasError ? /* @__PURE__ */ a("div", {
|
|
110
|
+
className: "markdown-error-state",
|
|
111
|
+
style: {
|
|
112
|
+
padding: "20px",
|
|
113
|
+
border: "1px solid #f44336",
|
|
114
|
+
backgroundColor: "rgba(244, 67, 54, 0.1)",
|
|
115
|
+
borderRadius: "4px"
|
|
116
|
+
},
|
|
117
|
+
children: [/* @__PURE__ */ i("h3", { children: "Markdown Rendering Error" }), /* @__PURE__ */ i("p", { children: "プレビューのレンダリング中にエラーが発生しました。詳細は開発者ツールのコンソールを確認してください。" })]
|
|
118
|
+
}) : this.props.children;
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
function h({ content: e, filePath: a, className: o = "", onLinkClick: s }) {
|
|
122
|
+
let [c, l] = r(null), [d, h] = r(null), [g, _] = r(null);
|
|
123
|
+
t(() => {
|
|
124
|
+
Promise.all([
|
|
125
|
+
import("./react-markdown-BXmDW998.js"),
|
|
126
|
+
import("./remark-gfm-Cfc5YeEq.js"),
|
|
127
|
+
import("./rehype-raw-_yRr8ewB.js")
|
|
128
|
+
]).then(([e, t, n]) => (l(() => e.default), h(() => t.default), _(() => n.default), null)).catch((e) => {
|
|
129
|
+
console.error("Failed to load markdown modules:", e);
|
|
130
|
+
});
|
|
131
|
+
}, []);
|
|
132
|
+
let v = n(() => ({
|
|
133
|
+
img: (e) => /* @__PURE__ */ i(p, {
|
|
134
|
+
...e,
|
|
135
|
+
filePath: a
|
|
136
|
+
}),
|
|
137
|
+
a: (e) => /* @__PURE__ */ i("a", {
|
|
138
|
+
...e,
|
|
139
|
+
onClick: (t) => {
|
|
140
|
+
s && e.href && (t.preventDefault(), s(e.href, { newTab: !1 }));
|
|
141
|
+
},
|
|
142
|
+
onAuxClick: (t) => {
|
|
143
|
+
t.button === 1 && s && e.href && (t.preventDefault(), s(e.href, { newTab: !0 }));
|
|
144
|
+
}
|
|
145
|
+
}),
|
|
146
|
+
code: (e) => {
|
|
147
|
+
let { children: t, className: n, node: r, ...a } = e, o = /language-([^ \n\r\t]+)/.exec(n || ""), s = o ? o[1] : void 0, c = s, l = r?.meta || "";
|
|
148
|
+
if (s && s.includes("{")) {
|
|
149
|
+
let e = s.indexOf("{");
|
|
150
|
+
c = s.substring(0, e), l ||= s.substring(e);
|
|
151
|
+
}
|
|
152
|
+
let d = f(l), p = c || "", m = String(t).replace(/\n$/, ""), h = { ...d }, g = u.getCodePreprocessors();
|
|
153
|
+
for (let e of g) if (e.languages.includes(p) || e.languages.includes("*")) {
|
|
154
|
+
let t = e.preprocess({
|
|
155
|
+
language: p,
|
|
156
|
+
code: m,
|
|
157
|
+
attributes: h
|
|
158
|
+
});
|
|
159
|
+
p = t.language, m = t.code, h = t.attributes;
|
|
160
|
+
}
|
|
161
|
+
let _ = u.getCodeProcessors().find((e) => e.language === p);
|
|
162
|
+
if (_) {
|
|
163
|
+
let e = _.component;
|
|
164
|
+
return /* @__PURE__ */ i(e, {
|
|
165
|
+
value: m,
|
|
166
|
+
language: p,
|
|
167
|
+
attributes: h,
|
|
168
|
+
...a
|
|
169
|
+
}, m);
|
|
170
|
+
}
|
|
171
|
+
return /* @__PURE__ */ i("code", {
|
|
172
|
+
className: n,
|
|
173
|
+
...a,
|
|
174
|
+
children: t
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
}), [a, s]);
|
|
178
|
+
if (!c || !d || !g) return /* @__PURE__ */ i("div", { children: "Loading preview..." });
|
|
179
|
+
let y = u.preprocess(e);
|
|
180
|
+
return /* @__PURE__ */ i("div", {
|
|
181
|
+
className: o,
|
|
182
|
+
children: /* @__PURE__ */ i(m, {
|
|
183
|
+
content: y,
|
|
184
|
+
filePath: a,
|
|
185
|
+
children: /* @__PURE__ */ i(c, {
|
|
186
|
+
remarkPlugins: [d],
|
|
187
|
+
rehypePlugins: [g],
|
|
188
|
+
components: v,
|
|
189
|
+
children: y
|
|
190
|
+
})
|
|
191
|
+
})
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
//#endregion
|
|
195
|
+
export { h as NovelaidMarkdown, l as NovelaidMarkdownProcessor, u as defaultProcessor };
|