@vuepress/markdown 2.0.0-rc.1 → 2.0.0-rc.11

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/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';
@@ -87,9 +87,9 @@ interface LinksPluginOptions {
87
87
  /**
88
88
  * Tag for internal links
89
89
  *
90
- * @default 'RouterLink'
90
+ * @default 'RouteLink'
91
91
  */
92
- internalTag?: 'a' | 'RouterLink';
92
+ internalTag?: 'a' | 'RouteLink' | 'RouterLink';
93
93
  /**
94
94
  * Additional attributes for external links
95
95
  *
@@ -106,14 +106,14 @@ interface LinksPluginOptions {
106
106
  /**
107
107
  * Process links in markdown file
108
108
  *
109
- * - internal links: convert them into `<RouterLink>`
110
- * - external links: add extra attrs and external icon
109
+ * - internal links: convert `<a>` tag into internalTag
110
+ * - external links: add extra attrs
111
111
  */
112
112
  declare const linksPlugin: PluginWithOptions<LinksPluginOptions>;
113
113
 
114
114
  type Markdown = MarkdownIt;
115
115
 
116
- interface MarkdownOptions extends MarkdownIt.Options {
116
+ interface MarkdownOptions extends Options$1 {
117
117
  anchor?: false | AnchorPluginOptions;
118
118
  assets?: false | AssetsPluginOptions;
119
119
  code?: false | CodePluginOptions;
@@ -140,7 +140,7 @@ type MarkdownHeader = PageHeader;
140
140
  interface MarkdownLink {
141
141
  raw: string;
142
142
  relative: string;
143
- absolute: string;
143
+ absolute: string | null;
144
144
  }
145
145
  /**
146
146
  * The `env` object to be passed to markdown-it render function
package/dist/index.js CHANGED
@@ -400,7 +400,7 @@ var importCodePlugin = (md, options = {}) => {
400
400
  };
401
401
 
402
402
  // src/plugins/linksPlugin/linksPlugin.ts
403
- import { isLinkExternal } from "@vuepress/shared";
403
+ import { inferRoutePath, isLinkExternal } from "@vuepress/shared";
404
404
 
405
405
  // src/plugins/linksPlugin/resolvePaths.ts
406
406
  import { removeLeadingSlash } from "@vuepress/shared";
@@ -426,7 +426,7 @@ var resolvePaths = (rawPath, base, filePathRelative) => {
426
426
  absolutePath = path4.join(base, relativePath);
427
427
  } else {
428
428
  relativePath = rawPath.replace(/^(?:\.\/)?(.*)$/, "$1");
429
- absolutePath = relativePath;
429
+ absolutePath = null;
430
430
  }
431
431
  }
432
432
  return {
@@ -437,7 +437,7 @@ var resolvePaths = (rawPath, base, filePathRelative) => {
437
437
 
438
438
  // src/plugins/linksPlugin/linksPlugin.ts
439
439
  var linksPlugin = (md, options = {}) => {
440
- const internalTag = options.internalTag || "RouterLink";
440
+ const internalTag = options.internalTag || "RouteLink";
441
441
  const externalAttrs = {
442
442
  target: "_blank",
443
443
  rel: "noopener noreferrer",
@@ -460,25 +460,31 @@ var linksPlugin = (md, options = {}) => {
460
460
  return;
461
461
  }
462
462
  const internalLinkMatch = hrefLink.match(
463
- /^((?:.*)(?:\/|\.md|\.html))(#.*)?$/
463
+ /^([^#?]*?(?:\/|\.md|\.html))([#?].*)?$/
464
464
  );
465
465
  if (!internalLinkMatch) {
466
466
  return;
467
467
  }
468
468
  const rawPath = internalLinkMatch[1];
469
- const rawHash = internalLinkMatch[2] || "";
469
+ const rawHashAndQueries = internalLinkMatch[2] || "";
470
470
  const { relativePath, absolutePath } = resolvePaths(
471
471
  rawPath,
472
472
  base,
473
473
  filePathRelative
474
474
  );
475
- const normalizedPath = absolutePath.replace(new RegExp(`^${base}`), "/").replace(/(^|\/)(README|index).md$/i, "$1").replace(/\.md$/, ".html");
476
- if (internalTag === "RouterLink") {
475
+ if (["RouterLink", "RouteLink"].includes(internalTag)) {
477
476
  token.tag = internalTag;
478
477
  hrefAttr[0] = "to";
478
+ const normalizedPath = inferRoutePath(
479
+ absolutePath ? absolutePath.replace(new RegExp(`^${base}`), "/") : relativePath
480
+ );
481
+ hrefAttr[1] = `${normalizedPath}${rawHashAndQueries}`;
479
482
  hasOpenInternalLink = true;
483
+ } else {
484
+ const normalizedPath = inferRoutePath(absolutePath ?? relativePath);
485
+ hrefAttr[1] = `${normalizedPath}${rawHashAndQueries}`;
480
486
  }
481
- hrefAttr[1] = `${normalizedPath}${rawHash}`;
487
+ ;
482
488
  (env.links ??= []).push({
483
489
  raw: hrefLink,
484
490
  relative: relativePath,
@@ -489,7 +495,7 @@ var linksPlugin = (md, options = {}) => {
489
495
  handleLinkOpen(tokens, idx, env);
490
496
  return self.renderToken(tokens, idx, options2);
491
497
  };
492
- md.renderer.rules.link_close = (tokens, idx, options2, env, self) => {
498
+ md.renderer.rules.link_close = (tokens, idx, options2, _env, self) => {
493
499
  if (hasOpenInternalLink) {
494
500
  hasOpenInternalLink = false;
495
501
  tokens[idx].tag = internalTag;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vuepress/markdown",
3
- "version": "2.0.0-rc.1",
3
+ "version": "2.0.0-rc.11",
4
4
  "description": "Markdown package of VuePress",
5
5
  "keywords": [
6
6
  "vuepress",
@@ -27,25 +27,25 @@
27
27
  "dist"
28
28
  ],
29
29
  "dependencies": {
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",
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
42
  "markdown-it-emoji": "^3.0.0",
43
43
  "mdurl": "^2.0.0",
44
- "@vuepress/shared": "2.0.0-rc.1",
45
- "@vuepress/utils": "2.0.0-rc.1"
44
+ "@vuepress/shared": "2.0.0-rc.11",
45
+ "@vuepress/utils": "2.0.0-rc.11"
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"