@vuepress/markdown 2.0.0-rc.29 → 2.0.0-rc.30
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 +16 -0
- package/dist/index.js +15 -7
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -19,6 +19,22 @@ interface AssetsPluginOptions {
|
|
|
19
19
|
* Whether to prepend base to absolute path
|
|
20
20
|
*/
|
|
21
21
|
absolutePathPrependBase?: boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Use aliases for non-strict relative paths.
|
|
24
|
+
*
|
|
25
|
+
* This is a path that does not start
|
|
26
|
+
* with `./` or `../` or `/` or `<protocol header>`:
|
|
27
|
+
* `<img src="path1/path2.png" />`
|
|
28
|
+
*
|
|
29
|
+
* - If the option is `true`. `path1` is regarded as an alias.
|
|
30
|
+
* - If the option is `false`. It is regarded as a relative path.
|
|
31
|
+
* - If the option is `"@-prefix"`.
|
|
32
|
+
* If the path starts with `@`, `path1` is regarded as an alias;
|
|
33
|
+
* Otherwise, it is regarded as a relative path.
|
|
34
|
+
*
|
|
35
|
+
* @default true
|
|
36
|
+
*/
|
|
37
|
+
aliasSupport?: boolean | '@-prefix';
|
|
22
38
|
}
|
|
23
39
|
/**
|
|
24
40
|
* Plugin to handle assets links
|
package/dist/index.js
CHANGED
|
@@ -12,9 +12,14 @@ import { decode } from "mdurl";
|
|
|
12
12
|
import { full as emojiPlugin } from "markdown-it-emoji";
|
|
13
13
|
import { inferRoutePath, isLinkExternal, removeLeadingSlash } from "@vuepress/shared";
|
|
14
14
|
//#region src/plugins/assetsPlugin/resolveLink.ts
|
|
15
|
-
const resolveLink = (link, { env, absolutePathPrependBase = false }) => {
|
|
15
|
+
const resolveLink = (link, { env, absolutePathPrependBase = false, aliasSupport = true }) => {
|
|
16
16
|
if (link.startsWith("data:")) return link;
|
|
17
17
|
let resolvedLink = decode(link);
|
|
18
|
+
if (aliasSupport === false || aliasSupport === "@-prefix") {
|
|
19
|
+
if (!(link.startsWith("/") || link.startsWith("./") || link.startsWith("../") || /[A-Za-z]+:\/\//.test(link))) {
|
|
20
|
+
if (aliasSupport === false || !link.startsWith("@")) resolvedLink = `./${resolvedLink}`;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
18
23
|
if (absolutePathPrependBase && env.base && link.startsWith("/")) resolvedLink = path.join(env.base, resolvedLink);
|
|
19
24
|
return resolvedLink;
|
|
20
25
|
};
|
|
@@ -23,24 +28,27 @@ const resolveLink = (link, { env, absolutePathPrependBase = false }) => {
|
|
|
23
28
|
/**
|
|
24
29
|
* Plugin to handle assets links
|
|
25
30
|
*/
|
|
26
|
-
const assetsPlugin = (md, { absolutePathPrependBase = false } = {}) => {
|
|
31
|
+
const assetsPlugin = (md, { absolutePathPrependBase = false, aliasSupport = true } = {}) => {
|
|
27
32
|
const rawImageRule = md.renderer.rules.image;
|
|
28
33
|
md.renderer.rules.image = (tokens, idx, options, env, self) => {
|
|
29
34
|
const token = tokens[idx];
|
|
30
35
|
const link = token.attrGet("src");
|
|
31
36
|
if (link) token.attrSet("src", resolveLink(link, {
|
|
32
37
|
env,
|
|
33
|
-
absolutePathPrependBase
|
|
38
|
+
absolutePathPrependBase,
|
|
39
|
+
aliasSupport
|
|
34
40
|
}));
|
|
35
41
|
return rawImageRule(tokens, idx, options, env, self);
|
|
36
42
|
};
|
|
37
43
|
const createHtmlRule = (rawHtmlRule) => (tokens, idx, options, env, self) => {
|
|
38
|
-
tokens[idx].content = tokens[idx].content.replace(/(<img\b
|
|
44
|
+
tokens[idx].content = tokens[idx].content.replace(/(<(?:img|source|video|audio)\b.*?\bsrc=)(['"])(.*?)\2/gs, (_, prefix, quote, src) => `${prefix}${quote}${resolveLink(src.trim(), {
|
|
39
45
|
env,
|
|
40
|
-
absolutePathPrependBase
|
|
41
|
-
|
|
46
|
+
absolutePathPrependBase,
|
|
47
|
+
aliasSupport
|
|
48
|
+
})}${quote}`).replace(/(<(?:img|source|video|audio)\b.*?\bsrcset=)(['"])(.*?)\2/gs, (_, prefix, quote, srcset) => `${prefix}${quote}${srcset.split(",").map((item) => item.trim().replace(/^([^ ]*?)([ \n].*)?$/, (__, url, descriptor = "") => `${resolveLink(url.trim(), {
|
|
42
49
|
env,
|
|
43
|
-
absolutePathPrependBase
|
|
50
|
+
absolutePathPrependBase,
|
|
51
|
+
aliasSupport
|
|
44
52
|
})}${descriptor.replace(/[ \n]+/g, " ").trimEnd()}`)).join(", ")}${quote}`);
|
|
45
53
|
return rawHtmlRule(tokens, idx, options, env, self);
|
|
46
54
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vuepress/markdown",
|
|
3
|
-
"version": "2.0.0-rc.
|
|
3
|
+
"version": "2.0.0-rc.30",
|
|
4
4
|
"description": "Markdown package of VuePress",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"markdown",
|
|
@@ -45,8 +45,8 @@
|
|
|
45
45
|
"markdown-it-anchor": "^9.2.0",
|
|
46
46
|
"markdown-it-emoji": "^3.0.0",
|
|
47
47
|
"mdurl": "^2.0.0",
|
|
48
|
-
"@vuepress/shared": "2.0.0-rc.
|
|
49
|
-
"@vuepress/utils": "2.0.0-rc.
|
|
48
|
+
"@vuepress/shared": "2.0.0-rc.30",
|
|
49
|
+
"@vuepress/utils": "2.0.0-rc.30"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
52
|
"@types/mdurl": "^2.0.0"
|