@vuepress/markdown 2.0.0-beta.21 → 2.0.0-beta.22

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.
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.assetsPlugin = void 0;
4
+ const resolveLink_1 = require("./resolveLink");
5
+ /**
6
+ * Plugin to handle assets links
7
+ */
8
+ const assetsPlugin = (md, { relativePathPrefix = '@source' } = {}) => {
9
+ // wrap raw image renderer rule
10
+ const rawImageRule = md.renderer.rules.image;
11
+ md.renderer.rules.image = (tokens, idx, options, env, self) => {
12
+ const token = tokens[idx];
13
+ // get the image link
14
+ const link = token.attrGet('src');
15
+ if (link) {
16
+ // replace the original link with resolved link
17
+ token.attrSet('src', resolveLink_1.resolveLink(link, relativePathPrefix, env));
18
+ }
19
+ return rawImageRule(tokens, idx, options, env, self);
20
+ };
21
+ // wrap raw html renderer rule
22
+ const createHtmlRule = (rawHtmlRule) => (tokens, idx, options, env, self) => {
23
+ // replace the original link with resolved link
24
+ tokens[idx].content = tokens[idx].content.replace(/^( *<img\b.*src=")([^"]*)(")/s, (_, prefix, link, suffix) => `${prefix}${resolveLink_1.resolveLink(link, relativePathPrefix, env)}${suffix}`);
25
+ return rawHtmlRule(tokens, idx, options, env, self);
26
+ };
27
+ const rawHtmlBlockRule = md.renderer.rules.html_block;
28
+ const rawHtmlInlineRule = md.renderer.rules.html_inline;
29
+ md.renderer.rules.html_block = createHtmlRule(rawHtmlBlockRule);
30
+ md.renderer.rules.html_inline = createHtmlRule(rawHtmlInlineRule);
31
+ };
32
+ exports.assetsPlugin = assetsPlugin;
@@ -0,0 +1,2 @@
1
+ export * from './assetsPlugin';
2
+ export * from './resolveLink';
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
+ };
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ __exportStar(require("./assetsPlugin"), exports);
14
+ __exportStar(require("./resolveLink"), exports);
@@ -0,0 +1,2 @@
1
+ import type { MarkdownEnv } from '../../types';
2
+ export declare const resolveLink: (link: string, relativePathPrefix: string, env: MarkdownEnv) => string;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.resolveLink = void 0;
4
+ const utils_1 = require("@vuepress/utils");
5
+ const mdurl_1 = require("mdurl");
6
+ const resolveLink = (link, relativePathPrefix, env) => {
7
+ // decode link to ensure bundler can find the file correctly
8
+ let resolvedLink = mdurl_1.decode(link);
9
+ // if the link is relative path, and the `env.filePathRelative` exists
10
+ // add `@source` alias to the link
11
+ if (/^\.{1,2}\//.test(link) && env.filePathRelative) {
12
+ resolvedLink = `${relativePathPrefix}/${utils_1.path.join(utils_1.path.dirname(env.filePathRelative), resolvedLink)}`;
13
+ }
14
+ return resolvedLink;
15
+ };
16
+ exports.resolveLink = resolveLink;
@@ -12,7 +12,8 @@ const hoistTagsPlugin = (md, { customBlocks = [] } = {}) => {
12
12
  // hoist <script>, <style> and other user defined tags
13
13
  const hoistTags = Array.from(new Set(['script', 'style', ...customBlocks]));
14
14
  const hoistTagsRegexp = new RegExp(`^<(${hoistTags.join('|')})(?=(\\s|>|$))`, 'i');
15
- md.renderer.rules.html_block = (tokens, idx, _, env) => {
15
+ const rawRule = md.renderer.rules.html_block;
16
+ md.renderer.rules.html_block = (tokens, idx, options, env, self) => {
16
17
  const content = tokens[idx].content;
17
18
  const hoistedTags = env.hoistedTags || (env.hoistedTags = []);
18
19
  // record the hoisted tags to env and do not render them
@@ -20,7 +21,7 @@ const hoistTagsPlugin = (md, { customBlocks = [] } = {}) => {
20
21
  hoistedTags.push(content);
21
22
  return '';
22
23
  }
23
- return content;
24
+ return rawRule(tokens, idx, options, env, self);
24
25
  };
25
26
  };
26
27
  exports.hoistTagsPlugin = hoistTagsPlugin;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vuepress/markdown",
3
- "version": "2.0.0-beta.21",
3
+ "version": "2.0.0-beta.22",
4
4
  "description": "Markdown package of VuePress",
5
5
  "keywords": [
6
6
  "vuepress",
@@ -37,5 +37,5 @@
37
37
  "publishConfig": {
38
38
  "access": "public"
39
39
  },
40
- "gitHead": "75cba56b201fd4124e6cfbf5d0baa913063c9b40"
40
+ "gitHead": "8db8d235df8914c70c864ae3f3f66f93cfd1a457"
41
41
  }
@@ -1,30 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.assetsPlugin = void 0;
4
- const mdurl_1 = require("mdurl");
5
- const utils_1 = require("@vuepress/utils");
6
- /**
7
- * Plugin to handle assets links
8
- */
9
- const assetsPlugin = (md, { relativePathPrefix = '@source' } = {}) => {
10
- const rawRule = md.renderer.rules.image;
11
- md.renderer.rules.image = (tokens, idx, options, env, self) => {
12
- const token = tokens[idx];
13
- // get the image link
14
- const link = token.attrGet('src');
15
- if (!link) {
16
- return rawRule(tokens, idx, options, env, self);
17
- }
18
- // decode link to ensure bundler can find the file correctly
19
- let resolvedLink = mdurl_1.decode(link);
20
- // if the link is relative path, and the `env.filePathRelative` exists
21
- // add `@source` alias to the link
22
- if (/^\.{1,2}\//.test(link) && env.filePathRelative) {
23
- resolvedLink = `${relativePathPrefix}/${utils_1.path.join(utils_1.path.dirname(env.filePathRelative), resolvedLink)}`;
24
- }
25
- // replace the original link with resolved link
26
- token.attrSet('src', resolvedLink);
27
- return rawRule(tokens, idx, options, env, self);
28
- };
29
- };
30
- exports.assetsPlugin = assetsPlugin;