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