@void/md 0.7.6 → 0.7.8

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.
@@ -56,10 +56,10 @@ function gitHubAlertsPlugin(md, options) {
56
56
  };
57
57
  const rule = (state) => {
58
58
  const tokens = state.tokens;
59
- for (let i = 0; i < tokens.length; i++) if (tokens[i].type === "blockquote_open") {
60
- const startIndex = i;
59
+ for (let tokenIndex = 0; tokenIndex < tokens.length; tokenIndex++) if (tokens[tokenIndex].type === "blockquote_open") {
60
+ const startIndex = tokenIndex;
61
61
  const open = tokens[startIndex];
62
- let endIndex = i + 1;
62
+ let endIndex = tokenIndex + 1;
63
63
  while (endIndex < tokens.length && (tokens[endIndex].type !== "blockquote_close" || tokens[endIndex].level !== open.level)) endIndex++;
64
64
  if (endIndex === tokens.length) continue;
65
65
  const close = tokens[endIndex];
@@ -124,7 +124,7 @@ function lineNumberPlugin(md, enable = false) {
124
124
  const matchStart = info.match(/=(\d+)/);
125
125
  if (matchStart?.[1]) startLineNumber = parseInt(matchStart[1]);
126
126
  const lines = rawCode.slice(rawCode.indexOf("<code>"), rawCode.indexOf("</code>")).split("\n");
127
- const lineNumbersWrapper = `<div class="line-numbers-wrapper" aria-hidden="true">${[...Array(lines.length)].map((_, i) => `<span class="line-number">${i + startLineNumber}</span><br>`).join("")}</div>`;
127
+ const lineNumbersWrapper = `<div class="line-numbers-wrapper" aria-hidden="true">${[...Array(lines.length)].map((_, lineOffset) => `<span class="line-number">${lineOffset + startLineNumber}</span><br>`).join("")}</div>`;
128
128
  return rawCode.replace(/<\/div>$/, `${lineNumbersWrapper}</div>`).replace(/"(language-[^"]*?)"/, "\"$1 line-numbers-mode\"");
129
129
  };
130
130
  }
@@ -224,13 +224,13 @@ function tocPlugin(md, options) {
224
224
  };
225
225
  md.renderer.rules.toc_body = (tokens) => {
226
226
  const headers = [];
227
- for (let i = 0; i < tokens.length; i++) {
228
- const token = tokens[i];
227
+ for (let tokenIndex = 0; tokenIndex < tokens.length; tokenIndex++) {
228
+ const token = tokens[tokenIndex];
229
229
  if (token.type === "heading_open") {
230
230
  const depth = Number(token.tag.slice(1));
231
231
  if (level.includes(depth)) {
232
232
  const slug = token.attrGet?.("id") ?? "";
233
- const text = (tokens[i + 1]?.children?.filter((child) => child.type === "text" || child.type === "code_inline").map((child) => child.content).join("") ?? "").trim();
233
+ const text = (tokens[tokenIndex + 1]?.children?.filter((child) => child.type === "text" || child.type === "code_inline").map((child) => child.content).join("") ?? "").trim();
234
234
  headers.push({
235
235
  depth,
236
236
  slug,
@@ -254,7 +254,7 @@ async function getCompiler(options) {
254
254
  return compilerPromise;
255
255
  }
256
256
  async function createCompiler(options) {
257
- const md = new MarkdownExit({
257
+ const markdown = new MarkdownExit({
258
258
  html: true,
259
259
  linkify: true
260
260
  });
@@ -274,8 +274,8 @@ async function createCompiler(options) {
274
274
  transformerNotationFocus(),
275
275
  transformerNotationErrorLevel()
276
276
  ];
277
- md.renderer.rules.fence = async (tokens, idx) => {
278
- const token = tokens[idx];
277
+ markdown.renderer.rules.fence = async (tokens, tokenIndex) => {
278
+ const token = tokens[tokenIndex];
279
279
  const code = token.content;
280
280
  let lang = token.info ? token.info.split(/\s+/g)[0] : "text";
281
281
  if (!isSpecialLang(lang) && !highlighter.getLoadedLanguages().includes(lang)) if (lang in bundledLanguages) await highlighter.loadLanguage(lang);
@@ -288,26 +288,26 @@ async function createCompiler(options) {
288
288
  meta: { __raw: token.info }
289
289
  });
290
290
  };
291
- md.use(preWrapperPlugin);
292
- md.use(containerPlugin);
293
- md.use(imagePlugin, { lazyLoading: true });
294
- md.use(linkPlugin);
295
- md.use(lineNumberPlugin, false);
296
- md.use(gitHubAlertsPlugin);
297
- md.use(attrs);
298
- md.use(full);
299
- md.use(anchor, { permalink: anchor.permalink.ariaHidden({ placement: "before" }) });
300
- md.use(tocPlugin);
301
- return md;
291
+ markdown.use(preWrapperPlugin);
292
+ markdown.use(containerPlugin);
293
+ markdown.use(imagePlugin, { lazyLoading: true });
294
+ markdown.use(linkPlugin);
295
+ markdown.use(lineNumberPlugin, false);
296
+ markdown.use(gitHubAlertsPlugin);
297
+ markdown.use(attrs);
298
+ markdown.use(full);
299
+ markdown.use(anchor, { permalink: anchor.permalink.ariaHidden({ placement: "before" }) });
300
+ markdown.use(tocPlugin);
301
+ return markdown;
302
302
  }
303
303
  function extractHeadings(tokens) {
304
304
  const headings = [];
305
- for (let i = 0; i < tokens.length; i++) {
306
- const token = tokens[i];
305
+ for (let tokenIndex = 0; tokenIndex < tokens.length; tokenIndex++) {
306
+ const token = tokens[tokenIndex];
307
307
  if (token.type === "heading_open") {
308
308
  const depth = Number(token.tag.slice(1));
309
309
  const slug = token.attrGet?.("id") ?? "";
310
- const text = (tokens[i + 1]?.children?.filter((child) => child.type === "text" || child.type === "code_inline").map((child) => child.content).join("") ?? "").trim();
310
+ const text = (tokens[tokenIndex + 1]?.children?.filter((child) => child.type === "text" || child.type === "code_inline").map((child) => child.content).join("") ?? "").trim();
311
311
  headings.push({
312
312
  depth,
313
313
  slug,
@@ -326,7 +326,7 @@ async function compile(source, options) {
326
326
  html: await compiler.renderAsync(content, env),
327
327
  frontmatter,
328
328
  headings,
329
- title: frontmatter.title ?? headings.find((h) => h.depth === 1)?.text ?? ""
329
+ title: frontmatter.title ?? headings.find((heading) => heading.depth === 1)?.text ?? ""
330
330
  };
331
331
  }
332
332
  //#endregion
package/dist/index.d.mts CHANGED
@@ -1,3 +1,3 @@
1
1
  import { FrontmatterContext, setFrontmatter, useFrontmatter } from "./runtime/index.mjs";
2
- import { n as MdPage } from "./plugin-BpyOmjmC.mjs";
2
+ import { n as MdPage } from "./plugin-DXBtOQJb.mjs";
3
3
  export { FrontmatterContext, type MdPage, setFrontmatter, useFrontmatter };
@@ -1,56 +1,55 @@
1
1
  import { Plugin } from "vite";
2
2
 
3
3
  //#region src/compile.d.ts
4
- interface Heading {
4
+ type Heading = Readonly<{
5
5
  depth: number;
6
6
  slug: string;
7
7
  text: string;
8
- }
9
- interface CompileResult {
8
+ }>;
9
+ type CompileResult = Readonly<{
10
10
  html: string;
11
11
  frontmatter: Record<string, unknown>;
12
- headings: Array<Heading>;
12
+ headings: ReadonlyArray<Heading>;
13
13
  title: string;
14
- }
15
- interface CompileOptions {
14
+ }>;
15
+ type CompileOptions = Readonly<{
16
16
  shiki?: {
17
17
  themes?: {
18
18
  light: string;
19
19
  dark: string;
20
20
  };
21
- langs?: Array<string>;
21
+ langs?: ReadonlyArray<string>;
22
22
  };
23
- }
23
+ }>;
24
24
  //#endregion
25
25
  //#region src/extract-script.d.ts
26
- interface IslandImport {
26
+ type IslandImport = {
27
27
  name: string;
28
28
  specifier: string;
29
- strategy: string;
30
- /** Root-relative island ID (set during transform when file context is available). */
29
+ strategy: string; /** Root-relative island ID (set during transform when file context is available). */
31
30
  islandId?: string;
32
- }
33
- interface ScriptExtraction {
31
+ };
32
+ type ScriptExtraction = Readonly<{
34
33
  script: string | null;
35
34
  body: string;
36
35
  islandImports: Array<IslandImport>;
37
36
  clientCode: string | null;
38
- }
37
+ }>;
39
38
  //#endregion
40
39
  //#region src/plugin.d.ts
41
- interface MdPage {
40
+ type MdPage = Readonly<{
42
41
  path: string;
43
42
  title: string;
44
43
  frontmatter: Record<string, unknown>;
45
- headings: Array<{
44
+ headings: ReadonlyArray<{
46
45
  depth: number;
47
46
  slug: string;
48
47
  text: string;
49
48
  }>;
50
- }
51
- interface MarkdownOptions {
49
+ }>;
50
+ type MarkdownOptions = Readonly<{
52
51
  shiki?: CompileOptions["shiki"];
53
- }
54
- declare function voidMarkdown(options?: MarkdownOptions): Array<Plugin>;
52
+ }>;
53
+ declare function voidMarkdown(options?: MarkdownOptions): ReadonlyArray<Plugin>;
55
54
  //#endregion
56
55
  export { ScriptExtraction as a, IslandImport as i, MdPage as n, CompileOptions as o, voidMarkdown as r, CompileResult as s, MarkdownOptions as t };
package/dist/plugin.d.mts CHANGED
@@ -1,2 +1,2 @@
1
- import { a as ScriptExtraction, i as IslandImport, n as MdPage, o as CompileOptions, r as voidMarkdown, s as CompileResult, t as MarkdownOptions } from "./plugin-BpyOmjmC.mjs";
1
+ import { a as ScriptExtraction, i as IslandImport, n as MdPage, o as CompileOptions, r as voidMarkdown, s as CompileResult, t as MarkdownOptions } from "./plugin-DXBtOQJb.mjs";
2
2
  export { CompileOptions, CompileResult, IslandImport, MarkdownOptions, MdPage, ScriptExtraction, voidMarkdown };
package/dist/plugin.mjs CHANGED
@@ -17,14 +17,14 @@ function generateMdTypes() {
17
17
  return [
18
18
  "// Auto-generated by @void/md — do not edit",
19
19
  "",
20
- "export interface VoidMdPage {",
20
+ "export type VoidMdPage = Readonly<{",
21
21
  " path: string;",
22
22
  " title: string;",
23
23
  " frontmatter: Record<string, unknown>;",
24
- " headings: Array<{ depth: number; slug: string; text: string }>;",
25
- "}",
24
+ " headings: ReadonlyArray<{ depth: number; slug: string; text: string }>;",
25
+ "}>;",
26
26
  "",
27
- "declare const pages: Array<VoidMdPage>;",
27
+ "declare const pages: ReadonlyArray<VoidMdPage>;",
28
28
  "export default pages;",
29
29
  ""
30
30
  ].join("\n");
@@ -114,21 +114,21 @@ function emitReactComponentWithIslands(result, islandImports) {
114
114
  const chunks = buildRenderChunks(result.html, islandImports);
115
115
  let code = `import React from "react";\n`;
116
116
  code += `import { FrontmatterContext } from "@void/md";\n`;
117
- for (let i = 0; i < islandImports.length; i++) {
118
- const item = islandImports[i];
119
- code += `import _raw_island_${i} from ${JSON.stringify(item.specifier)};\n`;
117
+ for (let islandIndex = 0; islandIndex < islandImports.length; islandIndex++) {
118
+ const islandImport = islandImports[islandIndex];
119
+ code += `import _raw_island_${islandIndex} from ${JSON.stringify(islandImport.specifier)};\n`;
120
120
  }
121
- for (let i = 0; i < islandImports.length; i++) {
122
- const item = islandImports[i];
123
- code += `function ${item.name}(props) {
121
+ for (let islandIndex = 0; islandIndex < islandImports.length; islandIndex++) {
122
+ const islandImport = islandImports[islandIndex];
123
+ code += `function ${islandImport.name}(props) {
124
124
  return React.createElement(
125
125
  "div",
126
126
  {
127
- "data-island": ${JSON.stringify(toIslandId(item))},
127
+ "data-island": ${JSON.stringify(toIslandId(islandImport))},
128
128
  "data-props": JSON.stringify(props),
129
- "data-hydrate": ${JSON.stringify(item.strategy)}
129
+ "data-hydrate": ${JSON.stringify(islandImport.strategy)}
130
130
  },
131
- React.createElement(_raw_island_${i}, props)
131
+ React.createElement(_raw_island_${islandIndex}, props)
132
132
  );
133
133
  }\n`;
134
134
  }
@@ -186,11 +186,11 @@ function emitSolidComponentWithIslands(result, islandImports) {
186
186
  const chunks = buildRenderChunks(result.html, islandImports);
187
187
  const importAliasByName = /* @__PURE__ */ new Map();
188
188
  let code = `import { FrontmatterContext } from "@void/md";\n`;
189
- for (let i = 0; i < islandImports.length; i++) {
190
- const item = islandImports[i];
191
- const alias = `RawIsland${i}`;
192
- importAliasByName.set(item.name, alias);
193
- code += `import ${alias} from ${JSON.stringify(item.specifier)};\n`;
189
+ for (let islandIndex = 0; islandIndex < islandImports.length; islandIndex++) {
190
+ const islandImport = islandImports[islandIndex];
191
+ const alias = `RawIsland${islandIndex}`;
192
+ importAliasByName.set(islandImport.name, alias);
193
+ code += `import ${alias} from ${JSON.stringify(islandImport.specifier)};\n`;
194
194
  }
195
195
  code += `
196
196
  const __frontmatter = ${JSON.stringify(result.frontmatter)};
@@ -263,11 +263,11 @@ export const headings = ${toSvelteLiteral(result.headings)};
263
263
  <script>
264
264
  import { setFrontmatter } from "@void/md";
265
265
  `;
266
- for (let i = 0; i < islandImports.length; i++) {
267
- const item = islandImports[i];
268
- const alias = `RawIsland${i}`;
269
- importAliasByName.set(item.name, alias);
270
- source += `import ${alias} from ${JSON.stringify(item.specifier)};
266
+ for (let islandIndex = 0; islandIndex < islandImports.length; islandIndex++) {
267
+ const islandImport = islandImports[islandIndex];
268
+ const alias = `RawIsland${islandIndex}`;
269
+ importAliasByName.set(islandImport.name, alias);
270
+ source += `import ${alias} from ${JSON.stringify(islandImport.specifier)};
271
271
  `;
272
272
  }
273
273
  source += `
@@ -318,44 +318,44 @@ export default defineComponent({
318
318
  const ISLAND_TAG_RE = /<([A-Z]\w*)\s*((?:[^>/"']|"[^"]*"|'[^']*')*)\/\s*>|<([A-Z]\w*)\s*((?:[^>/"']|"[^"]*"|'[^']*')*)>([\s\S]*?)<\/\3\s*>/g;
319
319
  function findIslandTags(html, names) {
320
320
  const matches = [];
321
- let m;
321
+ let tagMatch;
322
322
  ISLAND_TAG_RE.lastIndex = 0;
323
- while ((m = ISLAND_TAG_RE.exec(html)) !== null) {
324
- const name = m[1] ?? m[3];
323
+ while ((tagMatch = ISLAND_TAG_RE.exec(html)) !== null) {
324
+ const name = tagMatch[1] ?? tagMatch[3];
325
325
  if (names.has(name)) matches.push({
326
326
  name,
327
- start: m.index,
328
- end: m.index + m[0].length,
329
- attrs: (m[2] ?? m[4] ?? "").trim(),
330
- children: m[5] ?? ""
327
+ start: tagMatch.index,
328
+ end: tagMatch.index + tagMatch[0].length,
329
+ attrs: (tagMatch[2] ?? tagMatch[4] ?? "").trim(),
330
+ children: tagMatch[5] ?? ""
331
331
  });
332
332
  }
333
333
  return matches;
334
334
  }
335
335
  function parseAttrs(attrStr) {
336
336
  const result = {};
337
- const re = /(\w[\w-]*)(?:\s*=\s*(?:"([^"]*)"|'([^']*)'|(\S+)))?/g;
338
- let m;
339
- while ((m = re.exec(attrStr)) !== null) result[m[1]] = m[2] ?? m[3] ?? m[4] ?? "";
337
+ const attrRe = /(\w[\w-]*)(?:\s*=\s*(?:"([^"]*)"|'([^']*)'|(\S+)))?/g;
338
+ let attrMatch;
339
+ while ((attrMatch = attrRe.exec(attrStr)) !== null) result[attrMatch[1]] = attrMatch[2] ?? attrMatch[3] ?? attrMatch[4] ?? "";
340
340
  return result;
341
341
  }
342
342
  function emitVueComponentWithIslands(result, islandImports) {
343
- const nameSet = new Set(islandImports.map((i) => i.name));
343
+ const nameSet = new Set(islandImports.map((islandImport) => islandImport.name));
344
344
  const islandTags = findIslandTags(result.html, nameSet);
345
345
  let code = `import { defineComponent, h, createStaticVNode, provide } from "vue";\n`;
346
- for (let i = 0; i < islandImports.length; i++) {
347
- const imp = islandImports[i];
348
- code += `import _raw_island_${i} from ${JSON.stringify(imp.specifier)};\n`;
346
+ for (let islandIndex = 0; islandIndex < islandImports.length; islandIndex++) {
347
+ const islandImport = islandImports[islandIndex];
348
+ code += `import _raw_island_${islandIndex} from ${JSON.stringify(islandImport.specifier)};\n`;
349
349
  }
350
- for (let i = 0; i < islandImports.length; i++) {
351
- const imp = islandImports[i];
352
- code += `const ${imp.name} = { inheritAttrs: false, render() {
350
+ for (let islandIndex = 0; islandIndex < islandImports.length; islandIndex++) {
351
+ const islandImport = islandImports[islandIndex];
352
+ code += `const ${islandImport.name} = { inheritAttrs: false, render() {
353
353
  const props = this.$attrs;
354
354
  return h("div", {
355
- "data-island": ${JSON.stringify(toIslandId(imp))},
355
+ "data-island": ${JSON.stringify(toIslandId(islandImport))},
356
356
  "data-props": JSON.stringify(props),
357
- "data-hydrate": ${JSON.stringify(imp.strategy)}
358
- }, h(_raw_island_${i}, props));
357
+ "data-hydrate": ${JSON.stringify(islandImport.strategy)}
358
+ }, h(_raw_island_${islandIndex}, props));
359
359
  }};\n`;
360
360
  }
361
361
  const vnodes = [];
@@ -408,11 +408,11 @@ function extractScript(source) {
408
408
  const script = match[1].trim();
409
409
  const body = source.slice(match[0].length);
410
410
  const islandImports = [];
411
- let m;
412
- while ((m = ISLAND_IMPORT_RE.exec(script)) !== null) islandImports.push({
413
- name: m[1],
414
- specifier: m[2].slice(1, -1),
415
- strategy: m[3].slice(1, -1)
411
+ let importMatch;
412
+ while ((importMatch = ISLAND_IMPORT_RE.exec(script)) !== null) islandImports.push({
413
+ name: importMatch[1],
414
+ specifier: importMatch[2].slice(1, -1),
415
+ strategy: importMatch[3].slice(1, -1)
416
416
  });
417
417
  return {
418
418
  script,
@@ -426,22 +426,22 @@ function extractScript(source) {
426
426
  let metadataCompiler = null;
427
427
  function getMetadataCompiler() {
428
428
  if (metadataCompiler) return metadataCompiler;
429
- const md = new MarkdownExit({
429
+ const markdown = new MarkdownExit({
430
430
  html: true,
431
431
  linkify: true
432
432
  });
433
- md.use(anchor, { permalink: anchor.permalink.ariaHidden({ placement: "before" }) });
434
- metadataCompiler = md;
435
- return md;
433
+ markdown.use(anchor, { permalink: anchor.permalink.ariaHidden({ placement: "before" }) });
434
+ metadataCompiler = markdown;
435
+ return markdown;
436
436
  }
437
437
  function extractHeadings(tokens) {
438
438
  const headings = [];
439
- for (let i = 0; i < tokens.length; i++) {
440
- const token = tokens[i];
439
+ for (let tokenIndex = 0; tokenIndex < tokens.length; tokenIndex++) {
440
+ const token = tokens[tokenIndex];
441
441
  if (token.type === "heading_open") {
442
442
  const depth = Number(token.tag.slice(1));
443
443
  const slug = token.attrGet?.("id") ?? "";
444
- const text = (tokens[i + 1]?.children?.filter((t) => t.type === "text" || t.type === "code_inline").map((t) => t.content).join("") ?? "").trim();
444
+ const text = (tokens[tokenIndex + 1]?.children?.filter((child) => child.type === "text" || child.type === "code_inline").map((child) => child.content).join("") ?? "").trim();
445
445
  headings.push({
446
446
  depth,
447
447
  slug,
@@ -457,7 +457,7 @@ function extractMetadata(source) {
457
457
  return {
458
458
  frontmatter,
459
459
  headings,
460
- title: frontmatter.title ?? headings.find((h) => h.depth === 1)?.text ?? ""
460
+ title: frontmatter.title ?? headings.find((heading) => heading.depth === 1)?.text ?? ""
461
461
  };
462
462
  }
463
463
  //#endregion
@@ -517,7 +517,7 @@ function voidMarkdown(options) {
517
517
  frontmatter: result.frontmatter,
518
518
  headings: result.headings
519
519
  };
520
- }))).sort((a, b) => a.path.localeCompare(b.path));
520
+ }))).sort((leftPage, rightPage) => leftPage.path.localeCompare(rightPage.path));
521
521
  }
522
522
  function writeMdTypes() {
523
523
  const outDir = join(root, ".void");
@@ -646,7 +646,7 @@ export function useFrontmatter() { return useContext(FrontmatterContext) ?? {};
646
646
  const absPath = resolve(dirname(_id), imp.specifier);
647
647
  imp.islandId = normalizePath(relative(root, absPath)).replace(/\.[^.]+$/, "");
648
648
  }
649
- const { compile } = await import("./compile-BRZW8ppH.mjs");
649
+ const { compile } = await import("./compile-zfpn0RR9.mjs");
650
650
  const result = await compile(body, { shiki: options?.shiki });
651
651
  if (adapter === "vue") {
652
652
  if (islandImports.length > 0) return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@void/md",
3
- "version": "0.7.6",
3
+ "version": "0.7.8",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/voidzero-dev/void.git",
@@ -51,11 +51,11 @@
51
51
  "vite": "npm:@voidzero-dev/vite-plus-core@0.1.20",
52
52
  "vite-plus": "^0.1.20",
53
53
  "vue": "^3.5.34",
54
- "void": "0.7.6"
54
+ "void": "0.7.8"
55
55
  },
56
56
  "peerDependencies": {
57
57
  "vite": "npm:@voidzero-dev/vite-plus-core@0.1.20",
58
- "void": "0.7.6"
58
+ "void": "0.7.8"
59
59
  },
60
60
  "scripts": {
61
61
  "build": "vp pack",
package/pages.d.ts CHANGED
@@ -4,12 +4,12 @@
4
4
  */
5
5
  export {};
6
6
 
7
- export interface VoidMdPage {
7
+ export type VoidMdPage = Readonly<{
8
8
  path: string;
9
9
  title: string;
10
10
  frontmatter: Record<string, unknown>;
11
- headings: Array<{ depth: number; slug: string; text: string }>;
12
- }
11
+ headings: ReadonlyArray<{ depth: number; slug: string; text: string }>;
12
+ }>;
13
13
 
14
- declare const pages: Array<VoidMdPage>;
14
+ declare const pages: ReadonlyArray<VoidMdPage>;
15
15
  export default pages;