@vuepress/markdown 2.0.0-rc.0 → 2.0.0-rc.10

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2018-present, Yuxi (Evan) You
3
+ Copyright (c) 2018-present, VuePress Community
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md ADDED
@@ -0,0 +1,12 @@
1
+ # @vuepress/markdown
2
+
3
+ [![npm](https://badgen.net/npm/v/@vuepress/markdown/next)](https://www.npmjs.com/package/@vuepress/markdown)
4
+ [![license](https://badgen.net/github/license/vuepress/core)](https://github.com/vuepress/core/blob/main/LICENSE)
5
+
6
+ ## Documentation
7
+
8
+ https://v2.vuepress.vuejs.org
9
+
10
+ ## License
11
+
12
+ [MIT](https://github.com/vuepress/core/blob/main/LICENSE)
package/dist/index.d.ts CHANGED
@@ -2,7 +2,7 @@ import { SfcPluginOptions } from '@mdit-vue/plugin-sfc';
2
2
  export { MarkdownSfcBlocks, SfcPluginOptions, sfcPlugin } from '@mdit-vue/plugin-sfc';
3
3
  import { MarkdownItEnv } from '@mdit-vue/types';
4
4
  import { PageHeader, PageFrontmatter } from '@vuepress/shared';
5
- import MarkdownIt, { PluginWithOptions } from 'markdown-it';
5
+ import MarkdownIt, { PluginWithOptions, Options as Options$1 } from 'markdown-it';
6
6
  import { FrontmatterPluginOptions } from '@mdit-vue/plugin-frontmatter';
7
7
  export { FrontmatterPluginOptions, frontmatterPlugin } from '@mdit-vue/plugin-frontmatter';
8
8
  import { HeadersPluginOptions } from '@mdit-vue/plugin-headers';
@@ -11,14 +11,18 @@ import { TocPluginOptions } from '@mdit-vue/plugin-toc';
11
11
  export { TocPluginOptions, tocPlugin } from '@mdit-vue/plugin-toc';
12
12
  import anchorPlugin from 'markdown-it-anchor';
13
13
  export { default as anchorPlugin } from 'markdown-it-anchor';
14
- import emojiPlugin from 'markdown-it-emoji';
15
- export { default as emojiPlugin } from 'markdown-it-emoji';
14
+ import { Options } from 'markdown-it-emoji';
15
+ export { full as emojiPlugin } from 'markdown-it-emoji';
16
16
  export { ComponentPluginOptions, componentPlugin } from '@mdit-vue/plugin-component';
17
17
  export { titlePlugin } from '@mdit-vue/plugin-title';
18
18
 
19
19
  type AnchorPluginOptions = anchorPlugin.AnchorOptions;
20
20
 
21
21
  interface AssetsPluginOptions {
22
+ /**
23
+ * Whether to prepend base to absolute path
24
+ */
25
+ absolutePathPrependBase?: boolean;
22
26
  /**
23
27
  * Prefix to add to relative assets links
24
28
  */
@@ -47,7 +51,7 @@ interface CodePluginOptions {
47
51
  *
48
52
  * - Required for `highlightLines`
49
53
  * - Required for `lineNumbers`
50
- * - Required for language display of default theme
54
+ * - Required for title display of default theme
51
55
  */
52
56
  preWrapper?: boolean;
53
57
  /**
@@ -69,7 +73,7 @@ interface CodePluginOptions {
69
73
  */
70
74
  declare const codePlugin: PluginWithOptions<CodePluginOptions>;
71
75
 
72
- type EmojiPluginOptions = emojiPlugin.Options;
76
+ type EmojiPluginOptions = Options;
73
77
 
74
78
  interface ImportCodePluginOptions {
75
79
  /**
@@ -83,9 +87,9 @@ interface LinksPluginOptions {
83
87
  /**
84
88
  * Tag for internal links
85
89
  *
86
- * @default 'RouterLink'
90
+ * @default 'RouteLink'
87
91
  */
88
- internalTag?: 'a' | 'RouterLink';
92
+ internalTag?: 'a' | 'RouteLink' | 'RouterLink';
89
93
  /**
90
94
  * Additional attributes for external links
91
95
  *
@@ -102,14 +106,14 @@ interface LinksPluginOptions {
102
106
  /**
103
107
  * Process links in markdown file
104
108
  *
105
- * - internal links: convert them into `<RouterLink>`
106
- * - external links: add extra attrs and external icon
109
+ * - internal links: convert `<a>` tag into internalTag
110
+ * - external links: add extra attrs
107
111
  */
108
112
  declare const linksPlugin: PluginWithOptions<LinksPluginOptions>;
109
113
 
110
114
  type Markdown = MarkdownIt;
111
115
 
112
- interface MarkdownOptions extends MarkdownIt.Options {
116
+ interface MarkdownOptions extends Options$1 {
113
117
  anchor?: false | AnchorPluginOptions;
114
118
  assets?: false | AssetsPluginOptions;
115
119
  code?: false | CodePluginOptions;
@@ -136,7 +140,7 @@ type MarkdownHeader = PageHeader;
136
140
  interface MarkdownLink {
137
141
  raw: string;
138
142
  relative: string;
139
- absolute: string;
143
+ absolute: string | null;
140
144
  }
141
145
  /**
142
146
  * The `env` object to be passed to markdown-it render function
@@ -181,4 +185,4 @@ type MarkdownSlugifyFunction = (str: string) => string;
181
185
  */
182
186
  declare const createMarkdown: ({ anchor, assets, code, component, emoji, frontmatter, headers, title, importCode, links, sfc, slugify, toc, ...markdownItOptions }?: MarkdownOptions) => Markdown;
183
187
 
184
- export { AnchorPluginOptions, AssetsPluginOptions, CodePluginOptions, EmojiPluginOptions, ImportCodePluginOptions, LinksPluginOptions, Markdown, MarkdownEnv, MarkdownHeader, MarkdownLink, MarkdownOptions, MarkdownSlugifyFunction, assetsPlugin, codePlugin, createMarkdown, importCodePlugin, linksPlugin };
188
+ export { type AnchorPluginOptions, type AssetsPluginOptions, type CodePluginOptions, type EmojiPluginOptions, type ImportCodePluginOptions, type LinksPluginOptions, type Markdown, type MarkdownEnv, type MarkdownHeader, type MarkdownLink, type MarkdownOptions, type MarkdownSlugifyFunction, assetsPlugin, codePlugin, createMarkdown, importCodePlugin, linksPlugin };
package/dist/index.js CHANGED
@@ -28,7 +28,12 @@ import { default as anchorPlugin } from "markdown-it-anchor";
28
28
  // src/plugins/assetsPlugin/resolveLink.ts
29
29
  import { path } from "@vuepress/utils";
30
30
  import { decode } from "mdurl";
31
- var resolveLink = (link, relativePathPrefix, env, strict = false) => {
31
+ var resolveLink = (link, {
32
+ env,
33
+ absolutePathPrependBase = false,
34
+ relativePathPrefix,
35
+ strict = false
36
+ }) => {
32
37
  if (link.startsWith("data:"))
33
38
  return link;
34
39
  let resolvedLink = decode(link);
@@ -45,40 +50,49 @@ var resolveLink = (link, relativePathPrefix, env, strict = false) => {
45
50
  resolvedLink
46
51
  )}`;
47
52
  }
53
+ if (absolutePathPrependBase && env.base && link.startsWith("/")) {
54
+ resolvedLink = path.join(env.base, resolvedLink);
55
+ }
48
56
  return resolvedLink;
49
57
  };
50
58
 
51
59
  // src/plugins/assetsPlugin/assetsPlugin.ts
52
- var assetsPlugin = (md, { relativePathPrefix = "@source" } = {}) => {
60
+ var assetsPlugin = (md, {
61
+ absolutePathPrependBase = false,
62
+ relativePathPrefix = "@source"
63
+ } = {}) => {
53
64
  const rawImageRule = md.renderer.rules.image;
54
65
  md.renderer.rules.image = (tokens, idx, options, env, self) => {
55
66
  const token = tokens[idx];
56
67
  const link = token.attrGet("src");
57
68
  if (link) {
58
- token.attrSet("src", resolveLink(link, relativePathPrefix, env));
69
+ token.attrSet(
70
+ "src",
71
+ resolveLink(link, { env, absolutePathPrependBase, relativePathPrefix })
72
+ );
59
73
  }
60
74
  return rawImageRule(tokens, idx, options, env, self);
61
75
  };
62
76
  const createHtmlRule = (rawHtmlRule) => (tokens, idx, options, env, self) => {
63
77
  tokens[idx].content = tokens[idx].content.replace(
64
78
  /(<img\b.*?src=)(['"])([^\2]*?)\2/gs,
65
- (_, prefix, quote, src) => `${prefix}${quote}${resolveLink(
66
- src.trim(),
67
- relativePathPrefix,
79
+ (_, prefix, quote, src) => `${prefix}${quote}${resolveLink(src.trim(), {
68
80
  env,
69
- true
70
- )}${quote}`
81
+ absolutePathPrependBase,
82
+ relativePathPrefix,
83
+ strict: true
84
+ })}${quote}`
71
85
  ).replace(
72
86
  /(<img\b.*?srcset=)(['"])([^\2]*?)\2/gs,
73
87
  (_, prefix, quote, srcset) => `${prefix}${quote}${srcset.split(",").map(
74
88
  (item) => item.trim().replace(
75
89
  /^([^ ]*?)([ \n].*)?$/,
76
- (_2, url, descriptor = "") => `${resolveLink(
77
- url.trim(),
78
- relativePathPrefix,
90
+ (_2, url, descriptor = "") => `${resolveLink(url.trim(), {
79
91
  env,
80
- true
81
- )}${descriptor.replace(/[ \n]+/g, " ").trimEnd()}`
92
+ absolutePathPrependBase,
93
+ relativePathPrefix,
94
+ strict: true
95
+ })}${descriptor.replace(/[ \n]+/g, " ").trimEnd()}`
82
96
  )
83
97
  ).join(", ")}${quote}`
84
98
  );
@@ -90,6 +104,14 @@ var assetsPlugin = (md, { relativePathPrefix = "@source" } = {}) => {
90
104
  md.renderer.rules.html_inline = createHtmlRule(rawHtmlInlineRule);
91
105
  };
92
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
+
93
115
  // src/plugins/codePlugin/resolveHighlightLines.ts
94
116
  var resolveHighlightLines = (info) => {
95
117
  const match = info.match(/{([\d,-]+)}/);
@@ -271,7 +293,8 @@ var codePlugin = (md, {
271
293
  const lineNumbersCode = lines.map(() => `<div class="line-number"></div>`).join("");
272
294
  result = `${result}<div class="line-numbers" aria-hidden="true">${lineNumbersCode}</div>`;
273
295
  }
274
- result = `<div class="${languageClass}${useLineNumbers ? " line-numbers-mode" : ""}" data-ext="${language.ext}">${result}</div>`;
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>`;
275
298
  return result;
276
299
  };
277
300
  if (vPreInline) {
@@ -284,7 +307,7 @@ var codePlugin = (md, {
284
307
  };
285
308
 
286
309
  // src/plugins/emojiPlugin.ts
287
- import emojiPlugin from "markdown-it-emoji";
310
+ import { full as emojiPlugin } from "markdown-it-emoji";
288
311
 
289
312
  // src/plugins/importCodePlugin/createImportCodeBlockRule.ts
290
313
  import { path as path2 } from "@vuepress/utils";
@@ -377,7 +400,7 @@ var importCodePlugin = (md, options = {}) => {
377
400
  };
378
401
 
379
402
  // src/plugins/linksPlugin/linksPlugin.ts
380
- import { isLinkExternal } from "@vuepress/shared";
403
+ import { inferRoutePath, isLinkExternal } from "@vuepress/shared";
381
404
 
382
405
  // src/plugins/linksPlugin/resolvePaths.ts
383
406
  import { removeLeadingSlash } from "@vuepress/shared";
@@ -403,7 +426,7 @@ var resolvePaths = (rawPath, base, filePathRelative) => {
403
426
  absolutePath = path4.join(base, relativePath);
404
427
  } else {
405
428
  relativePath = rawPath.replace(/^(?:\.\/)?(.*)$/, "$1");
406
- absolutePath = relativePath;
429
+ absolutePath = null;
407
430
  }
408
431
  }
409
432
  return {
@@ -414,7 +437,7 @@ var resolvePaths = (rawPath, base, filePathRelative) => {
414
437
 
415
438
  // src/plugins/linksPlugin/linksPlugin.ts
416
439
  var linksPlugin = (md, options = {}) => {
417
- const internalTag = options.internalTag || "RouterLink";
440
+ const internalTag = options.internalTag || "RouteLink";
418
441
  const externalAttrs = {
419
442
  target: "_blank",
420
443
  rel: "noopener noreferrer",
@@ -437,25 +460,31 @@ var linksPlugin = (md, options = {}) => {
437
460
  return;
438
461
  }
439
462
  const internalLinkMatch = hrefLink.match(
440
- /^((?:.*)(?:\/|\.md|\.html))(#.*)?$/
463
+ /^([^#?]*?(?:\/|\.md|\.html))([#?].*)?$/
441
464
  );
442
465
  if (!internalLinkMatch) {
443
466
  return;
444
467
  }
445
468
  const rawPath = internalLinkMatch[1];
446
- const rawHash = internalLinkMatch[2] || "";
469
+ const rawHashAndQueries = internalLinkMatch[2] || "";
447
470
  const { relativePath, absolutePath } = resolvePaths(
448
471
  rawPath,
449
472
  base,
450
473
  filePathRelative
451
474
  );
452
- const normalizedPath = absolutePath.replace(new RegExp(`^${base}`), "/").replace(/(^|\/)(README|index).md$/i, "$1").replace(/\.md$/, ".html");
453
- if (internalTag === "RouterLink") {
475
+ if (["RouterLink", "RouteLink"].includes(internalTag)) {
454
476
  token.tag = internalTag;
455
477
  hrefAttr[0] = "to";
478
+ const normalizedPath = inferRoutePath(
479
+ absolutePath ? absolutePath.replace(new RegExp(`^${base}`), "/") : relativePath
480
+ );
481
+ hrefAttr[1] = `${normalizedPath}${rawHashAndQueries}`;
456
482
  hasOpenInternalLink = true;
483
+ } else {
484
+ const normalizedPath = inferRoutePath(absolutePath ?? relativePath);
485
+ hrefAttr[1] = `${normalizedPath}${rawHashAndQueries}`;
457
486
  }
458
- hrefAttr[1] = `${normalizedPath}${rawHash}`;
487
+ ;
459
488
  (env.links ??= []).push({
460
489
  raw: hrefLink,
461
490
  relative: relativePath,
@@ -466,7 +495,7 @@ var linksPlugin = (md, options = {}) => {
466
495
  handleLinkOpen(tokens, idx, env);
467
496
  return self.renderToken(tokens, idx, options2);
468
497
  };
469
- md.renderer.rules.link_close = (tokens, idx, options2, env, self) => {
498
+ md.renderer.rules.link_close = (tokens, idx, options2, _env, self) => {
470
499
  if (hasOpenInternalLink) {
471
500
  hasOpenInternalLink = false;
472
501
  tokens[idx].tag = internalTag;
@@ -501,11 +530,10 @@ var createMarkdown = ({
501
530
  md.use(anchorPlugin, {
502
531
  level: [1, 2, 3, 4, 5, 6],
503
532
  slugify,
504
- permalink: anchorPlugin.permalink.ariaHidden({
533
+ permalink: anchorPlugin.permalink.headerLink({
505
534
  class: "header-anchor",
506
- symbol: "#",
507
- space: true,
508
- placement: "before"
535
+ // Add a span inside the link so Safari shows headings in reader view.
536
+ safariReaderFix: true
509
537
  }),
510
538
  ...anchor
511
539
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vuepress/markdown",
3
- "version": "2.0.0-rc.0",
3
+ "version": "2.0.0-rc.10",
4
4
  "description": "Markdown package of VuePress",
5
5
  "keywords": [
6
6
  "vuepress",
@@ -8,11 +8,11 @@
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
18
  "author": "meteorlxy",
@@ -27,25 +27,25 @@
27
27
  "dist"
28
28
  ],
29
29
  "dependencies": {
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",
30
+ "@mdit-vue/plugin-component": "^2.1.3",
31
+ "@mdit-vue/plugin-frontmatter": "^2.1.3",
32
+ "@mdit-vue/plugin-headers": "^2.1.3",
33
+ "@mdit-vue/plugin-sfc": "^2.1.3",
34
+ "@mdit-vue/plugin-title": "^2.1.3",
35
+ "@mdit-vue/plugin-toc": "^2.1.3",
36
+ "@mdit-vue/shared": "^2.1.3",
37
+ "@mdit-vue/types": "^2.1.0",
38
+ "@types/markdown-it": "^14.1.1",
39
+ "@types/markdown-it-emoji": "^3.0.1",
40
+ "markdown-it": "^14.1.0",
41
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"
42
+ "markdown-it-emoji": "^3.0.0",
43
+ "mdurl": "^2.0.0",
44
+ "@vuepress/shared": "2.0.0-rc.10",
45
+ "@vuepress/utils": "2.0.0-rc.10"
46
46
  },
47
47
  "devDependencies": {
48
- "@types/mdurl": "^1.0.5"
48
+ "@types/mdurl": "^2.0.0"
49
49
  },
50
50
  "publishConfig": {
51
51
  "access": "public"
@@ -62,7 +62,7 @@
62
62
  "outDir": "./dist",
63
63
  "sourcemap": false,
64
64
  "target": "es2022",
65
- "tsconfig": "../tsconfig.dts.json"
65
+ "tsconfig": "../../tsconfig.dts.json"
66
66
  },
67
67
  "scripts": {
68
68
  "build": "tsup",