@vuepress/markdown 2.0.0-beta.27 → 2.0.0-beta.33

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.
@@ -21,7 +21,7 @@ const assetsPlugin = (md, { relativePathPrefix = '@source' } = {}) => {
21
21
  // wrap raw html renderer rule
22
22
  const createHtmlRule = (rawHtmlRule) => (tokens, idx, options, env, self) => {
23
23
  // replace the original link with resolved link
24
- tokens[idx].content = tokens[idx].content.replace(/^( *<img\b.*src=")([^"]*)(")/s, (_, prefix, link, suffix) => `${prefix}${(0, resolveLink_1.resolveLink)(link, relativePathPrefix, env)}${suffix}`);
24
+ tokens[idx].content = tokens[idx].content.replace(/(<img\b.*?src=")([^"]*)(")/gs, (_, prefix, link, suffix) => `${prefix}${(0, resolveLink_1.resolveLink)(link, relativePathPrefix, env)}${suffix}`);
25
25
  return rawHtmlRule(tokens, idx, options, env, self);
26
26
  };
27
27
  const rawHtmlBlockRule = md.renderer.rules.html_block;
@@ -1,3 +1,3 @@
1
1
  import type { RuleBlock } from 'markdown-it/lib/parser_block';
2
2
  import type { ImportCodePluginOptions } from './importCodePlugin';
3
- export declare const createImportCodeBlockRule: ({ handleImportPath, }: ImportCodePluginOptions) => RuleBlock;
3
+ export declare const createImportCodeBlockRule: ({ handleImportPath }: ImportCodePluginOptions) => RuleBlock;
@@ -8,7 +8,7 @@ const MIN_LENGTH = 9;
8
8
  const START_CODES = [64, 91, 99, 111, 100, 101];
9
9
  // regexp to match the import syntax
10
10
  const SYNTAX_RE = /^@\[code(?:{(?:(\d+)?-(\d+)?)})?(?: ([^\]]+))?\]\(([^)]*)\)/;
11
- const createImportCodeBlockRule = ({ handleImportPath = (str) => str, }) => (state, startLine, endLine, silent) => {
11
+ const createImportCodeBlockRule = ({ handleImportPath = (str) => str }) => (state, startLine, endLine, silent) => {
12
12
  // if it's indented more than 3 spaces, it should be a code block
13
13
  /* istanbul ignore if */
14
14
  if (state.sCount[startLine] - state.blkIndent >= 4) {
@@ -18,12 +18,6 @@ export interface LinksPluginOptions {
18
18
  * ```
19
19
  */
20
20
  externalAttrs?: Record<string, string>;
21
- /**
22
- * Whether to render an outbound icon to external links
23
- *
24
- * @default true
25
- */
26
- externalIcon?: boolean;
27
21
  }
28
22
  /**
29
23
  * Process links in markdown file
@@ -10,7 +10,6 @@ const resolvePaths_1 = require("./resolvePaths");
10
10
  * - external links: add extra attrs and external icon
11
11
  */
12
12
  const linksPlugin = (md, options = {}) => {
13
- var _a;
14
13
  // tag of internal links
15
14
  const internalTag = options.internalTag || 'RouterLink';
16
15
  // attrs that going to be added to external links
@@ -19,12 +18,8 @@ const linksPlugin = (md, options = {}) => {
19
18
  rel: 'noopener noreferrer',
20
19
  ...options.externalAttrs,
21
20
  };
22
- // external icon
23
- const externalIcon = (_a = options.externalIcon) !== null && _a !== void 0 ? _a : true;
24
21
  let hasOpenInternalLink = false;
25
- let hasOpenExternalLink = false;
26
22
  const handleLinkOpen = (tokens, idx, env) => {
27
- var _a;
28
23
  // get current token
29
24
  const token = tokens[idx];
30
25
  // get `href` attr index
@@ -38,78 +33,64 @@ const linksPlugin = (md, options = {}) => {
38
33
  const hrefAttr = token.attrs[hrefIndex];
39
34
  const hrefLink = hrefAttr[1];
40
35
  // get `base` and `filePathRelative` from `env`
41
- const { base = '/', filePathRelative = null, frontmatter = {} } = env;
36
+ const { base = '/', filePathRelative = null } = env;
42
37
  // check if a link is an external link
43
38
  if ((0, shared_1.isLinkExternal)(hrefLink, base)) {
44
39
  // set `externalAttrs` to current token
45
40
  Object.entries(externalAttrs).forEach(([key, val]) => token.attrSet(key, val));
46
- // check if we should render external icon
47
- if (
48
- // frontmatter should override plugin option
49
- ((_a = frontmatter.externalIcon) !== null && _a !== void 0 ? _a : externalIcon) &&
50
- // only when an external link has `target="_blank"`
51
- // should we render external icon
52
- externalAttrs.target === '_blank') {
53
- hasOpenExternalLink = true;
54
- }
55
41
  return;
56
42
  }
57
43
  // check if a link is an internal link
58
44
  const internalLinkMatch = hrefLink.match(/^((?:.*)(?:\/|\.md|\.html))(#.*)?$/);
59
- if (internalLinkMatch) {
60
- // convert
61
- // <a href="hrefLink">
62
- // to
63
- // <RouterLink to="toProp">
64
- // notice that the path and hash are encoded by markdown-it
65
- const rawPath = internalLinkMatch[1];
66
- const rawHash = internalLinkMatch[2] || '';
67
- // resolve relative and absolute path
68
- const { relativePath, absolutePath } = (0, resolvePaths_1.resolvePaths)(rawPath, base, filePathRelative);
69
- // normalize markdown file path to route path
70
- //
71
- // we are removing the `base` from absolute path because it should not be
72
- // passed to `<RouterLink>`
73
- //
74
- // '/foo/index.md' => '/foo/'
75
- // '/foo/bar.md' => '/foo/bar.html'
76
- const normalizedPath = absolutePath
77
- .replace(new RegExp(`^${base}`), '/')
78
- .replace(/(^|\/)(README|index).md$/i, '$1')
79
- .replace(/\.md$/, '.html');
80
- if (internalTag === 'RouterLink') {
81
- // convert starting tag of internal link to `<RouterLink>`
82
- token.tag = internalTag;
83
- // replace the original `href` attr with `to` attr
84
- hrefAttr[0] = 'to';
85
- // set `hasOpenInternalLink` to modify the ending tag
86
- hasOpenInternalLink = true;
87
- }
88
- hrefAttr[1] = `${normalizedPath}${rawHash}`;
89
- // extract internal links for file / page existence check
90
- const links = env.links || (env.links = []);
91
- links.push({
92
- raw: hrefLink,
93
- relative: relativePath,
94
- absolute: absolutePath,
95
- });
45
+ if (!internalLinkMatch) {
46
+ return;
47
+ }
48
+ // convert
49
+ // <a href="hrefLink">
50
+ // to
51
+ // <RouterLink to="toProp">
52
+ // notice that the path and hash are encoded by markdown-it
53
+ const rawPath = internalLinkMatch[1];
54
+ const rawHash = internalLinkMatch[2] || '';
55
+ // resolve relative and absolute path
56
+ const { relativePath, absolutePath } = (0, resolvePaths_1.resolvePaths)(rawPath, base, filePathRelative);
57
+ // normalize markdown file path to route path
58
+ //
59
+ // we are removing the `base` from absolute path because it should not be
60
+ // passed to `<RouterLink>`
61
+ //
62
+ // '/foo/index.md' => '/foo/'
63
+ // '/foo/bar.md' => '/foo/bar.html'
64
+ const normalizedPath = absolutePath
65
+ .replace(new RegExp(`^${base}`), '/')
66
+ .replace(/(^|\/)(README|index).md$/i, '$1')
67
+ .replace(/\.md$/, '.html');
68
+ if (internalTag === 'RouterLink') {
69
+ // convert starting tag of internal link to `<RouterLink>`
70
+ token.tag = internalTag;
71
+ // replace the original `href` attr with `to` attr
72
+ hrefAttr[0] = 'to';
73
+ // set `hasOpenInternalLink` to modify the ending tag
74
+ hasOpenInternalLink = true;
96
75
  }
76
+ hrefAttr[1] = `${normalizedPath}${rawHash}`;
77
+ // extract internal links for file / page existence check
78
+ const links = env.links || (env.links = []);
79
+ links.push({
80
+ raw: hrefLink,
81
+ relative: relativePath,
82
+ absolute: absolutePath,
83
+ });
97
84
  };
98
85
  md.renderer.rules.link_open = (tokens, idx, options, env, self) => {
99
86
  handleLinkOpen(tokens, idx, env);
100
87
  return self.renderToken(tokens, idx, options);
101
88
  };
102
89
  md.renderer.rules.link_close = (tokens, idx, options, env, self) => {
103
- const token = tokens[idx];
104
- // add external icon before ending tag of external link
105
- if (hasOpenExternalLink) {
106
- hasOpenExternalLink = false;
107
- return '<OutboundLink/>' + self.renderToken(tokens, idx, options);
108
- }
109
90
  // convert ending tag of internal link
110
91
  if (hasOpenInternalLink) {
111
92
  hasOpenInternalLink = false;
112
- token.tag = internalTag;
93
+ tokens[idx].tag = internalTag;
113
94
  }
114
95
  return self.renderToken(tokens, idx, options);
115
96
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vuepress/markdown",
3
- "version": "2.0.0-beta.27",
3
+ "version": "2.0.0-beta.33",
4
4
  "description": "Markdown package of VuePress",
5
5
  "keywords": [
6
6
  "vuepress",
@@ -27,9 +27,9 @@
27
27
  },
28
28
  "dependencies": {
29
29
  "@types/markdown-it": "^12.2.3",
30
- "@vuepress/shared": "2.0.0-beta.27",
31
- "@vuepress/utils": "2.0.0-beta.27",
32
- "markdown-it": "^12.2.0",
30
+ "@vuepress/shared": "2.0.0-beta.33",
31
+ "@vuepress/utils": "2.0.0-beta.33",
32
+ "markdown-it": "^12.3.2",
33
33
  "markdown-it-anchor": "^8.4.1",
34
34
  "markdown-it-emoji": "^2.0.0",
35
35
  "mdurl": "^1.0.1"
@@ -37,5 +37,5 @@
37
37
  "publishConfig": {
38
38
  "access": "public"
39
39
  },
40
- "gitHead": "2671a94fe6864e215eb84f318b7e657744a0bc5d"
40
+ "gitHead": "0934a5d6685922e0dc6391622b00a3b89140492c"
41
41
  }