@diplodoc/notes-extension 0.0.0-stage → 0.1.0-transform5.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 +21 -0
- package/README.md +89 -2
- package/build/cjs/browser/index.d.ts +23 -0
- package/build/cjs/browser.js +317 -0
- package/build/cjs/browser.js.map +7 -0
- package/build/cjs/index.js +356 -0
- package/build/cjs/index.js.map +7 -0
- package/build/cjs/package.json +1 -0
- package/build/cjs/plugin/close.d.ts +7 -0
- package/build/cjs/plugin/const.d.ts +19 -0
- package/build/cjs/plugin/index.d.ts +18 -0
- package/build/cjs/plugin/plugin.d.ts +8 -0
- package/build/cjs/plugin/pure.d.ts +4 -0
- package/build/cjs/plugin/resources.d.ts +9 -0
- package/build/cjs/plugin/transform.d.ts +17 -0
- package/build/cjs/plugin/types.d.ts +35 -0
- package/build/cjs/plugin.js +265 -0
- package/build/cjs/plugin.js.map +7 -0
- package/build/cjs/runtime/index.d.ts +1 -0
- package/build/esm/browser/index.d.ts +23 -0
- package/build/esm/browser.js +289 -0
- package/build/esm/browser.js.map +7 -0
- package/build/esm/index.js +328 -0
- package/build/esm/index.js.map +7 -0
- package/build/esm/package.json +1 -0
- package/build/esm/plugin/close.d.ts +7 -0
- package/build/esm/plugin/const.d.ts +19 -0
- package/build/esm/plugin/index.d.ts +18 -0
- package/build/esm/plugin/plugin.d.ts +8 -0
- package/build/esm/plugin/pure.d.ts +4 -0
- package/build/esm/plugin/resources.d.ts +9 -0
- package/build/esm/plugin/transform.d.ts +17 -0
- package/build/esm/plugin/types.d.ts +35 -0
- package/build/esm/plugin.js +235 -0
- package/build/esm/plugin.js.map +7 -0
- package/build/esm/runtime/index.d.ts +1 -0
- package/build/runtime/index.cjs +1 -0
- package/build/runtime/index.css +55 -0
- package/build/runtime/index.d.ts +1 -0
- package/build/runtime/index.mjs +1 -0
- package/build/scss/_notes.scss +87 -0
- package/build/types/browser/index.d.ts +23 -0
- package/build/types/plugin/close.d.ts +7 -0
- package/build/types/plugin/const.d.ts +19 -0
- package/build/types/plugin/index.d.ts +18 -0
- package/build/types/plugin/plugin.d.ts +8 -0
- package/build/types/plugin/pure.d.ts +4 -0
- package/build/types/plugin/resources.d.ts +9 -0
- package/build/types/plugin/transform.d.ts +17 -0
- package/build/types/plugin/types.d.ts +35 -0
- package/build/types/runtime/index.d.ts +1 -0
- package/package.json +88 -4
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/plugin/pure.ts
|
|
21
|
+
var pure_exports = {};
|
|
22
|
+
__export(pure_exports, {
|
|
23
|
+
DEFAULT_LANG: () => DEFAULT_LANG,
|
|
24
|
+
TITLES: () => TITLES,
|
|
25
|
+
TokenType: () => TokenType,
|
|
26
|
+
createNotesPlugin: () => createNotesPlugin
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(pure_exports);
|
|
29
|
+
|
|
30
|
+
// src/plugin/close.ts
|
|
31
|
+
function createNestedCloseTokenIdxFactory(formatPath) {
|
|
32
|
+
const nestedCloseTokenIdxFactory = (tokenName, matchOpenToken2, matchCloseToken2) => (tokens, idx, path, log) => {
|
|
33
|
+
let level = 0;
|
|
34
|
+
let i = idx;
|
|
35
|
+
while (i < tokens.length) {
|
|
36
|
+
if (matchOpenToken2(tokens, i)) {
|
|
37
|
+
level++;
|
|
38
|
+
} else if (matchCloseToken2(tokens, i)) {
|
|
39
|
+
if (level === 0) {
|
|
40
|
+
return i;
|
|
41
|
+
}
|
|
42
|
+
level--;
|
|
43
|
+
}
|
|
44
|
+
i++;
|
|
45
|
+
}
|
|
46
|
+
log.error(`${tokenName} must be closed${path ? ` in ${formatPath(path)}` : ""}`);
|
|
47
|
+
return null;
|
|
48
|
+
};
|
|
49
|
+
return nestedCloseTokenIdxFactory;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// src/plugin/const.ts
|
|
53
|
+
var DEFAULT_LANG = "ru";
|
|
54
|
+
var TITLES = {
|
|
55
|
+
ru: {
|
|
56
|
+
info: "\u041F\u0440\u0438\u043C\u0435\u0447\u0430\u043D\u0438\u0435",
|
|
57
|
+
tip: "\u0421\u043E\u0432\u0435\u0442",
|
|
58
|
+
alert: "\u0412\u043D\u0438\u043C\u0430\u043D\u0438\u0435",
|
|
59
|
+
warning: "\u0412\u0430\u0436\u043D\u043E"
|
|
60
|
+
},
|
|
61
|
+
en: {
|
|
62
|
+
info: "Note",
|
|
63
|
+
tip: "Tip",
|
|
64
|
+
alert: "Alert",
|
|
65
|
+
warning: "Warning"
|
|
66
|
+
},
|
|
67
|
+
ar: {
|
|
68
|
+
info: "\u0645\u0644\u0627\u062D\u0638\u0629",
|
|
69
|
+
tip: "\u0646\u0635\u064A\u062D\u0629",
|
|
70
|
+
alert: "\u0627\u0646\u062A\u0628\u0627\u0647",
|
|
71
|
+
warning: "\u0647\u0627\u0645"
|
|
72
|
+
},
|
|
73
|
+
cs: {
|
|
74
|
+
info: "Pozn\xE1mka",
|
|
75
|
+
tip: "Tip",
|
|
76
|
+
alert: "Upozorn\u011Bn\xED",
|
|
77
|
+
warning: "Varov\xE1n\xED"
|
|
78
|
+
},
|
|
79
|
+
fr: {
|
|
80
|
+
info: "Remarque",
|
|
81
|
+
tip: "Astuce",
|
|
82
|
+
alert: "Alerte",
|
|
83
|
+
warning: "Avertissement"
|
|
84
|
+
},
|
|
85
|
+
es: {
|
|
86
|
+
info: "Nota",
|
|
87
|
+
tip: "Consejo",
|
|
88
|
+
alert: "Alerta",
|
|
89
|
+
warning: "Aviso"
|
|
90
|
+
},
|
|
91
|
+
he: {
|
|
92
|
+
info: "\u05DE\u05D9\u05D3\u05E2",
|
|
93
|
+
tip: "\u05D8\u05D9\u05E4",
|
|
94
|
+
alert: "\u05D4\u05EA\u05E8\u05D0\u05D4",
|
|
95
|
+
warning: "\u05D0\u05D6\u05D4\u05E8\u05D4"
|
|
96
|
+
},
|
|
97
|
+
bg: {
|
|
98
|
+
info: "\u0417\u0430\u0431\u0435\u043B\u0435\u0436\u043A\u0430",
|
|
99
|
+
tip: "\u0421\u044A\u0432\u0435\u0442",
|
|
100
|
+
alert: "\u0412\u043D\u0438\u043C\u0430\u043D\u0438\u0435",
|
|
101
|
+
warning: "\u0412\u0430\u0436\u043D\u043E"
|
|
102
|
+
},
|
|
103
|
+
et: {
|
|
104
|
+
info: "M\xE4rkus",
|
|
105
|
+
tip: "N\xF5uanne",
|
|
106
|
+
alert: "T\xE4helepanu",
|
|
107
|
+
warning: "T\xE4htis"
|
|
108
|
+
},
|
|
109
|
+
el: {
|
|
110
|
+
info: "\u03A3\u03B7\u03BC\u03B5\u03AF\u03C9\u03C3\u03B7",
|
|
111
|
+
tip: "\u03A3\u03C5\u03BC\u03B2\u03BF\u03C5\u03BB\u03AE",
|
|
112
|
+
alert: "\u03A0\u03C1\u03BF\u03C3\u03BF\u03C7\u03AE",
|
|
113
|
+
warning: "\u03A3\u03B7\u03BC\u03B1\u03BD\u03C4\u03B9\u03BA\u03CC"
|
|
114
|
+
},
|
|
115
|
+
pt: {
|
|
116
|
+
info: "Observa\xE7\xE3o",
|
|
117
|
+
tip: "Sugest\xE3o",
|
|
118
|
+
alert: "Aten\xE7\xE3o",
|
|
119
|
+
warning: "Importante"
|
|
120
|
+
},
|
|
121
|
+
zh: {
|
|
122
|
+
info: "\u5907\u6CE8",
|
|
123
|
+
tip: "\u63D0\u793A",
|
|
124
|
+
alert: "\u6CE8\u610F",
|
|
125
|
+
warning: "\u91CD\u8981"
|
|
126
|
+
},
|
|
127
|
+
"zh-tw": {
|
|
128
|
+
info: "\u5099\u6CE8",
|
|
129
|
+
tip: "\u63D0\u793A",
|
|
130
|
+
alert: "\u6CE8\u610F",
|
|
131
|
+
warning: "\u91CD\u8981"
|
|
132
|
+
},
|
|
133
|
+
kk: {
|
|
134
|
+
info: "\u0415\u0441\u043A\u0435\u0440\u0442\u0443",
|
|
135
|
+
tip: "\u041A\u0435\u04A3\u0435\u0441",
|
|
136
|
+
alert: "\u041D\u0430\u0437\u0430\u0440 \u0430\u0443\u0434\u0430\u0440\u044B\u04A3\u044B\u0437",
|
|
137
|
+
warning: "\u041C\u0430\u04A3\u044B\u0437\u0434\u044B"
|
|
138
|
+
},
|
|
139
|
+
tr: {
|
|
140
|
+
info: "Not",
|
|
141
|
+
tip: "\xD6neri",
|
|
142
|
+
alert: "Dikkat",
|
|
143
|
+
warning: "\xD6nemli"
|
|
144
|
+
},
|
|
145
|
+
uz: {
|
|
146
|
+
info: "Sharh",
|
|
147
|
+
tip: "Maslahat",
|
|
148
|
+
alert: "Diqqat",
|
|
149
|
+
warning: "Bu muhim"
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
var TokenType = {
|
|
153
|
+
Note: "yfm-note",
|
|
154
|
+
NoteOpen: "yfm_note_open",
|
|
155
|
+
NoteClose: "yfm_note_close",
|
|
156
|
+
NoteTitleOpen: "yfm_note_title_open",
|
|
157
|
+
NoteTitleClose: "yfm_note_title_close",
|
|
158
|
+
NoteContentOpen: "yfm_note_content_open",
|
|
159
|
+
NoteContentClose: "yfm_note_content_close"
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
// src/plugin/plugin.ts
|
|
163
|
+
var quietLogger = { warn: (_message) => {
|
|
164
|
+
}, error: (_message) => {
|
|
165
|
+
} };
|
|
166
|
+
var ALERT_RE = /^{% note (alert|info|tip|warning)\s*(?:"(.*?)")? %}$/;
|
|
167
|
+
var WRONG_NOTES = /^{% note (.*)%}/;
|
|
168
|
+
var matchCloseToken = (tokens, i) => {
|
|
169
|
+
return tokens[i].type === "paragraph_open" && tokens[i + 1].type === "inline" && tokens[i + 1].content.trim() === "{% endnote %}";
|
|
170
|
+
};
|
|
171
|
+
var titleDictionaries = new Map(Object.entries(TITLES));
|
|
172
|
+
function getTitle(type, lang) {
|
|
173
|
+
return (titleDictionaries.get(lang) ?? TITLES.ru)[type];
|
|
174
|
+
}
|
|
175
|
+
function matchOpenToken(tokens, i) {
|
|
176
|
+
return tokens[i].type === "paragraph_open" && tokens[i + 1].type === "inline" && tokens[i + 1].content.match(ALERT_RE);
|
|
177
|
+
}
|
|
178
|
+
function matchWrongNotes(tokens, i) {
|
|
179
|
+
return tokens[i].type === "paragraph_open" && tokens[i + 1].type === "inline" && tokens[i + 1].content.match(WRONG_NOTES);
|
|
180
|
+
}
|
|
181
|
+
function createNotesPlugin(formatPath = (path) => path, onNote) {
|
|
182
|
+
const findCloseTokenIdx = createNestedCloseTokenIdxFactory(formatPath)(
|
|
183
|
+
"Note",
|
|
184
|
+
matchOpenToken,
|
|
185
|
+
matchCloseToken
|
|
186
|
+
);
|
|
187
|
+
const index = (md, { lang = DEFAULT_LANG, notesAutotitle, path: optPath, log = quietLogger } = {}) => {
|
|
188
|
+
notesAutotitle = typeof notesAutotitle === "boolean" ? notesAutotitle : true;
|
|
189
|
+
const plugin = (state) => {
|
|
190
|
+
const { tokens, env } = state;
|
|
191
|
+
const path = typeof env.path === "string" && env.path ? env.path : optPath ?? "";
|
|
192
|
+
let i = 0;
|
|
193
|
+
while (i < tokens.length) {
|
|
194
|
+
const match = matchOpenToken(tokens, i);
|
|
195
|
+
if (match) {
|
|
196
|
+
const closeTokenIdx = findCloseTokenIdx(tokens, i + 2, path, log);
|
|
197
|
+
if (!closeTokenIdx) {
|
|
198
|
+
i += 3;
|
|
199
|
+
continue;
|
|
200
|
+
}
|
|
201
|
+
const type = match[1].toLowerCase();
|
|
202
|
+
const newOpenToken = new state.Token("yfm_note_open", "div", 1);
|
|
203
|
+
newOpenToken.attrSet("class", `yfm-note yfm-accent-${type}`);
|
|
204
|
+
newOpenToken.attrSet("note-type", type);
|
|
205
|
+
newOpenToken.map = tokens[i].map;
|
|
206
|
+
const closeTokenMap = tokens[closeTokenIdx].map;
|
|
207
|
+
if (closeTokenMap && newOpenToken.map) {
|
|
208
|
+
newOpenToken.map[1] = closeTokenMap[1];
|
|
209
|
+
}
|
|
210
|
+
const newCloseToken = new state.Token("yfm_note_close", "div", -1);
|
|
211
|
+
newCloseToken.map = tokens[closeTokenIdx].map;
|
|
212
|
+
const titleOpen = new state.Token("yfm_note_title_open", "p", 1);
|
|
213
|
+
titleOpen.attrSet("class", "yfm-note-title");
|
|
214
|
+
const autotitle = notesAutotitle ? getTitle(type, lang) : "";
|
|
215
|
+
const titleContent = match[2] === void 0 ? autotitle : match[2];
|
|
216
|
+
const titleInline = state.md.parseInline(titleContent, state.env)[0];
|
|
217
|
+
titleInline.map = null;
|
|
218
|
+
const titleClose = new state.Token("yfm_note_title_close", "p", -1);
|
|
219
|
+
titleOpen.block = true;
|
|
220
|
+
titleClose.block = true;
|
|
221
|
+
const contentOpen = new state.Token("yfm_note_content_open", "div", 1);
|
|
222
|
+
contentOpen.attrSet("class", "yfm-note-content");
|
|
223
|
+
const contentClose = new state.Token("yfm_note_content_close", "div", -1);
|
|
224
|
+
if (newOpenToken.map) {
|
|
225
|
+
contentOpen.map = [newOpenToken.map[0] + 2, newOpenToken.map[1] - 2];
|
|
226
|
+
}
|
|
227
|
+
const insideTokens = [newOpenToken];
|
|
228
|
+
if (titleInline.content) {
|
|
229
|
+
insideTokens.push(titleOpen, titleInline, titleClose);
|
|
230
|
+
}
|
|
231
|
+
insideTokens.push(
|
|
232
|
+
contentOpen,
|
|
233
|
+
...tokens.slice(i + 3, closeTokenIdx),
|
|
234
|
+
contentClose,
|
|
235
|
+
newCloseToken
|
|
236
|
+
);
|
|
237
|
+
tokens.splice(i, closeTokenIdx - i + 3, ...insideTokens);
|
|
238
|
+
onNote?.(env);
|
|
239
|
+
i++;
|
|
240
|
+
} else if (matchWrongNotes(tokens, i) && tokens[i + 1].content !== "{% endnote %}") {
|
|
241
|
+
log.warn(
|
|
242
|
+
`Incorrect syntax for notes${path ? `, file ${formatPath(path)}` : ""}`
|
|
243
|
+
);
|
|
244
|
+
i += 3;
|
|
245
|
+
} else {
|
|
246
|
+
i++;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
};
|
|
250
|
+
try {
|
|
251
|
+
md.core.ruler.before("curly_attributes", "notes", plugin);
|
|
252
|
+
} catch {
|
|
253
|
+
md.core.ruler.push("notes", plugin);
|
|
254
|
+
}
|
|
255
|
+
};
|
|
256
|
+
return index;
|
|
257
|
+
}
|
|
258
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
259
|
+
0 && (module.exports = {
|
|
260
|
+
DEFAULT_LANG,
|
|
261
|
+
TITLES,
|
|
262
|
+
TokenType,
|
|
263
|
+
createNotesPlugin
|
|
264
|
+
});
|
|
265
|
+
//# sourceMappingURL=plugin.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/plugin/pure.ts", "../../src/plugin/close.ts", "../../src/plugin/const.ts", "../../src/plugin/plugin.ts"],
|
|
4
|
+
"sourcesContent": ["export {createNotesPlugin} from './plugin.js';\nexport {TokenType, TITLES, DEFAULT_LANG} from './const.js';\nexport type {Lang} from './const.js';\nexport type {\n NoteParser,\n NoteState,\n NoteToken,\n NotesLogger,\n NotesOptions,\n NotesPlugin,\n} from './types.js';\n", "import type {MatchTokenFunction, NoteToken, NotesLogger} from './types.js';\n\n/**\n * Bind the existing close-token search to the host's path formatter.\n * @param formatPath - Plain browser or original terminal path formatting.\n * @returns The existing finite token-search factory.\n */\nexport function createNestedCloseTokenIdxFactory(formatPath: (path: string) => string) {\n const nestedCloseTokenIdxFactory =\n (\n tokenName: string,\n matchOpenToken: MatchTokenFunction,\n matchCloseToken: MatchTokenFunction,\n ) =>\n (tokens: NoteToken[], idx: number, path: string, log: NotesLogger) => {\n let level = 0;\n let i = idx;\n while (i < tokens.length) {\n if (matchOpenToken(tokens, i)) {\n level++;\n } else if (matchCloseToken(tokens, i)) {\n if (level === 0) {\n return i;\n }\n level--;\n }\n\n i++;\n }\n\n log.error(`${tokenName} must be closed${path ? ` in ${formatPath(path)}` : ''}`);\n\n return null;\n };\n\n return nestedCloseTokenIdxFactory;\n}\n", "export const ENV_FLAG_NAME = 'has-yfm-notes';\nexport const DEFAULT_LANG = 'ru';\n\nexport type Lang =\n | 'ru'\n | 'en'\n | 'ar'\n | 'cs'\n | 'fr'\n | 'es'\n | 'he'\n | 'bg'\n | 'et'\n | 'el'\n | 'pt'\n | 'zh'\n | 'zh-tw'\n | 'kk'\n | 'tr'\n | 'uz';\n\nexport const TITLES: Record<Lang, Record<string, string>> = {\n ru: {\n info: '\u041F\u0440\u0438\u043C\u0435\u0447\u0430\u043D\u0438\u0435',\n tip: '\u0421\u043E\u0432\u0435\u0442',\n alert: '\u0412\u043D\u0438\u043C\u0430\u043D\u0438\u0435',\n warning: '\u0412\u0430\u0436\u043D\u043E',\n },\n en: {\n info: 'Note',\n tip: 'Tip',\n alert: 'Alert',\n warning: 'Warning',\n },\n ar: {\n info: '\u0645\u0644\u0627\u062D\u0638\u0629',\n tip: '\u0646\u0635\u064A\u062D\u0629',\n alert: '\u0627\u0646\u062A\u0628\u0627\u0647',\n warning: '\u0647\u0627\u0645',\n },\n cs: {\n info: 'Pozn\u00E1mka',\n tip: 'Tip',\n alert: 'Upozorn\u011Bn\u00ED',\n warning: 'Varov\u00E1n\u00ED',\n },\n fr: {\n info: 'Remarque',\n tip: 'Astuce',\n alert: 'Alerte',\n warning: 'Avertissement',\n },\n es: {\n info: 'Nota',\n tip: 'Consejo',\n alert: 'Alerta',\n warning: 'Aviso',\n },\n he: {\n info: '\u05DE\u05D9\u05D3\u05E2',\n tip: '\u05D8\u05D9\u05E4',\n alert: '\u05D4\u05EA\u05E8\u05D0\u05D4',\n warning: '\u05D0\u05D6\u05D4\u05E8\u05D4',\n },\n bg: {\n info: '\u0417\u0430\u0431\u0435\u043B\u0435\u0436\u043A\u0430',\n tip: '\u0421\u044A\u0432\u0435\u0442',\n alert: '\u0412\u043D\u0438\u043C\u0430\u043D\u0438\u0435',\n warning: '\u0412\u0430\u0436\u043D\u043E',\n },\n et: {\n info: 'M\u00E4rkus',\n tip: 'N\u00F5uanne',\n alert: 'T\u00E4helepanu',\n warning: 'T\u00E4htis',\n },\n el: {\n info: '\u03A3\u03B7\u03BC\u03B5\u03AF\u03C9\u03C3\u03B7',\n tip: '\u03A3\u03C5\u03BC\u03B2\u03BF\u03C5\u03BB\u03AE',\n alert: '\u03A0\u03C1\u03BF\u03C3\u03BF\u03C7\u03AE',\n warning: '\u03A3\u03B7\u03BC\u03B1\u03BD\u03C4\u03B9\u03BA\u03CC',\n },\n pt: {\n info: 'Observa\u00E7\u00E3o',\n tip: 'Sugest\u00E3o',\n alert: 'Aten\u00E7\u00E3o',\n warning: 'Importante',\n },\n zh: {\n info: '\u5907\u6CE8',\n tip: '\u63D0\u793A',\n alert: '\u6CE8\u610F',\n warning: '\u91CD\u8981',\n },\n 'zh-tw': {\n info: '\u5099\u6CE8',\n tip: '\u63D0\u793A',\n alert: '\u6CE8\u610F',\n warning: '\u91CD\u8981',\n },\n kk: {\n info: '\u0415\u0441\u043A\u0435\u0440\u0442\u0443',\n tip: '\u041A\u0435\u04A3\u0435\u0441',\n alert: '\u041D\u0430\u0437\u0430\u0440 \u0430\u0443\u0434\u0430\u0440\u044B\u04A3\u044B\u0437',\n warning: '\u041C\u0430\u04A3\u044B\u0437\u0434\u044B',\n },\n tr: {\n info: 'Not',\n tip: '\u00D6neri',\n alert: 'Dikkat',\n warning: '\u00D6nemli',\n },\n uz: {\n info: 'Sharh',\n tip: 'Maslahat',\n alert: 'Diqqat',\n warning: 'Bu muhim',\n },\n};\n\nexport const TokenType = {\n Note: 'yfm-note',\n NoteOpen: 'yfm_note_open',\n NoteClose: 'yfm_note_close',\n NoteTitleOpen: 'yfm_note_title_open',\n NoteTitleClose: 'yfm_note_title_close',\n NoteContentOpen: 'yfm_note_content_open',\n NoteContentClose: 'yfm_note_content_close',\n} as const;\n\nexport const ClassNames = {\n Note: 'yfm-note',\n Accent: 'yfm-accent',\n Title: 'yfm-note-title',\n Content: 'yfm-note-content',\n} as const;\n", "import type {\n MatchTokenFunction,\n NoteParser,\n NoteState,\n NoteToken,\n NotesOptions,\n NotesPlugin,\n} from './types.js';\n\nimport {createNestedCloseTokenIdxFactory} from './close.js';\nimport {DEFAULT_LANG, TITLES} from './const.js';\n\nconst quietLogger = {warn: (_message: string) => {}, error: (_message: string) => {}};\n\nconst ALERT_RE = /^{% note (alert|info|tip|warning)\\s*(?:\"(.*?)\")? %}$/;\nconst WRONG_NOTES = /^{% note (.*)%}/;\n\nconst matchCloseToken: MatchTokenFunction = (tokens, i) => {\n return (\n tokens[i].type === 'paragraph_open' &&\n tokens[i + 1].type === 'inline' &&\n tokens[i + 1].content.trim() === '{% endnote %}'\n );\n};\n\nconst titleDictionaries = new Map(Object.entries(TITLES));\n\nfunction getTitle(type: string, lang: string) {\n return (titleDictionaries.get(lang) ?? TITLES.ru)[type];\n}\n\nfunction matchOpenToken(tokens: NoteToken[], i: number) {\n return (\n tokens[i].type === 'paragraph_open' &&\n tokens[i + 1].type === 'inline' &&\n tokens[i + 1].content.match(ALERT_RE)\n );\n}\n\nfunction matchWrongNotes(tokens: NoteToken[], i: number) {\n return (\n tokens[i].type === 'paragraph_open' &&\n tokens[i + 1].type === 'inline' &&\n tokens[i + 1].content.match(WRONG_NOTES)\n );\n}\n\n/**\n * Bind existing feature diagnostics to an execution-host path formatter.\n * @param formatPath - Original terminal or plain browser formatting.\n * @param onNote - Optional host resource notification after a real note is created.\n * @returns The unchanged feature callback.\n */\nexport function createNotesPlugin(\n formatPath: (path: string) => string = (path) => path,\n onNote?: (env: Record<string, unknown>) => void,\n): NotesPlugin {\n const findCloseTokenIdx = createNestedCloseTokenIdxFactory(formatPath)(\n 'Note',\n matchOpenToken,\n matchCloseToken,\n );\n\n const index: NotesPlugin = <Token extends NoteToken>(\n md: NoteParser<Token>,\n {lang = DEFAULT_LANG, notesAutotitle, path: optPath, log = quietLogger}: NotesOptions = {},\n ) => {\n notesAutotitle = typeof notesAutotitle === 'boolean' ? notesAutotitle : true;\n\n const plugin = (state: NoteState<Token>) => {\n const {tokens, env} = state;\n const path = typeof env.path === 'string' && env.path ? env.path : (optPath ?? '');\n let i = 0;\n\n while (i < tokens.length) {\n const match = matchOpenToken(tokens, i);\n\n if (match) {\n // Skip paragraph_close for open token (+1) and paragraph_open for close token (+1)\n // This is minimal useless content length\n const closeTokenIdx = findCloseTokenIdx(tokens, i + 2, path, log);\n\n if (!closeTokenIdx) {\n i += 3;\n continue;\n }\n\n const type = match[1].toLowerCase();\n const newOpenToken = new state.Token('yfm_note_open', 'div', 1);\n newOpenToken.attrSet('class', `yfm-note yfm-accent-${type}`);\n newOpenToken.attrSet('note-type', type);\n newOpenToken.map = tokens[i].map;\n const closeTokenMap = tokens[closeTokenIdx].map;\n\n if (closeTokenMap && newOpenToken.map) {\n newOpenToken.map[1] = closeTokenMap[1];\n }\n\n const newCloseToken = new state.Token('yfm_note_close', 'div', -1);\n newCloseToken.map = tokens[closeTokenIdx].map;\n\n // Add extra paragraph\n const titleOpen = new state.Token('yfm_note_title_open', 'p', 1);\n titleOpen.attrSet('class', 'yfm-note-title');\n const autotitle = notesAutotitle ? getTitle(type, lang) : '';\n const titleContent = match[2] === undefined ? autotitle : match[2];\n const titleInline = state.md.parseInline(titleContent, state.env)[0];\n titleInline.map = null;\n const titleClose = new state.Token('yfm_note_title_close', 'p', -1);\n\n titleOpen.block = true;\n titleClose.block = true;\n\n const contentOpen = new state.Token('yfm_note_content_open', 'div', 1);\n contentOpen.attrSet('class', 'yfm-note-content');\n const contentClose = new state.Token('yfm_note_content_close', 'div', -1);\n\n if (newOpenToken.map) {\n contentOpen.map = [newOpenToken.map[0] + 2, newOpenToken.map[1] - 2];\n }\n\n const insideTokens = [newOpenToken];\n if (titleInline.content) {\n insideTokens.push(titleOpen, titleInline, titleClose);\n }\n\n insideTokens.push(\n contentOpen,\n ...tokens.slice(i + 3, closeTokenIdx),\n contentClose,\n newCloseToken,\n );\n\n tokens.splice(i, closeTokenIdx - i + 3, ...insideTokens);\n\n onNote?.(env);\n i++;\n } else if (\n matchWrongNotes(tokens, i) &&\n tokens[i + 1].content !== '{% endnote %}'\n ) {\n log.warn(\n `Incorrect syntax for notes${path ? `, file ${formatPath(path)}` : ''}`,\n );\n\n i += 3;\n } else {\n i++;\n }\n }\n };\n\n try {\n md.core.ruler.before('curly_attributes', 'notes', plugin);\n } catch {\n md.core.ruler.push('notes', plugin);\n }\n };\n\n return index;\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACOO,SAAS,iCAAiC,YAAsC;AACnF,QAAM,6BACF,CACI,WACAA,iBACAC,qBAEJ,CAAC,QAAqB,KAAa,MAAc,QAAqB;AAClE,QAAI,QAAQ;AACZ,QAAI,IAAI;AACR,WAAO,IAAI,OAAO,QAAQ;AACtB,UAAID,gBAAe,QAAQ,CAAC,GAAG;AAC3B;AAAA,MACJ,WAAWC,iBAAgB,QAAQ,CAAC,GAAG;AACnC,YAAI,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AA,QACT,OAAO;AACH;AAAA,QACJ;AAAA,MACJ;AAAA,IACJ;AAEA,QAAI;AACA,SAAG,KAAK,MAAM,OAAO,oBAAoB,SAAS,MAAM;AAAA,IAC5D,QAAQ;AACJ,SAAG,KAAK,MAAM,KAAK,SAAS,MAAM;AAAA,IACtC;AAAA,EACJ;AAEA,SAAO;AACX;",
|
|
6
|
+
"names": ["matchOpenToken", "matchCloseToken"]
|
|
7
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { NotesOptions, NotesPlugin } from '../plugin/types.js';
|
|
2
|
+
import type { RuntimeOption } from '../plugin/resources.js';
|
|
3
|
+
import { TokenType } from '../plugin/const.js';
|
|
4
|
+
export type TransformOptions = NotesOptions & {
|
|
5
|
+
runtime?: RuntimeOption;
|
|
6
|
+
bundle?: false;
|
|
7
|
+
};
|
|
8
|
+
export declare function transform(options?: TransformOptions): NotesPlugin;
|
|
9
|
+
export { TokenType };
|
|
10
|
+
export type { NotesOptions, NotesLogger } from '../plugin/types.js';
|
|
11
|
+
declare const _default: {
|
|
12
|
+
transform: typeof transform;
|
|
13
|
+
TokenType: {
|
|
14
|
+
readonly Note: "yfm-note";
|
|
15
|
+
readonly NoteOpen: "yfm_note_open";
|
|
16
|
+
readonly NoteClose: "yfm_note_close";
|
|
17
|
+
readonly NoteTitleOpen: "yfm_note_title_open";
|
|
18
|
+
readonly NoteTitleClose: "yfm_note_title_close";
|
|
19
|
+
readonly NoteContentOpen: "yfm_note_content_open";
|
|
20
|
+
readonly NoteContentClose: "yfm_note_content_close";
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
export default _default;
|
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
// src/plugin/close.ts
|
|
2
|
+
function createNestedCloseTokenIdxFactory(formatPath) {
|
|
3
|
+
const nestedCloseTokenIdxFactory = (tokenName, matchOpenToken2, matchCloseToken2) => (tokens, idx, path, log) => {
|
|
4
|
+
let level = 0;
|
|
5
|
+
let i = idx;
|
|
6
|
+
while (i < tokens.length) {
|
|
7
|
+
if (matchOpenToken2(tokens, i)) {
|
|
8
|
+
level++;
|
|
9
|
+
} else if (matchCloseToken2(tokens, i)) {
|
|
10
|
+
if (level === 0) {
|
|
11
|
+
return i;
|
|
12
|
+
}
|
|
13
|
+
level--;
|
|
14
|
+
}
|
|
15
|
+
i++;
|
|
16
|
+
}
|
|
17
|
+
log.error(`${tokenName} must be closed${path ? ` in ${formatPath(path)}` : ""}`);
|
|
18
|
+
return null;
|
|
19
|
+
};
|
|
20
|
+
return nestedCloseTokenIdxFactory;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// src/plugin/const.ts
|
|
24
|
+
var DEFAULT_LANG = "ru";
|
|
25
|
+
var TITLES = {
|
|
26
|
+
ru: {
|
|
27
|
+
info: "\u041F\u0440\u0438\u043C\u0435\u0447\u0430\u043D\u0438\u0435",
|
|
28
|
+
tip: "\u0421\u043E\u0432\u0435\u0442",
|
|
29
|
+
alert: "\u0412\u043D\u0438\u043C\u0430\u043D\u0438\u0435",
|
|
30
|
+
warning: "\u0412\u0430\u0436\u043D\u043E"
|
|
31
|
+
},
|
|
32
|
+
en: {
|
|
33
|
+
info: "Note",
|
|
34
|
+
tip: "Tip",
|
|
35
|
+
alert: "Alert",
|
|
36
|
+
warning: "Warning"
|
|
37
|
+
},
|
|
38
|
+
ar: {
|
|
39
|
+
info: "\u0645\u0644\u0627\u062D\u0638\u0629",
|
|
40
|
+
tip: "\u0646\u0635\u064A\u062D\u0629",
|
|
41
|
+
alert: "\u0627\u0646\u062A\u0628\u0627\u0647",
|
|
42
|
+
warning: "\u0647\u0627\u0645"
|
|
43
|
+
},
|
|
44
|
+
cs: {
|
|
45
|
+
info: "Pozn\xE1mka",
|
|
46
|
+
tip: "Tip",
|
|
47
|
+
alert: "Upozorn\u011Bn\xED",
|
|
48
|
+
warning: "Varov\xE1n\xED"
|
|
49
|
+
},
|
|
50
|
+
fr: {
|
|
51
|
+
info: "Remarque",
|
|
52
|
+
tip: "Astuce",
|
|
53
|
+
alert: "Alerte",
|
|
54
|
+
warning: "Avertissement"
|
|
55
|
+
},
|
|
56
|
+
es: {
|
|
57
|
+
info: "Nota",
|
|
58
|
+
tip: "Consejo",
|
|
59
|
+
alert: "Alerta",
|
|
60
|
+
warning: "Aviso"
|
|
61
|
+
},
|
|
62
|
+
he: {
|
|
63
|
+
info: "\u05DE\u05D9\u05D3\u05E2",
|
|
64
|
+
tip: "\u05D8\u05D9\u05E4",
|
|
65
|
+
alert: "\u05D4\u05EA\u05E8\u05D0\u05D4",
|
|
66
|
+
warning: "\u05D0\u05D6\u05D4\u05E8\u05D4"
|
|
67
|
+
},
|
|
68
|
+
bg: {
|
|
69
|
+
info: "\u0417\u0430\u0431\u0435\u043B\u0435\u0436\u043A\u0430",
|
|
70
|
+
tip: "\u0421\u044A\u0432\u0435\u0442",
|
|
71
|
+
alert: "\u0412\u043D\u0438\u043C\u0430\u043D\u0438\u0435",
|
|
72
|
+
warning: "\u0412\u0430\u0436\u043D\u043E"
|
|
73
|
+
},
|
|
74
|
+
et: {
|
|
75
|
+
info: "M\xE4rkus",
|
|
76
|
+
tip: "N\xF5uanne",
|
|
77
|
+
alert: "T\xE4helepanu",
|
|
78
|
+
warning: "T\xE4htis"
|
|
79
|
+
},
|
|
80
|
+
el: {
|
|
81
|
+
info: "\u03A3\u03B7\u03BC\u03B5\u03AF\u03C9\u03C3\u03B7",
|
|
82
|
+
tip: "\u03A3\u03C5\u03BC\u03B2\u03BF\u03C5\u03BB\u03AE",
|
|
83
|
+
alert: "\u03A0\u03C1\u03BF\u03C3\u03BF\u03C7\u03AE",
|
|
84
|
+
warning: "\u03A3\u03B7\u03BC\u03B1\u03BD\u03C4\u03B9\u03BA\u03CC"
|
|
85
|
+
},
|
|
86
|
+
pt: {
|
|
87
|
+
info: "Observa\xE7\xE3o",
|
|
88
|
+
tip: "Sugest\xE3o",
|
|
89
|
+
alert: "Aten\xE7\xE3o",
|
|
90
|
+
warning: "Importante"
|
|
91
|
+
},
|
|
92
|
+
zh: {
|
|
93
|
+
info: "\u5907\u6CE8",
|
|
94
|
+
tip: "\u63D0\u793A",
|
|
95
|
+
alert: "\u6CE8\u610F",
|
|
96
|
+
warning: "\u91CD\u8981"
|
|
97
|
+
},
|
|
98
|
+
"zh-tw": {
|
|
99
|
+
info: "\u5099\u6CE8",
|
|
100
|
+
tip: "\u63D0\u793A",
|
|
101
|
+
alert: "\u6CE8\u610F",
|
|
102
|
+
warning: "\u91CD\u8981"
|
|
103
|
+
},
|
|
104
|
+
kk: {
|
|
105
|
+
info: "\u0415\u0441\u043A\u0435\u0440\u0442\u0443",
|
|
106
|
+
tip: "\u041A\u0435\u04A3\u0435\u0441",
|
|
107
|
+
alert: "\u041D\u0430\u0437\u0430\u0440 \u0430\u0443\u0434\u0430\u0440\u044B\u04A3\u044B\u0437",
|
|
108
|
+
warning: "\u041C\u0430\u04A3\u044B\u0437\u0434\u044B"
|
|
109
|
+
},
|
|
110
|
+
tr: {
|
|
111
|
+
info: "Not",
|
|
112
|
+
tip: "\xD6neri",
|
|
113
|
+
alert: "Dikkat",
|
|
114
|
+
warning: "\xD6nemli"
|
|
115
|
+
},
|
|
116
|
+
uz: {
|
|
117
|
+
info: "Sharh",
|
|
118
|
+
tip: "Maslahat",
|
|
119
|
+
alert: "Diqqat",
|
|
120
|
+
warning: "Bu muhim"
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
var TokenType = {
|
|
124
|
+
Note: "yfm-note",
|
|
125
|
+
NoteOpen: "yfm_note_open",
|
|
126
|
+
NoteClose: "yfm_note_close",
|
|
127
|
+
NoteTitleOpen: "yfm_note_title_open",
|
|
128
|
+
NoteTitleClose: "yfm_note_title_close",
|
|
129
|
+
NoteContentOpen: "yfm_note_content_open",
|
|
130
|
+
NoteContentClose: "yfm_note_content_close"
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
// src/plugin/plugin.ts
|
|
134
|
+
var quietLogger = { warn: (_message) => {
|
|
135
|
+
}, error: (_message) => {
|
|
136
|
+
} };
|
|
137
|
+
var ALERT_RE = /^{% note (alert|info|tip|warning)\s*(?:"(.*?)")? %}$/;
|
|
138
|
+
var WRONG_NOTES = /^{% note (.*)%}/;
|
|
139
|
+
var matchCloseToken = (tokens, i) => {
|
|
140
|
+
return tokens[i].type === "paragraph_open" && tokens[i + 1].type === "inline" && tokens[i + 1].content.trim() === "{% endnote %}";
|
|
141
|
+
};
|
|
142
|
+
var titleDictionaries = new Map(Object.entries(TITLES));
|
|
143
|
+
function getTitle(type, lang) {
|
|
144
|
+
return (titleDictionaries.get(lang) ?? TITLES.ru)[type];
|
|
145
|
+
}
|
|
146
|
+
function matchOpenToken(tokens, i) {
|
|
147
|
+
return tokens[i].type === "paragraph_open" && tokens[i + 1].type === "inline" && tokens[i + 1].content.match(ALERT_RE);
|
|
148
|
+
}
|
|
149
|
+
function matchWrongNotes(tokens, i) {
|
|
150
|
+
return tokens[i].type === "paragraph_open" && tokens[i + 1].type === "inline" && tokens[i + 1].content.match(WRONG_NOTES);
|
|
151
|
+
}
|
|
152
|
+
function createNotesPlugin(formatPath = (path) => path, onNote) {
|
|
153
|
+
const findCloseTokenIdx = createNestedCloseTokenIdxFactory(formatPath)(
|
|
154
|
+
"Note",
|
|
155
|
+
matchOpenToken,
|
|
156
|
+
matchCloseToken
|
|
157
|
+
);
|
|
158
|
+
const index = (md, { lang = DEFAULT_LANG, notesAutotitle, path: optPath, log = quietLogger } = {}) => {
|
|
159
|
+
notesAutotitle = typeof notesAutotitle === "boolean" ? notesAutotitle : true;
|
|
160
|
+
const plugin = (state) => {
|
|
161
|
+
const { tokens, env } = state;
|
|
162
|
+
const path = typeof env.path === "string" && env.path ? env.path : optPath ?? "";
|
|
163
|
+
let i = 0;
|
|
164
|
+
while (i < tokens.length) {
|
|
165
|
+
const match = matchOpenToken(tokens, i);
|
|
166
|
+
if (match) {
|
|
167
|
+
const closeTokenIdx = findCloseTokenIdx(tokens, i + 2, path, log);
|
|
168
|
+
if (!closeTokenIdx) {
|
|
169
|
+
i += 3;
|
|
170
|
+
continue;
|
|
171
|
+
}
|
|
172
|
+
const type = match[1].toLowerCase();
|
|
173
|
+
const newOpenToken = new state.Token("yfm_note_open", "div", 1);
|
|
174
|
+
newOpenToken.attrSet("class", `yfm-note yfm-accent-${type}`);
|
|
175
|
+
newOpenToken.attrSet("note-type", type);
|
|
176
|
+
newOpenToken.map = tokens[i].map;
|
|
177
|
+
const closeTokenMap = tokens[closeTokenIdx].map;
|
|
178
|
+
if (closeTokenMap && newOpenToken.map) {
|
|
179
|
+
newOpenToken.map[1] = closeTokenMap[1];
|
|
180
|
+
}
|
|
181
|
+
const newCloseToken = new state.Token("yfm_note_close", "div", -1);
|
|
182
|
+
newCloseToken.map = tokens[closeTokenIdx].map;
|
|
183
|
+
const titleOpen = new state.Token("yfm_note_title_open", "p", 1);
|
|
184
|
+
titleOpen.attrSet("class", "yfm-note-title");
|
|
185
|
+
const autotitle = notesAutotitle ? getTitle(type, lang) : "";
|
|
186
|
+
const titleContent = match[2] === void 0 ? autotitle : match[2];
|
|
187
|
+
const titleInline = state.md.parseInline(titleContent, state.env)[0];
|
|
188
|
+
titleInline.map = null;
|
|
189
|
+
const titleClose = new state.Token("yfm_note_title_close", "p", -1);
|
|
190
|
+
titleOpen.block = true;
|
|
191
|
+
titleClose.block = true;
|
|
192
|
+
const contentOpen = new state.Token("yfm_note_content_open", "div", 1);
|
|
193
|
+
contentOpen.attrSet("class", "yfm-note-content");
|
|
194
|
+
const contentClose = new state.Token("yfm_note_content_close", "div", -1);
|
|
195
|
+
if (newOpenToken.map) {
|
|
196
|
+
contentOpen.map = [newOpenToken.map[0] + 2, newOpenToken.map[1] - 2];
|
|
197
|
+
}
|
|
198
|
+
const insideTokens = [newOpenToken];
|
|
199
|
+
if (titleInline.content) {
|
|
200
|
+
insideTokens.push(titleOpen, titleInline, titleClose);
|
|
201
|
+
}
|
|
202
|
+
insideTokens.push(
|
|
203
|
+
contentOpen,
|
|
204
|
+
...tokens.slice(i + 3, closeTokenIdx),
|
|
205
|
+
contentClose,
|
|
206
|
+
newCloseToken
|
|
207
|
+
);
|
|
208
|
+
tokens.splice(i, closeTokenIdx - i + 3, ...insideTokens);
|
|
209
|
+
onNote?.(env);
|
|
210
|
+
i++;
|
|
211
|
+
} else if (matchWrongNotes(tokens, i) && tokens[i + 1].content !== "{% endnote %}") {
|
|
212
|
+
log.warn(
|
|
213
|
+
`Incorrect syntax for notes${path ? `, file ${formatPath(path)}` : ""}`
|
|
214
|
+
);
|
|
215
|
+
i += 3;
|
|
216
|
+
} else {
|
|
217
|
+
i++;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
};
|
|
221
|
+
try {
|
|
222
|
+
md.core.ruler.before("curly_attributes", "notes", plugin);
|
|
223
|
+
} catch {
|
|
224
|
+
md.core.ruler.push("notes", plugin);
|
|
225
|
+
}
|
|
226
|
+
};
|
|
227
|
+
return index;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
// src/plugin/resources.ts
|
|
231
|
+
function normalizeRuntime(runtime, bundle = false) {
|
|
232
|
+
if (runtime === false) return false;
|
|
233
|
+
if (typeof runtime === "string") {
|
|
234
|
+
if (bundle)
|
|
235
|
+
throw new TypeError("Option `runtime` should be record when `bundle` is enabled.");
|
|
236
|
+
return { script: runtime, style: runtime };
|
|
237
|
+
}
|
|
238
|
+
return runtime ?? { style: "_assets/notes-extension.css" };
|
|
239
|
+
}
|
|
240
|
+
function semanticOptions(defaults, settings) {
|
|
241
|
+
return {
|
|
242
|
+
lang: settings.lang === void 0 ? defaults.lang : settings.lang,
|
|
243
|
+
notesAutotitle: settings.notesAutotitle === void 0 ? defaults.notesAutotitle : settings.notesAutotitle,
|
|
244
|
+
path: settings.path === void 0 ? defaults.path : settings.path,
|
|
245
|
+
log: settings.log === void 0 ? defaults.log : settings.log
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
function isRecord(value) {
|
|
249
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
250
|
+
}
|
|
251
|
+
function addResources(env, runtime) {
|
|
252
|
+
const previous = env.meta;
|
|
253
|
+
if (previous !== void 0 && !isRecord(previous)) {
|
|
254
|
+
throw new TypeError("Notes resource metadata must be an object.");
|
|
255
|
+
}
|
|
256
|
+
const meta = { ...previous };
|
|
257
|
+
for (const key of ["style", "script"]) {
|
|
258
|
+
const resource = runtime[key];
|
|
259
|
+
if (!resource) continue;
|
|
260
|
+
const existing = meta[key];
|
|
261
|
+
let values = [];
|
|
262
|
+
if (Array.isArray(existing)) values = [...existing];
|
|
263
|
+
else if (existing !== void 0) values = [existing];
|
|
264
|
+
if (!values.includes(resource)) values.push(resource);
|
|
265
|
+
meta[key] = values;
|
|
266
|
+
}
|
|
267
|
+
env.meta = meta;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
// src/browser/index.ts
|
|
271
|
+
function transform(options = {}) {
|
|
272
|
+
if (options.bundle !== void 0 && options.bundle !== false) {
|
|
273
|
+
throw new TypeError("Browser notes extension cannot copy runtime files.");
|
|
274
|
+
}
|
|
275
|
+
const runtime = normalizeRuntime(options.runtime);
|
|
276
|
+
return function plugin(md, settings = {}) {
|
|
277
|
+
createNotesPlugin(void 0, runtime ? (env) => addResources(env, runtime) : void 0)(
|
|
278
|
+
md,
|
|
279
|
+
semanticOptions(options, settings)
|
|
280
|
+
);
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
var browser_default = { transform, TokenType };
|
|
284
|
+
export {
|
|
285
|
+
TokenType,
|
|
286
|
+
browser_default as default,
|
|
287
|
+
transform
|
|
288
|
+
};
|
|
289
|
+
//# sourceMappingURL=browser.js.map
|