@vuepress/markdown 2.0.0-beta.9 → 2.0.0-rc.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.
Files changed (74) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +12 -0
  3. package/dist/index.d.ts +188 -0
  4. package/dist/index.js +599 -0
  5. package/package.json +50 -19
  6. package/CHANGELOG.md +0 -247
  7. package/lib/index.d.ts +0 -4
  8. package/lib/index.js +0 -16
  9. package/lib/markdown.d.ts +0 -5
  10. package/lib/markdown.js +0 -77
  11. package/lib/plugins/anchorPlugin.d.ts +0 -62
  12. package/lib/plugins/anchorPlugin.js +0 -5
  13. package/lib/plugins/assetsPlugin.d.ts +0 -11
  14. package/lib/plugins/assetsPlugin.js +0 -24
  15. package/lib/plugins/codePlugin/codePlugin.d.ts +0 -28
  16. package/lib/plugins/codePlugin/codePlugin.js +0 -73
  17. package/lib/plugins/codePlugin/index.d.ts +0 -6
  18. package/lib/plugins/codePlugin/index.js +0 -18
  19. package/lib/plugins/codePlugin/languages.d.ts +0 -38
  20. package/lib/plugins/codePlugin/languages.js +0 -68
  21. package/lib/plugins/codePlugin/resolveHighlightLines.d.ts +0 -9
  22. package/lib/plugins/codePlugin/resolveHighlightLines.js +0 -28
  23. package/lib/plugins/codePlugin/resolveLanguage.d.ts +0 -5
  24. package/lib/plugins/codePlugin/resolveLanguage.js +0 -41
  25. package/lib/plugins/codePlugin/resolveLineNumbers.d.ts +0 -4
  26. package/lib/plugins/codePlugin/resolveLineNumbers.js +0 -16
  27. package/lib/plugins/codePlugin/resolveVPre.d.ts +0 -4
  28. package/lib/plugins/codePlugin/resolveVPre.js +0 -16
  29. package/lib/plugins/customComponentPlugin/customComponentPlugin.d.ts +0 -6
  30. package/lib/plugins/customComponentPlugin/customComponentPlugin.js +0 -18
  31. package/lib/plugins/customComponentPlugin/htmlBlockRule.d.ts +0 -2
  32. package/lib/plugins/customComponentPlugin/htmlBlockRule.js +0 -90
  33. package/lib/plugins/customComponentPlugin/htmlInlineRule.d.ts +0 -2
  34. package/lib/plugins/customComponentPlugin/htmlInlineRule.js +0 -40
  35. package/lib/plugins/customComponentPlugin/htmlRe.d.ts +0 -2
  36. package/lib/plugins/customComponentPlugin/htmlRe.js +0 -33
  37. package/lib/plugins/customComponentPlugin/index.d.ts +0 -4
  38. package/lib/plugins/customComponentPlugin/index.js +0 -16
  39. package/lib/plugins/customComponentPlugin/inlineTags.d.ts +0 -18
  40. package/lib/plugins/customComponentPlugin/inlineTags.js +0 -78
  41. package/lib/plugins/customComponentPlugin/vueReservedTags.d.ts +0 -6
  42. package/lib/plugins/customComponentPlugin/vueReservedTags.js +0 -17
  43. package/lib/plugins/emojiPlugin.d.ts +0 -25
  44. package/lib/plugins/emojiPlugin.js +0 -5
  45. package/lib/plugins/extractHeadersPlugin.d.ts +0 -27
  46. package/lib/plugins/extractHeadersPlugin.js +0 -32
  47. package/lib/plugins/hoistTagsPlugin.d.ts +0 -12
  48. package/lib/plugins/hoistTagsPlugin.js +0 -26
  49. package/lib/plugins/index.d.ts +0 -9
  50. package/lib/plugins/index.js +0 -21
  51. package/lib/plugins/linksPlugin/index.d.ts +0 -2
  52. package/lib/plugins/linksPlugin/index.js +0 -14
  53. package/lib/plugins/linksPlugin/linksPlugin.d.ts +0 -12
  54. package/lib/plugins/linksPlugin/linksPlugin.js +0 -108
  55. package/lib/plugins/linksPlugin/resolvePaths.d.ts +0 -7
  56. package/lib/plugins/linksPlugin/resolvePaths.js +0 -38
  57. package/lib/plugins/tocPlugin/createRenderHeaders.d.ts +0 -5
  58. package/lib/plugins/tocPlugin/createRenderHeaders.js +0 -28
  59. package/lib/plugins/tocPlugin/createTocBlockRule.d.ts +0 -11
  60. package/lib/plugins/tocPlugin/createTocBlockRule.js +0 -50
  61. package/lib/plugins/tocPlugin/index.d.ts +0 -3
  62. package/lib/plugins/tocPlugin/index.js +0 -15
  63. package/lib/plugins/tocPlugin/tocPlugin.d.ts +0 -65
  64. package/lib/plugins/tocPlugin/tocPlugin.js +0 -56
  65. package/lib/types.d.ts +0 -62
  66. package/lib/types.js +0 -2
  67. package/lib/utils/index.d.ts +0 -3
  68. package/lib/utils/index.js +0 -15
  69. package/lib/utils/parseEmoji.d.ts +0 -1
  70. package/lib/utils/parseEmoji.js +0 -6
  71. package/lib/utils/resolveHeadersFromTokens.d.ts +0 -12
  72. package/lib/utils/resolveHeadersFromTokens.js +0 -83
  73. package/lib/utils/slugify.d.ts +0 -1
  74. package/lib/utils/slugify.js +0 -24
package/dist/index.js ADDED
@@ -0,0 +1,599 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __export = (target, all) => {
3
+ for (var name in all)
4
+ __defProp(target, name, { get: all[name], enumerable: true });
5
+ };
6
+
7
+ // src/markdown.ts
8
+ import { slugify as defaultSlugify } from "@mdit-vue/shared";
9
+ import MarkdownIt from "markdown-it";
10
+
11
+ // src/plugins.ts
12
+ import {
13
+ componentPlugin
14
+ } from "@mdit-vue/plugin-component";
15
+ import {
16
+ frontmatterPlugin
17
+ } from "@mdit-vue/plugin-frontmatter";
18
+ import {
19
+ headersPlugin
20
+ } from "@mdit-vue/plugin-headers";
21
+ import { sfcPlugin } from "@mdit-vue/plugin-sfc";
22
+ import { titlePlugin } from "@mdit-vue/plugin-title";
23
+ import { tocPlugin } from "@mdit-vue/plugin-toc";
24
+
25
+ // src/plugins/anchorPlugin.ts
26
+ import { default as anchorPlugin } from "markdown-it-anchor";
27
+
28
+ // src/plugins/assetsPlugin/resolveLink.ts
29
+ import { path } from "@vuepress/utils";
30
+ import { decode } from "mdurl";
31
+ var resolveLink = (link, {
32
+ env,
33
+ absolutePathPrependBase = false,
34
+ relativePathPrefix,
35
+ strict = false
36
+ }) => {
37
+ if (link.startsWith("data:"))
38
+ return link;
39
+ let resolvedLink = decode(link);
40
+ const isRelativePath = strict ? (
41
+ // in strict mode, only link that starts with `./` or `../` is considered as relative path
42
+ /^\.{1,2}\//.test(link)
43
+ ) : (
44
+ // in non-strict mode, link that does not start with `/` and does not have protocol is considered as relative path
45
+ !link.startsWith("/") && !/[A-z]+:\/\//.test(link)
46
+ );
47
+ if (isRelativePath && env.filePathRelative) {
48
+ resolvedLink = `${relativePathPrefix}/${path.join(
49
+ path.dirname(env.filePathRelative),
50
+ resolvedLink
51
+ )}`;
52
+ }
53
+ if (absolutePathPrependBase && env.base && link.startsWith("/")) {
54
+ resolvedLink = path.join(env.base, resolvedLink);
55
+ }
56
+ return resolvedLink;
57
+ };
58
+
59
+ // src/plugins/assetsPlugin/assetsPlugin.ts
60
+ var assetsPlugin = (md, {
61
+ absolutePathPrependBase = false,
62
+ relativePathPrefix = "@source"
63
+ } = {}) => {
64
+ const rawImageRule = md.renderer.rules.image;
65
+ md.renderer.rules.image = (tokens, idx, options, env, self) => {
66
+ const token = tokens[idx];
67
+ const link = token.attrGet("src");
68
+ if (link) {
69
+ token.attrSet(
70
+ "src",
71
+ resolveLink(link, { env, absolutePathPrependBase, relativePathPrefix })
72
+ );
73
+ }
74
+ return rawImageRule(tokens, idx, options, env, self);
75
+ };
76
+ const createHtmlRule = (rawHtmlRule) => (tokens, idx, options, env, self) => {
77
+ tokens[idx].content = tokens[idx].content.replace(
78
+ /(<img\b.*?src=)(['"])([^\2]*?)\2/gs,
79
+ (_, prefix, quote, src) => `${prefix}${quote}${resolveLink(src.trim(), {
80
+ env,
81
+ absolutePathPrependBase,
82
+ relativePathPrefix,
83
+ strict: true
84
+ })}${quote}`
85
+ ).replace(
86
+ /(<img\b.*?srcset=)(['"])([^\2]*?)\2/gs,
87
+ (_, prefix, quote, srcset) => `${prefix}${quote}${srcset.split(",").map(
88
+ (item) => item.trim().replace(
89
+ /^([^ ]*?)([ \n].*)?$/,
90
+ (_2, url, descriptor = "") => `${resolveLink(url.trim(), {
91
+ env,
92
+ absolutePathPrependBase,
93
+ relativePathPrefix,
94
+ strict: true
95
+ })}${descriptor.replace(/[ \n]+/g, " ").trimEnd()}`
96
+ )
97
+ ).join(", ")}${quote}`
98
+ );
99
+ return rawHtmlRule(tokens, idx, options, env, self);
100
+ };
101
+ const rawHtmlBlockRule = md.renderer.rules.html_block;
102
+ const rawHtmlInlineRule = md.renderer.rules.html_inline;
103
+ md.renderer.rules.html_block = createHtmlRule(rawHtmlBlockRule);
104
+ md.renderer.rules.html_inline = createHtmlRule(rawHtmlInlineRule);
105
+ };
106
+
107
+ // src/plugins/codePlugin/resolveAttr.ts
108
+ var resolveAttr = (info, attr) => {
109
+ const pattern = `\\b${attr}\\s*=\\s*(?<quote>['"])(?<content>.+?)\\k<quote>(\\s|$)`;
110
+ const regex = new RegExp(pattern, "i");
111
+ const match = info.match(regex);
112
+ return match?.groups?.content ?? null;
113
+ };
114
+
115
+ // src/plugins/codePlugin/resolveHighlightLines.ts
116
+ var resolveHighlightLines = (info) => {
117
+ const match = info.match(/{([\d,-]+)}/);
118
+ if (match === null) {
119
+ return null;
120
+ }
121
+ return match[1].split(",").map((item) => {
122
+ const range = item.split("-");
123
+ if (range.length === 1) {
124
+ range.push(range[0]);
125
+ }
126
+ return range.map((str) => Number.parseInt(str, 10));
127
+ });
128
+ };
129
+ var isHighlightLine = (lineNumber, ranges) => ranges.some(([start, end]) => lineNumber >= start && lineNumber <= end);
130
+
131
+ // src/plugins/codePlugin/languages.ts
132
+ var languages_exports = {};
133
+ __export(languages_exports, {
134
+ languageBash: () => languageBash,
135
+ languageCsharp: () => languageCsharp,
136
+ languageDocker: () => languageDocker,
137
+ languageFsharp: () => languageFsharp,
138
+ languageJavascript: () => languageJavascript,
139
+ languageKotlin: () => languageKotlin,
140
+ languageMarkdown: () => languageMarkdown,
141
+ languagePython: () => languagePython,
142
+ languageRuby: () => languageRuby,
143
+ languageRust: () => languageRust,
144
+ languageStylus: () => languageStylus,
145
+ languageTypescript: () => languageTypescript,
146
+ languageYaml: () => languageYaml
147
+ });
148
+ var languageBash = {
149
+ name: "bash",
150
+ ext: "sh",
151
+ aliases: ["bash", "sh", "shell", "zsh"]
152
+ };
153
+ var languageCsharp = {
154
+ name: "csharp",
155
+ ext: "cs",
156
+ aliases: ["cs", "csharp"]
157
+ };
158
+ var languageDocker = {
159
+ name: "docker",
160
+ ext: "docker",
161
+ aliases: ["docker", "dockerfile"]
162
+ };
163
+ var languageFsharp = {
164
+ name: "fsharp",
165
+ ext: "fs",
166
+ aliases: ["fs", "fsharp"]
167
+ };
168
+ var languageJavascript = {
169
+ name: "javascript",
170
+ ext: "js",
171
+ aliases: ["javascript", "js"]
172
+ };
173
+ var languageKotlin = {
174
+ name: "kotlin",
175
+ ext: "kt",
176
+ aliases: ["kotlin", "kt"]
177
+ };
178
+ var languageMarkdown = {
179
+ name: "markdown",
180
+ ext: "md",
181
+ aliases: ["markdown", "md"]
182
+ };
183
+ var languagePython = {
184
+ name: "python",
185
+ ext: "py",
186
+ aliases: ["py", "python"]
187
+ };
188
+ var languageRuby = {
189
+ name: "ruby",
190
+ ext: "rb",
191
+ aliases: ["rb", "ruby"]
192
+ };
193
+ var languageRust = {
194
+ name: "rust",
195
+ ext: "rs",
196
+ aliases: ["rs", "rust"]
197
+ };
198
+ var languageStylus = {
199
+ name: "stylus",
200
+ ext: "styl",
201
+ aliases: ["styl", "stylus"]
202
+ };
203
+ var languageTypescript = {
204
+ name: "typescript",
205
+ ext: "ts",
206
+ aliases: ["ts", "typescript"]
207
+ };
208
+ var languageYaml = {
209
+ name: "yaml",
210
+ ext: "yml",
211
+ aliases: ["yaml", "yml"]
212
+ };
213
+
214
+ // src/plugins/codePlugin/resolveLanguage.ts
215
+ var languagesMap;
216
+ var getLanguagesMap = () => {
217
+ if (!languagesMap) {
218
+ languagesMap = Object.values(languages_exports).reduce((result, item) => {
219
+ item.aliases.forEach((alias) => {
220
+ result[alias] = item;
221
+ });
222
+ return result;
223
+ }, {});
224
+ }
225
+ return languagesMap;
226
+ };
227
+ var resolveLanguage = (info) => {
228
+ const alias = info.match(/^([^ :[{]+)/)?.[1] || "text";
229
+ return getLanguagesMap()[alias] ?? {
230
+ name: alias,
231
+ ext: alias,
232
+ aliases: [alias]
233
+ };
234
+ };
235
+
236
+ // src/plugins/codePlugin/resolveLineNumbers.ts
237
+ var resolveLineNumbers = (info) => {
238
+ if (/:line-numbers\b/.test(info)) {
239
+ return true;
240
+ }
241
+ if (/:no-line-numbers\b/.test(info)) {
242
+ return false;
243
+ }
244
+ return null;
245
+ };
246
+
247
+ // src/plugins/codePlugin/resolveVPre.ts
248
+ var resolveVPre = (info) => {
249
+ if (/:v-pre\b/.test(info)) {
250
+ return true;
251
+ }
252
+ if (/:no-v-pre\b/.test(info)) {
253
+ return false;
254
+ }
255
+ return null;
256
+ };
257
+
258
+ // src/plugins/codePlugin/codePlugin.ts
259
+ var codePlugin = (md, {
260
+ highlightLines = true,
261
+ lineNumbers = true,
262
+ preWrapper = true,
263
+ vPre: { block: vPreBlock = true, inline: vPreInline = true } = {}
264
+ } = {}) => {
265
+ md.renderer.rules.fence = (tokens, idx, options, env, slf) => {
266
+ const token = tokens[idx];
267
+ const info = token.info ? md.utils.unescapeAll(token.info).trim() : "";
268
+ const language = resolveLanguage(info);
269
+ const languageClass = `${options.langPrefix}${language.name}`;
270
+ const code = options.highlight?.(token.content, language.name, "") || md.utils.escapeHtml(token.content);
271
+ token.attrJoin("class", languageClass);
272
+ let result = code.startsWith("<pre") ? code : `<pre${slf.renderAttrs(token)}><code>${code}</code></pre>`;
273
+ const useVPre = resolveVPre(info) ?? vPreBlock;
274
+ if (useVPre) {
275
+ result = `<pre v-pre${result.slice("<pre".length)}`;
276
+ }
277
+ if (!preWrapper) {
278
+ return result;
279
+ }
280
+ const lines = code.split("\n").slice(0, -1);
281
+ const highlightLinesRanges = highlightLines ? resolveHighlightLines(info) : null;
282
+ if (highlightLinesRanges) {
283
+ const highlightLinesCode = lines.map((_, index) => {
284
+ if (isHighlightLine(index + 1, highlightLinesRanges)) {
285
+ return '<div class="highlight-line">&nbsp;</div>';
286
+ }
287
+ return "<br>";
288
+ }).join("");
289
+ result = `${result}<div class="highlight-lines">${highlightLinesCode}</div>`;
290
+ }
291
+ const useLineNumbers = resolveLineNumbers(info) ?? (typeof lineNumbers === "number" ? lines.length >= lineNumbers : lineNumbers);
292
+ if (useLineNumbers) {
293
+ const lineNumbersCode = lines.map(() => `<div class="line-number"></div>`).join("");
294
+ result = `${result}<div class="line-numbers" aria-hidden="true">${lineNumbersCode}</div>`;
295
+ }
296
+ const title = resolveAttr(info, "title") ?? language.ext;
297
+ result = `<div class="${languageClass}${useLineNumbers ? " line-numbers-mode" : ""}" data-ext="${language.ext}" data-title="${title}">${result}</div>`;
298
+ return result;
299
+ };
300
+ if (vPreInline) {
301
+ const rawInlineCodeRule = md.renderer.rules.code_inline;
302
+ md.renderer.rules.code_inline = (tokens, idx, options, env, slf) => {
303
+ const result = rawInlineCodeRule(tokens, idx, options, env, slf);
304
+ return `<code v-pre${result.slice("<code".length)}`;
305
+ };
306
+ }
307
+ };
308
+
309
+ // src/plugins/emojiPlugin.ts
310
+ import { full as emojiPlugin } from "markdown-it-emoji";
311
+
312
+ // src/plugins/importCodePlugin/createImportCodeBlockRule.ts
313
+ import { path as path2 } from "@vuepress/utils";
314
+ var MIN_LENGTH = 9;
315
+ var START_CODES = [64, 91, 99, 111, 100, 101];
316
+ var SYNTAX_RE = /^@\[code(?:{(?:(\d+)?-(\d+)?)})?(?: ([^\]]+))?\]\(([^)]*)\)/;
317
+ var createImportCodeBlockRule = ({ handleImportPath = (str) => str }) => (state, startLine, endLine, silent) => {
318
+ if (state.sCount[startLine] - state.blkIndent >= 4) {
319
+ return false;
320
+ }
321
+ const pos = state.bMarks[startLine] + state.tShift[startLine];
322
+ const max = state.eMarks[startLine];
323
+ if (pos + MIN_LENGTH > max)
324
+ return false;
325
+ for (let i = 0; i < START_CODES.length; i += 1) {
326
+ if (state.src.charCodeAt(pos + i) !== START_CODES[i]) {
327
+ return false;
328
+ }
329
+ }
330
+ const match = state.src.slice(pos, max).match(SYNTAX_RE);
331
+ if (!match)
332
+ return false;
333
+ if (silent)
334
+ return true;
335
+ const [, lineStart, lineEnd, info, importPath] = match;
336
+ const meta = {
337
+ importPath: handleImportPath(importPath),
338
+ lineStart: lineStart ? Number.parseInt(lineStart, 10) : 0,
339
+ lineEnd: lineEnd ? Number.parseInt(lineEnd, 10) : void 0
340
+ };
341
+ const token = state.push("import_code", "code", 0);
342
+ token.info = info ?? path2.extname(meta.importPath).slice(1);
343
+ token.markup = "```";
344
+ token.map = [startLine, startLine + 1];
345
+ token.meta = meta;
346
+ state.line = startLine + 1;
347
+ return true;
348
+ };
349
+
350
+ // src/plugins/importCodePlugin/resolveImportCode.ts
351
+ import { colors, fs, logger, path as path3 } from "@vuepress/utils";
352
+ var resolveImportCode = ({ importPath, lineStart, lineEnd }, { filePath }) => {
353
+ let importFilePath = importPath;
354
+ if (!path3.isAbsolute(importPath)) {
355
+ if (!filePath) {
356
+ logger.error(
357
+ `Import file ${colors.magenta(importPath)} can not be resolved`
358
+ );
359
+ return {
360
+ importFilePath: null,
361
+ importCode: "Error when resolving path"
362
+ };
363
+ }
364
+ importFilePath = path3.resolve(filePath, "..", importPath);
365
+ }
366
+ if (!fs.existsSync(importFilePath)) {
367
+ logger.error(`Import file ${colors.magenta(importPath)} not found`);
368
+ return {
369
+ importFilePath,
370
+ importCode: "File not found"
371
+ };
372
+ }
373
+ const fileContent = fs.readFileSync(importFilePath).toString();
374
+ return {
375
+ importFilePath,
376
+ importCode: fileContent.split("\n").slice(lineStart ? lineStart - 1 : lineStart, lineEnd).join("\n").replace(/\n?$/, "\n")
377
+ };
378
+ };
379
+
380
+ // src/plugins/importCodePlugin/importCodePlugin.ts
381
+ var importCodePlugin = (md, options = {}) => {
382
+ md.block.ruler.before(
383
+ "fence",
384
+ "import_code",
385
+ createImportCodeBlockRule(options),
386
+ {
387
+ alt: ["paragraph", "reference", "blockquote", "list"]
388
+ }
389
+ );
390
+ md.renderer.rules.import_code = (tokens, idx, options2, env, slf) => {
391
+ const token = tokens[idx];
392
+ const { importFilePath, importCode } = resolveImportCode(token.meta, env);
393
+ token.content = importCode;
394
+ if (importFilePath) {
395
+ ;
396
+ (env.importedFiles ??= []).push(importFilePath);
397
+ }
398
+ return md.renderer.rules.fence(tokens, idx, options2, env, slf);
399
+ };
400
+ };
401
+
402
+ // src/plugins/linksPlugin/linksPlugin.ts
403
+ import { isLinkExternal } from "@vuepress/shared";
404
+
405
+ // src/plugins/linksPlugin/resolvePaths.ts
406
+ import { removeLeadingSlash } from "@vuepress/shared";
407
+ import { path as path4 } from "@vuepress/utils";
408
+ var resolvePaths = (rawPath, base, filePathRelative) => {
409
+ let absolutePath;
410
+ let relativePath;
411
+ if (rawPath.startsWith("/")) {
412
+ if (rawPath.endsWith(".md")) {
413
+ absolutePath = path4.join(base, rawPath);
414
+ relativePath = removeLeadingSlash(rawPath);
415
+ } else {
416
+ absolutePath = rawPath;
417
+ relativePath = path4.relative(base, absolutePath);
418
+ }
419
+ } else {
420
+ if (filePathRelative) {
421
+ relativePath = path4.join(
422
+ // file path may contain non-ASCII characters
423
+ path4.dirname(encodeURI(filePathRelative)),
424
+ rawPath
425
+ );
426
+ absolutePath = path4.join(base, relativePath);
427
+ } else {
428
+ relativePath = rawPath.replace(/^(?:\.\/)?(.*)$/, "$1");
429
+ absolutePath = relativePath;
430
+ }
431
+ }
432
+ return {
433
+ absolutePath,
434
+ relativePath
435
+ };
436
+ };
437
+
438
+ // src/plugins/linksPlugin/linksPlugin.ts
439
+ var linksPlugin = (md, options = {}) => {
440
+ const internalTag = options.internalTag || "RouterLink";
441
+ const externalAttrs = {
442
+ target: "_blank",
443
+ rel: "noopener noreferrer",
444
+ ...options.externalAttrs
445
+ };
446
+ let hasOpenInternalLink = false;
447
+ const handleLinkOpen = (tokens, idx, env) => {
448
+ const token = tokens[idx];
449
+ const hrefIndex = token.attrIndex("href");
450
+ if (hrefIndex < 0) {
451
+ return;
452
+ }
453
+ const hrefAttr = token.attrs[hrefIndex];
454
+ const hrefLink = hrefAttr[1];
455
+ const { base = "/", filePathRelative = null } = env;
456
+ if (isLinkExternal(hrefLink, base)) {
457
+ Object.entries(externalAttrs).forEach(
458
+ ([key, val]) => token.attrSet(key, val)
459
+ );
460
+ return;
461
+ }
462
+ const internalLinkMatch = hrefLink.match(
463
+ /^((?:.*)(?:\/|\.md|\.html))(#.*)?$/
464
+ );
465
+ if (!internalLinkMatch) {
466
+ return;
467
+ }
468
+ const rawPath = internalLinkMatch[1];
469
+ const rawHash = internalLinkMatch[2] || "";
470
+ const { relativePath, absolutePath } = resolvePaths(
471
+ rawPath,
472
+ base,
473
+ filePathRelative
474
+ );
475
+ const normalizedPath = absolutePath.replace(new RegExp(`^${base}`), "/").replace(/(^|\/)(README|index).md$/i, "$1").replace(/\.md$/, ".html");
476
+ if (internalTag === "RouterLink") {
477
+ token.tag = internalTag;
478
+ hrefAttr[0] = "to";
479
+ hasOpenInternalLink = true;
480
+ }
481
+ hrefAttr[1] = `${normalizedPath}${rawHash}`;
482
+ (env.links ??= []).push({
483
+ raw: hrefLink,
484
+ relative: relativePath,
485
+ absolute: absolutePath
486
+ });
487
+ };
488
+ md.renderer.rules.link_open = (tokens, idx, options2, env, self) => {
489
+ handleLinkOpen(tokens, idx, env);
490
+ return self.renderToken(tokens, idx, options2);
491
+ };
492
+ md.renderer.rules.link_close = (tokens, idx, options2, env, self) => {
493
+ if (hasOpenInternalLink) {
494
+ hasOpenInternalLink = false;
495
+ tokens[idx].tag = internalTag;
496
+ }
497
+ return self.renderToken(tokens, idx, options2);
498
+ };
499
+ };
500
+
501
+ // src/markdown.ts
502
+ var createMarkdown = ({
503
+ anchor,
504
+ assets,
505
+ code,
506
+ component,
507
+ emoji,
508
+ frontmatter,
509
+ headers,
510
+ title,
511
+ importCode,
512
+ links,
513
+ sfc,
514
+ slugify = defaultSlugify,
515
+ toc,
516
+ ...markdownItOptions
517
+ } = {}) => {
518
+ const md = MarkdownIt({
519
+ ...markdownItOptions,
520
+ // should always enable html option
521
+ html: true
522
+ });
523
+ if (anchor !== false) {
524
+ md.use(anchorPlugin, {
525
+ level: [1, 2, 3, 4, 5, 6],
526
+ slugify,
527
+ permalink: anchorPlugin.permalink.headerLink({
528
+ class: "header-anchor",
529
+ // Add a span inside the link so Safari shows headings in reader view.
530
+ safariReaderFix: true
531
+ }),
532
+ ...anchor
533
+ });
534
+ }
535
+ if (assets !== false) {
536
+ md.use(assetsPlugin, assets);
537
+ }
538
+ if (code !== false) {
539
+ md.use(codePlugin, code);
540
+ }
541
+ if (component !== false) {
542
+ md.use(componentPlugin);
543
+ }
544
+ if (emoji !== false) {
545
+ md.use(emojiPlugin, emoji);
546
+ }
547
+ if (frontmatter !== false) {
548
+ md.use(frontmatterPlugin, {
549
+ ...frontmatter,
550
+ grayMatterOptions: {
551
+ excerpt: false,
552
+ ...frontmatter?.grayMatterOptions
553
+ }
554
+ });
555
+ }
556
+ if (headers !== false) {
557
+ md.use(headersPlugin, {
558
+ level: [2, 3],
559
+ slugify,
560
+ ...headers
561
+ });
562
+ }
563
+ if (importCode !== false) {
564
+ md.use(importCodePlugin, importCode);
565
+ }
566
+ if (links !== false) {
567
+ md.use(linksPlugin, links);
568
+ }
569
+ if (sfc !== false) {
570
+ md.use(sfcPlugin, sfc);
571
+ }
572
+ if (toc !== false) {
573
+ md.use(tocPlugin, {
574
+ level: [2, 3],
575
+ slugify,
576
+ linkTag: "router-link",
577
+ ...toc
578
+ });
579
+ }
580
+ if (title !== false) {
581
+ md.use(titlePlugin);
582
+ }
583
+ return md;
584
+ };
585
+ export {
586
+ anchorPlugin,
587
+ assetsPlugin,
588
+ codePlugin,
589
+ componentPlugin,
590
+ createMarkdown,
591
+ emojiPlugin,
592
+ frontmatterPlugin,
593
+ headersPlugin,
594
+ importCodePlugin,
595
+ linksPlugin,
596
+ sfcPlugin,
597
+ titlePlugin,
598
+ tocPlugin
599
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vuepress/markdown",
3
- "version": "2.0.0-beta.9",
3
+ "version": "2.0.0-rc.1",
4
4
  "description": "Markdown package of VuePress",
5
5
  "keywords": [
6
6
  "vuepress",
@@ -8,33 +8,64 @@
8
8
  ],
9
9
  "homepage": "https://github.com/vuepress",
10
10
  "bugs": {
11
- "url": "https://github.com/vuepress/vuepress-next/issues"
11
+ "url": "https://github.com/vuepress/core/issues"
12
12
  },
13
13
  "repository": {
14
14
  "type": "git",
15
- "url": "git+https://github.com/vuepress/vuepress-next.git"
15
+ "url": "git+https://github.com/vuepress/core.git"
16
16
  },
17
17
  "license": "MIT",
18
- "author": "Evan You",
19
- "main": "lib/index.js",
20
- "types": "lib/index.d.ts",
18
+ "author": "meteorlxy",
19
+ "type": "module",
20
+ "exports": {
21
+ ".": "./dist/index.js",
22
+ "./package.json": "./package.json"
23
+ },
24
+ "main": "./dist/index.js",
25
+ "types": "./dist/index.d.ts",
21
26
  "files": [
22
- "lib"
27
+ "dist"
23
28
  ],
24
- "scripts": {
25
- "build": "tsc -b tsconfig.build.json",
26
- "clean": "rimraf lib *.tsbuildinfo"
27
- },
28
29
  "dependencies": {
29
- "@types/markdown-it": "^12.0.1",
30
- "@vuepress/shared": "2.0.0-beta.7",
31
- "@vuepress/utils": "2.0.0-beta.8",
32
- "markdown-it": "^12.0.4",
33
- "markdown-it-anchor": "^7.1.0",
34
- "markdown-it-emoji": "^2.0.0"
30
+ "@mdit-vue/plugin-component": "^2.0.0",
31
+ "@mdit-vue/plugin-frontmatter": "^2.0.0",
32
+ "@mdit-vue/plugin-headers": "^2.0.0",
33
+ "@mdit-vue/plugin-sfc": "^2.0.0",
34
+ "@mdit-vue/plugin-title": "^2.0.0",
35
+ "@mdit-vue/plugin-toc": "^2.0.0",
36
+ "@mdit-vue/shared": "^2.0.0",
37
+ "@mdit-vue/types": "^2.0.0",
38
+ "@types/markdown-it": "^13.0.7",
39
+ "@types/markdown-it-emoji": "^2.0.4",
40
+ "markdown-it": "^14.0.0",
41
+ "markdown-it-anchor": "^8.6.7",
42
+ "markdown-it-emoji": "^3.0.0",
43
+ "mdurl": "^2.0.0",
44
+ "@vuepress/shared": "2.0.0-rc.1",
45
+ "@vuepress/utils": "2.0.0-rc.1"
46
+ },
47
+ "devDependencies": {
48
+ "@types/mdurl": "^1.0.5"
35
49
  },
36
50
  "publishConfig": {
37
51
  "access": "public"
38
52
  },
39
- "gitHead": "edccb16372fabcf160d45ae6207a871e66c81974"
40
- }
53
+ "tsup": {
54
+ "clean": true,
55
+ "dts": "./src/index.ts",
56
+ "entry": [
57
+ "./src/index.ts"
58
+ ],
59
+ "format": [
60
+ "esm"
61
+ ],
62
+ "outDir": "./dist",
63
+ "sourcemap": false,
64
+ "target": "es2022",
65
+ "tsconfig": "../../tsconfig.dts.json"
66
+ },
67
+ "scripts": {
68
+ "build": "tsup",
69
+ "clean": "rimraf dist"
70
+ }
71
+ }