@vuepress/markdown 2.0.0-rc.2 → 2.0.0-rc.20
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/README.md +1 -1
- package/dist/index.d.ts +49 -64
- package/dist/index.js +99 -257
- package/package.json +16 -16
package/README.md
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
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
|
-
import {
|
|
5
|
-
import MarkdownIt, { PluginWithOptions } from 'markdown-it';
|
|
4
|
+
import { PageFrontmatter, PageHeader } from '@vuepress/shared';
|
|
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';
|
|
@@ -33,46 +33,6 @@ interface AssetsPluginOptions {
|
|
|
33
33
|
*/
|
|
34
34
|
declare const assetsPlugin: PluginWithOptions<AssetsPluginOptions>;
|
|
35
35
|
|
|
36
|
-
interface CodePluginOptions {
|
|
37
|
-
/**
|
|
38
|
-
* Enable highlight lines or not
|
|
39
|
-
*/
|
|
40
|
-
highlightLines?: boolean;
|
|
41
|
-
/**
|
|
42
|
-
* Enable line numbers or not
|
|
43
|
-
*
|
|
44
|
-
* - A `boolean` value is to enable line numbers or not.
|
|
45
|
-
* - A `number` value is the minimum number of lines to enable line numbers
|
|
46
|
-
*/
|
|
47
|
-
lineNumbers?: boolean | number;
|
|
48
|
-
/**
|
|
49
|
-
* Wrap the `<pre>` tag with an extra `<div>` or not. Do not disable it unless you
|
|
50
|
-
* understand what's it for
|
|
51
|
-
*
|
|
52
|
-
* - Required for `highlightLines`
|
|
53
|
-
* - Required for `lineNumbers`
|
|
54
|
-
* - Required for title display of default theme
|
|
55
|
-
*/
|
|
56
|
-
preWrapper?: boolean;
|
|
57
|
-
/**
|
|
58
|
-
* Add `v-pre` directive or not
|
|
59
|
-
*/
|
|
60
|
-
vPre?: {
|
|
61
|
-
/**
|
|
62
|
-
* Add `v-pre` directive to `<pre>` tag of code block or not
|
|
63
|
-
*/
|
|
64
|
-
block?: boolean;
|
|
65
|
-
/**
|
|
66
|
-
* Add `v-pre` directive to `<code>` tag of inline code or not
|
|
67
|
-
*/
|
|
68
|
-
inline?: boolean;
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* Code plugin
|
|
73
|
-
*/
|
|
74
|
-
declare const codePlugin: PluginWithOptions<CodePluginOptions>;
|
|
75
|
-
|
|
76
36
|
type EmojiPluginOptions = Options;
|
|
77
37
|
|
|
78
38
|
interface ImportCodePluginOptions {
|
|
@@ -84,12 +44,6 @@ interface ImportCodePluginOptions {
|
|
|
84
44
|
declare const importCodePlugin: PluginWithOptions<ImportCodePluginOptions>;
|
|
85
45
|
|
|
86
46
|
interface LinksPluginOptions {
|
|
87
|
-
/**
|
|
88
|
-
* Tag for internal links
|
|
89
|
-
*
|
|
90
|
-
* @default 'RouterLink'
|
|
91
|
-
*/
|
|
92
|
-
internalTag?: 'a' | 'RouterLink';
|
|
93
47
|
/**
|
|
94
48
|
* Additional attributes for external links
|
|
95
49
|
*
|
|
@@ -102,31 +56,62 @@ interface LinksPluginOptions {
|
|
|
102
56
|
* ```
|
|
103
57
|
*/
|
|
104
58
|
externalAttrs?: Record<string, string>;
|
|
59
|
+
/**
|
|
60
|
+
* Tag for internal links
|
|
61
|
+
*
|
|
62
|
+
* @default 'RouteLink'
|
|
63
|
+
*/
|
|
64
|
+
internalTag?: 'a' | 'RouteLink' | 'RouterLink';
|
|
65
|
+
/**
|
|
66
|
+
* Method to check if a link is external
|
|
67
|
+
*
|
|
68
|
+
* @default import { isLinkExternal } from '@vuepress/shared'
|
|
69
|
+
*/
|
|
70
|
+
isExternal?: (href: string, env: MarkdownEnv) => boolean;
|
|
105
71
|
}
|
|
106
72
|
/**
|
|
107
73
|
* Process links in markdown file
|
|
108
74
|
*
|
|
109
|
-
* - internal links: convert
|
|
110
|
-
* - external links: add extra attrs
|
|
75
|
+
* - internal links: convert `<a>` tag into internalTag
|
|
76
|
+
* - external links: add extra attrs
|
|
111
77
|
*/
|
|
112
78
|
declare const linksPlugin: PluginWithOptions<LinksPluginOptions>;
|
|
113
79
|
|
|
80
|
+
interface VPrePluginOptions {
|
|
81
|
+
/**
|
|
82
|
+
* Add `v-pre` directive to `<pre>` tag of code block or not
|
|
83
|
+
*/
|
|
84
|
+
block?: boolean;
|
|
85
|
+
/**
|
|
86
|
+
* Add `v-pre` directive to `<code>` tag of inline code or not
|
|
87
|
+
*/
|
|
88
|
+
inline?: boolean;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* v-pre plugin
|
|
92
|
+
*/
|
|
93
|
+
declare const vPrePlugin: PluginWithOptions<VPrePluginOptions>;
|
|
94
|
+
|
|
114
95
|
type Markdown = MarkdownIt;
|
|
115
96
|
|
|
116
|
-
interface MarkdownOptions extends
|
|
117
|
-
anchor?:
|
|
118
|
-
assets?:
|
|
119
|
-
code?: false | CodePluginOptions;
|
|
97
|
+
interface MarkdownOptions extends Options$1 {
|
|
98
|
+
anchor?: AnchorPluginOptions | false;
|
|
99
|
+
assets?: AssetsPluginOptions | false;
|
|
120
100
|
component?: false;
|
|
121
|
-
emoji?:
|
|
122
|
-
frontmatter?:
|
|
123
|
-
headers?:
|
|
101
|
+
emoji?: EmojiPluginOptions | false;
|
|
102
|
+
frontmatter?: FrontmatterPluginOptions | false;
|
|
103
|
+
headers?: HeadersPluginOptions | false;
|
|
124
104
|
title?: false;
|
|
125
|
-
importCode?:
|
|
126
|
-
links?:
|
|
127
|
-
sfc?:
|
|
105
|
+
importCode?: ImportCodePluginOptions | false;
|
|
106
|
+
links?: LinksPluginOptions | false;
|
|
107
|
+
sfc?: SfcPluginOptions | false;
|
|
128
108
|
slugify?: MarkdownSlugifyFunction;
|
|
129
|
-
toc?:
|
|
109
|
+
toc?: TocPluginOptions | false;
|
|
110
|
+
vPre?: VPrePluginOptions | false;
|
|
111
|
+
/**
|
|
112
|
+
* @deprecated This feature has been removed. Please use `@vuepress/plugin-prismjs` or `@vuepress/plugin-shiki` instead.
|
|
113
|
+
*/
|
|
114
|
+
code?: never;
|
|
130
115
|
}
|
|
131
116
|
/**
|
|
132
117
|
* Headers in markdown file
|
|
@@ -140,7 +125,7 @@ type MarkdownHeader = PageHeader;
|
|
|
140
125
|
interface MarkdownLink {
|
|
141
126
|
raw: string;
|
|
142
127
|
relative: string;
|
|
143
|
-
absolute: string;
|
|
128
|
+
absolute: string | null;
|
|
144
129
|
}
|
|
145
130
|
/**
|
|
146
131
|
* The `env` object to be passed to markdown-it render function
|
|
@@ -183,6 +168,6 @@ type MarkdownSlugifyFunction = (str: string) => string;
|
|
|
183
168
|
/**
|
|
184
169
|
* Create vuepress customized markdown-it instance
|
|
185
170
|
*/
|
|
186
|
-
declare const createMarkdown: ({ anchor, assets, code, component, emoji, frontmatter, headers, title, importCode, links, sfc, slugify, toc, ...markdownItOptions }?: MarkdownOptions) => Markdown;
|
|
171
|
+
declare const createMarkdown: ({ anchor, assets, code, vPre, component, emoji, frontmatter, headers, title, importCode, links, sfc, slugify, toc, ...markdownItOptions }?: MarkdownOptions) => Markdown;
|
|
187
172
|
|
|
188
|
-
export { type AnchorPluginOptions, type AssetsPluginOptions, type
|
|
173
|
+
export { type AnchorPluginOptions, type AssetsPluginOptions, type EmojiPluginOptions, type ImportCodePluginOptions, type LinksPluginOptions, type Markdown, type MarkdownEnv, type MarkdownHeader, type MarkdownLink, type MarkdownOptions, type MarkdownSlugifyFunction, type VPrePluginOptions, assetsPlugin, createMarkdown, importCodePlugin, linksPlugin, vPrePlugin };
|
package/dist/index.js
CHANGED
|
@@ -1,11 +1,6 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __export = (target, all) => {
|
|
3
|
-
for (var name in all)
|
|
4
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
5
|
-
};
|
|
6
|
-
|
|
7
1
|
// src/markdown.ts
|
|
8
2
|
import { slugify as defaultSlugify } from "@mdit-vue/shared";
|
|
3
|
+
import { logger as logger2 } from "@vuepress/utils";
|
|
9
4
|
import MarkdownIt from "markdown-it";
|
|
10
5
|
|
|
11
6
|
// src/plugins.ts
|
|
@@ -23,7 +18,7 @@ import { titlePlugin } from "@mdit-vue/plugin-title";
|
|
|
23
18
|
import { tocPlugin } from "@mdit-vue/plugin-toc";
|
|
24
19
|
|
|
25
20
|
// src/plugins/anchorPlugin.ts
|
|
26
|
-
import
|
|
21
|
+
import anchorPlugin from "markdown-it-anchor";
|
|
27
22
|
|
|
28
23
|
// src/plugins/assetsPlugin/resolveLink.ts
|
|
29
24
|
import { path } from "@vuepress/utils";
|
|
@@ -34,8 +29,7 @@ var resolveLink = (link, {
|
|
|
34
29
|
relativePathPrefix,
|
|
35
30
|
strict = false
|
|
36
31
|
}) => {
|
|
37
|
-
if (link.startsWith("data:"))
|
|
38
|
-
return link;
|
|
32
|
+
if (link.startsWith("data:")) return link;
|
|
39
33
|
let resolvedLink = decode(link);
|
|
40
34
|
const isRelativePath = strict ? (
|
|
41
35
|
// in strict mode, only link that starts with `./` or `../` is considered as relative path
|
|
@@ -75,7 +69,7 @@ var assetsPlugin = (md, {
|
|
|
75
69
|
};
|
|
76
70
|
const createHtmlRule = (rawHtmlRule) => (tokens, idx, options, env, self) => {
|
|
77
71
|
tokens[idx].content = tokens[idx].content.replace(
|
|
78
|
-
/(<img\b.*?src=)(['"])(
|
|
72
|
+
/(<img\b.*?src=)(['"])(.*?)\2/gs,
|
|
79
73
|
(_, prefix, quote, src) => `${prefix}${quote}${resolveLink(src.trim(), {
|
|
80
74
|
env,
|
|
81
75
|
absolutePathPrependBase,
|
|
@@ -83,11 +77,11 @@ var assetsPlugin = (md, {
|
|
|
83
77
|
strict: true
|
|
84
78
|
})}${quote}`
|
|
85
79
|
).replace(
|
|
86
|
-
/(<img\b.*?srcset=)(['"])(
|
|
80
|
+
/(<img\b.*?srcset=)(['"])(.*?)\2/gs,
|
|
87
81
|
(_, prefix, quote, srcset) => `${prefix}${quote}${srcset.split(",").map(
|
|
88
82
|
(item) => item.trim().replace(
|
|
89
83
|
/^([^ ]*?)([ \n].*)?$/,
|
|
90
|
-
(
|
|
84
|
+
(__, url, descriptor = "") => `${resolveLink(url.trim(), {
|
|
91
85
|
env,
|
|
92
86
|
absolutePathPrependBase,
|
|
93
87
|
relativePathPrefix,
|
|
@@ -104,208 +98,6 @@ var assetsPlugin = (md, {
|
|
|
104
98
|
md.renderer.rules.html_inline = createHtmlRule(rawHtmlInlineRule);
|
|
105
99
|
};
|
|
106
100
|
|
|
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
|
-
|
|
115
|
-
// src/plugins/codePlugin/resolveHighlightLines.ts
|
|
116
|
-
var resolveHighlightLines = (info) => {
|
|
117
|
-
const match = info.match(/{([\d,-]+)}/);
|
|
118
|
-
if (match === null) {
|
|
119
|
-
return null;
|
|
120
|
-
}
|
|
121
|
-
return match[1].split(",").map((item) => {
|
|
122
|
-
const range = item.split("-");
|
|
123
|
-
if (range.length === 1) {
|
|
124
|
-
range.push(range[0]);
|
|
125
|
-
}
|
|
126
|
-
return range.map((str) => Number.parseInt(str, 10));
|
|
127
|
-
});
|
|
128
|
-
};
|
|
129
|
-
var isHighlightLine = (lineNumber, ranges) => ranges.some(([start, end]) => lineNumber >= start && lineNumber <= end);
|
|
130
|
-
|
|
131
|
-
// src/plugins/codePlugin/languages.ts
|
|
132
|
-
var languages_exports = {};
|
|
133
|
-
__export(languages_exports, {
|
|
134
|
-
languageBash: () => languageBash,
|
|
135
|
-
languageCsharp: () => languageCsharp,
|
|
136
|
-
languageDocker: () => languageDocker,
|
|
137
|
-
languageFsharp: () => languageFsharp,
|
|
138
|
-
languageJavascript: () => languageJavascript,
|
|
139
|
-
languageKotlin: () => languageKotlin,
|
|
140
|
-
languageMarkdown: () => languageMarkdown,
|
|
141
|
-
languagePython: () => languagePython,
|
|
142
|
-
languageRuby: () => languageRuby,
|
|
143
|
-
languageRust: () => languageRust,
|
|
144
|
-
languageStylus: () => languageStylus,
|
|
145
|
-
languageTypescript: () => languageTypescript,
|
|
146
|
-
languageYaml: () => languageYaml
|
|
147
|
-
});
|
|
148
|
-
var languageBash = {
|
|
149
|
-
name: "bash",
|
|
150
|
-
ext: "sh",
|
|
151
|
-
aliases: ["bash", "sh", "shell", "zsh"]
|
|
152
|
-
};
|
|
153
|
-
var languageCsharp = {
|
|
154
|
-
name: "csharp",
|
|
155
|
-
ext: "cs",
|
|
156
|
-
aliases: ["cs", "csharp"]
|
|
157
|
-
};
|
|
158
|
-
var languageDocker = {
|
|
159
|
-
name: "docker",
|
|
160
|
-
ext: "docker",
|
|
161
|
-
aliases: ["docker", "dockerfile"]
|
|
162
|
-
};
|
|
163
|
-
var languageFsharp = {
|
|
164
|
-
name: "fsharp",
|
|
165
|
-
ext: "fs",
|
|
166
|
-
aliases: ["fs", "fsharp"]
|
|
167
|
-
};
|
|
168
|
-
var languageJavascript = {
|
|
169
|
-
name: "javascript",
|
|
170
|
-
ext: "js",
|
|
171
|
-
aliases: ["javascript", "js"]
|
|
172
|
-
};
|
|
173
|
-
var languageKotlin = {
|
|
174
|
-
name: "kotlin",
|
|
175
|
-
ext: "kt",
|
|
176
|
-
aliases: ["kotlin", "kt"]
|
|
177
|
-
};
|
|
178
|
-
var languageMarkdown = {
|
|
179
|
-
name: "markdown",
|
|
180
|
-
ext: "md",
|
|
181
|
-
aliases: ["markdown", "md"]
|
|
182
|
-
};
|
|
183
|
-
var languagePython = {
|
|
184
|
-
name: "python",
|
|
185
|
-
ext: "py",
|
|
186
|
-
aliases: ["py", "python"]
|
|
187
|
-
};
|
|
188
|
-
var languageRuby = {
|
|
189
|
-
name: "ruby",
|
|
190
|
-
ext: "rb",
|
|
191
|
-
aliases: ["rb", "ruby"]
|
|
192
|
-
};
|
|
193
|
-
var languageRust = {
|
|
194
|
-
name: "rust",
|
|
195
|
-
ext: "rs",
|
|
196
|
-
aliases: ["rs", "rust"]
|
|
197
|
-
};
|
|
198
|
-
var languageStylus = {
|
|
199
|
-
name: "stylus",
|
|
200
|
-
ext: "styl",
|
|
201
|
-
aliases: ["styl", "stylus"]
|
|
202
|
-
};
|
|
203
|
-
var languageTypescript = {
|
|
204
|
-
name: "typescript",
|
|
205
|
-
ext: "ts",
|
|
206
|
-
aliases: ["ts", "typescript"]
|
|
207
|
-
};
|
|
208
|
-
var languageYaml = {
|
|
209
|
-
name: "yaml",
|
|
210
|
-
ext: "yml",
|
|
211
|
-
aliases: ["yaml", "yml"]
|
|
212
|
-
};
|
|
213
|
-
|
|
214
|
-
// src/plugins/codePlugin/resolveLanguage.ts
|
|
215
|
-
var languagesMap;
|
|
216
|
-
var getLanguagesMap = () => {
|
|
217
|
-
if (!languagesMap) {
|
|
218
|
-
languagesMap = Object.values(languages_exports).reduce((result, item) => {
|
|
219
|
-
item.aliases.forEach((alias) => {
|
|
220
|
-
result[alias] = item;
|
|
221
|
-
});
|
|
222
|
-
return result;
|
|
223
|
-
}, {});
|
|
224
|
-
}
|
|
225
|
-
return languagesMap;
|
|
226
|
-
};
|
|
227
|
-
var resolveLanguage = (info) => {
|
|
228
|
-
const alias = info.match(/^([^ :[{]+)/)?.[1] || "text";
|
|
229
|
-
return getLanguagesMap()[alias] ?? {
|
|
230
|
-
name: alias,
|
|
231
|
-
ext: alias,
|
|
232
|
-
aliases: [alias]
|
|
233
|
-
};
|
|
234
|
-
};
|
|
235
|
-
|
|
236
|
-
// src/plugins/codePlugin/resolveLineNumbers.ts
|
|
237
|
-
var resolveLineNumbers = (info) => {
|
|
238
|
-
if (/:line-numbers\b/.test(info)) {
|
|
239
|
-
return true;
|
|
240
|
-
}
|
|
241
|
-
if (/:no-line-numbers\b/.test(info)) {
|
|
242
|
-
return false;
|
|
243
|
-
}
|
|
244
|
-
return null;
|
|
245
|
-
};
|
|
246
|
-
|
|
247
|
-
// src/plugins/codePlugin/resolveVPre.ts
|
|
248
|
-
var resolveVPre = (info) => {
|
|
249
|
-
if (/:v-pre\b/.test(info)) {
|
|
250
|
-
return true;
|
|
251
|
-
}
|
|
252
|
-
if (/:no-v-pre\b/.test(info)) {
|
|
253
|
-
return false;
|
|
254
|
-
}
|
|
255
|
-
return null;
|
|
256
|
-
};
|
|
257
|
-
|
|
258
|
-
// src/plugins/codePlugin/codePlugin.ts
|
|
259
|
-
var codePlugin = (md, {
|
|
260
|
-
highlightLines = true,
|
|
261
|
-
lineNumbers = true,
|
|
262
|
-
preWrapper = true,
|
|
263
|
-
vPre: { block: vPreBlock = true, inline: vPreInline = true } = {}
|
|
264
|
-
} = {}) => {
|
|
265
|
-
md.renderer.rules.fence = (tokens, idx, options, env, slf) => {
|
|
266
|
-
const token = tokens[idx];
|
|
267
|
-
const info = token.info ? md.utils.unescapeAll(token.info).trim() : "";
|
|
268
|
-
const language = resolveLanguage(info);
|
|
269
|
-
const languageClass = `${options.langPrefix}${language.name}`;
|
|
270
|
-
const code = options.highlight?.(token.content, language.name, "") || md.utils.escapeHtml(token.content);
|
|
271
|
-
token.attrJoin("class", languageClass);
|
|
272
|
-
let result = code.startsWith("<pre") ? code : `<pre${slf.renderAttrs(token)}><code>${code}</code></pre>`;
|
|
273
|
-
const useVPre = resolveVPre(info) ?? vPreBlock;
|
|
274
|
-
if (useVPre) {
|
|
275
|
-
result = `<pre v-pre${result.slice("<pre".length)}`;
|
|
276
|
-
}
|
|
277
|
-
if (!preWrapper) {
|
|
278
|
-
return result;
|
|
279
|
-
}
|
|
280
|
-
const lines = code.split("\n").slice(0, -1);
|
|
281
|
-
const highlightLinesRanges = highlightLines ? resolveHighlightLines(info) : null;
|
|
282
|
-
if (highlightLinesRanges) {
|
|
283
|
-
const highlightLinesCode = lines.map((_, index) => {
|
|
284
|
-
if (isHighlightLine(index + 1, highlightLinesRanges)) {
|
|
285
|
-
return '<div class="highlight-line"> </div>';
|
|
286
|
-
}
|
|
287
|
-
return "<br>";
|
|
288
|
-
}).join("");
|
|
289
|
-
result = `${result}<div class="highlight-lines">${highlightLinesCode}</div>`;
|
|
290
|
-
}
|
|
291
|
-
const useLineNumbers = resolveLineNumbers(info) ?? (typeof lineNumbers === "number" ? lines.length >= lineNumbers : lineNumbers);
|
|
292
|
-
if (useLineNumbers) {
|
|
293
|
-
const lineNumbersCode = lines.map(() => `<div class="line-number"></div>`).join("");
|
|
294
|
-
result = `${result}<div class="line-numbers" aria-hidden="true">${lineNumbersCode}</div>`;
|
|
295
|
-
}
|
|
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>`;
|
|
298
|
-
return result;
|
|
299
|
-
};
|
|
300
|
-
if (vPreInline) {
|
|
301
|
-
const rawInlineCodeRule = md.renderer.rules.code_inline;
|
|
302
|
-
md.renderer.rules.code_inline = (tokens, idx, options, env, slf) => {
|
|
303
|
-
const result = rawInlineCodeRule(tokens, idx, options, env, slf);
|
|
304
|
-
return `<code v-pre${result.slice("<code".length)}`;
|
|
305
|
-
};
|
|
306
|
-
}
|
|
307
|
-
};
|
|
308
|
-
|
|
309
101
|
// src/plugins/emojiPlugin.ts
|
|
310
102
|
import { full as emojiPlugin } from "markdown-it-emoji";
|
|
311
103
|
|
|
@@ -313,30 +105,31 @@ import { full as emojiPlugin } from "markdown-it-emoji";
|
|
|
313
105
|
import { path as path2 } from "@vuepress/utils";
|
|
314
106
|
var MIN_LENGTH = 9;
|
|
315
107
|
var START_CODES = [64, 91, 99, 111, 100, 101];
|
|
316
|
-
var SYNTAX_RE = /^@\[code(?:{(?:(
|
|
108
|
+
var SYNTAX_RE = /^@\[code(?:{(?:(?:(?<lineStart>\d+)?-(?<lineEnd>\d+)?)|(?<lineSingle>\d+))})?(?: (?<info>[^\]]+))?\]\((?<importPath>[^)]*)\)/;
|
|
109
|
+
var parseLineNumber = (line) => line ? Number.parseInt(line, 10) : void 0;
|
|
317
110
|
var createImportCodeBlockRule = ({ handleImportPath = (str) => str }) => (state, startLine, endLine, silent) => {
|
|
318
111
|
if (state.sCount[startLine] - state.blkIndent >= 4) {
|
|
319
112
|
return false;
|
|
320
113
|
}
|
|
321
114
|
const pos = state.bMarks[startLine] + state.tShift[startLine];
|
|
322
115
|
const max = state.eMarks[startLine];
|
|
323
|
-
if (pos + MIN_LENGTH > max)
|
|
324
|
-
return false;
|
|
116
|
+
if (pos + MIN_LENGTH > max) return false;
|
|
325
117
|
for (let i = 0; i < START_CODES.length; i += 1) {
|
|
326
118
|
if (state.src.charCodeAt(pos + i) !== START_CODES[i]) {
|
|
327
119
|
return false;
|
|
328
120
|
}
|
|
329
121
|
}
|
|
330
122
|
const match = state.src.slice(pos, max).match(SYNTAX_RE);
|
|
331
|
-
if (!match)
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
const
|
|
123
|
+
if (!match?.groups) return false;
|
|
124
|
+
if (silent) return true;
|
|
125
|
+
const { info, importPath } = match.groups;
|
|
126
|
+
const lineSingle = parseLineNumber(match.groups.lineSingle);
|
|
127
|
+
const lineStart = lineSingle ?? parseLineNumber(match.groups.lineStart) ?? 0;
|
|
128
|
+
const lineEnd = lineSingle ?? parseLineNumber(match.groups.lineEnd);
|
|
336
129
|
const meta = {
|
|
337
130
|
importPath: handleImportPath(importPath),
|
|
338
|
-
lineStart
|
|
339
|
-
lineEnd
|
|
131
|
+
lineStart,
|
|
132
|
+
lineEnd
|
|
340
133
|
};
|
|
341
134
|
const token = state.push("import_code", "code", 0);
|
|
342
135
|
token.info = info ?? path2.extname(meta.importPath).slice(1);
|
|
@@ -387,20 +180,23 @@ var importCodePlugin = (md, options = {}) => {
|
|
|
387
180
|
alt: ["paragraph", "reference", "blockquote", "list"]
|
|
388
181
|
}
|
|
389
182
|
);
|
|
390
|
-
md.renderer.rules.import_code = (tokens, idx,
|
|
183
|
+
md.renderer.rules.import_code = (tokens, idx, opts, env, slf) => {
|
|
391
184
|
const token = tokens[idx];
|
|
392
|
-
const { importFilePath, importCode } = resolveImportCode(
|
|
185
|
+
const { importFilePath, importCode } = resolveImportCode(
|
|
186
|
+
token.meta,
|
|
187
|
+
env
|
|
188
|
+
);
|
|
393
189
|
token.content = importCode;
|
|
394
190
|
if (importFilePath) {
|
|
395
191
|
;
|
|
396
192
|
(env.importedFiles ??= []).push(importFilePath);
|
|
397
193
|
}
|
|
398
|
-
return md.renderer.rules.fence(tokens, idx,
|
|
194
|
+
return md.renderer.rules.fence(tokens, idx, opts, env, slf);
|
|
399
195
|
};
|
|
400
196
|
};
|
|
401
197
|
|
|
402
198
|
// src/plugins/linksPlugin/linksPlugin.ts
|
|
403
|
-
import { isLinkExternal } from "@vuepress/shared";
|
|
199
|
+
import { inferRoutePath, isLinkExternal } from "@vuepress/shared";
|
|
404
200
|
|
|
405
201
|
// src/plugins/linksPlugin/resolvePaths.ts
|
|
406
202
|
import { removeLeadingSlash } from "@vuepress/shared";
|
|
@@ -416,18 +212,16 @@ var resolvePaths = (rawPath, base, filePathRelative) => {
|
|
|
416
212
|
absolutePath = rawPath;
|
|
417
213
|
relativePath = path4.relative(base, absolutePath);
|
|
418
214
|
}
|
|
215
|
+
} else if (filePathRelative) {
|
|
216
|
+
relativePath = path4.join(
|
|
217
|
+
// file path may contain non-ASCII characters
|
|
218
|
+
path4.dirname(encodeURI(filePathRelative)),
|
|
219
|
+
rawPath
|
|
220
|
+
);
|
|
221
|
+
absolutePath = path4.join(base, relativePath);
|
|
419
222
|
} else {
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
// file path may contain non-ASCII characters
|
|
423
|
-
path4.dirname(encodeURI(filePathRelative)),
|
|
424
|
-
rawPath
|
|
425
|
-
);
|
|
426
|
-
absolutePath = path4.join(base, relativePath);
|
|
427
|
-
} else {
|
|
428
|
-
relativePath = rawPath.replace(/^(?:\.\/)?(.*)$/, "$1");
|
|
429
|
-
absolutePath = relativePath;
|
|
430
|
-
}
|
|
223
|
+
relativePath = rawPath.replace(/^(?:\.\/)?(.*)$/, "$1");
|
|
224
|
+
absolutePath = null;
|
|
431
225
|
}
|
|
432
226
|
return {
|
|
433
227
|
absolutePath,
|
|
@@ -437,7 +231,8 @@ var resolvePaths = (rawPath, base, filePathRelative) => {
|
|
|
437
231
|
|
|
438
232
|
// src/plugins/linksPlugin/linksPlugin.ts
|
|
439
233
|
var linksPlugin = (md, options = {}) => {
|
|
440
|
-
const internalTag = options.internalTag || "
|
|
234
|
+
const internalTag = options.internalTag || "RouteLink";
|
|
235
|
+
const isExternal = options.isExternal ?? ((href, env) => isLinkExternal(href, env.base));
|
|
441
236
|
const externalAttrs = {
|
|
442
237
|
target: "_blank",
|
|
443
238
|
rel: "noopener noreferrer",
|
|
@@ -453,56 +248,97 @@ var linksPlugin = (md, options = {}) => {
|
|
|
453
248
|
const hrefAttr = token.attrs[hrefIndex];
|
|
454
249
|
const hrefLink = hrefAttr[1];
|
|
455
250
|
const { base = "/", filePathRelative = null } = env;
|
|
456
|
-
if (
|
|
457
|
-
Object.entries(externalAttrs).forEach(
|
|
458
|
-
|
|
459
|
-
);
|
|
251
|
+
if (isExternal(hrefLink, env)) {
|
|
252
|
+
Object.entries(externalAttrs).forEach(([key, val]) => {
|
|
253
|
+
token.attrSet(key, val);
|
|
254
|
+
});
|
|
460
255
|
return;
|
|
461
256
|
}
|
|
462
257
|
const internalLinkMatch = hrefLink.match(
|
|
463
|
-
/^((
|
|
258
|
+
/^([^#?]*?(?:\/|\.md|\.html))([#?].*)?$/
|
|
464
259
|
);
|
|
465
260
|
if (!internalLinkMatch) {
|
|
466
261
|
return;
|
|
467
262
|
}
|
|
468
263
|
const rawPath = internalLinkMatch[1];
|
|
469
|
-
const
|
|
264
|
+
const rawHashAndQueries = internalLinkMatch[2] || "";
|
|
470
265
|
const { relativePath, absolutePath } = resolvePaths(
|
|
471
266
|
rawPath,
|
|
472
267
|
base,
|
|
473
268
|
filePathRelative
|
|
474
269
|
);
|
|
475
|
-
|
|
476
|
-
if (internalTag === "RouterLink") {
|
|
270
|
+
if (["RouterLink", "RouteLink"].includes(internalTag)) {
|
|
477
271
|
token.tag = internalTag;
|
|
478
272
|
hrefAttr[0] = "to";
|
|
273
|
+
const normalizedPath = inferRoutePath(
|
|
274
|
+
absolutePath ? absolutePath.replace(new RegExp(`^${base}`), "/") : relativePath
|
|
275
|
+
);
|
|
276
|
+
hrefAttr[1] = `${normalizedPath}${rawHashAndQueries}`;
|
|
479
277
|
hasOpenInternalLink = true;
|
|
278
|
+
} else {
|
|
279
|
+
const normalizedPath = inferRoutePath(absolutePath ?? relativePath);
|
|
280
|
+
hrefAttr[1] = `${normalizedPath}${rawHashAndQueries}`;
|
|
480
281
|
}
|
|
481
|
-
|
|
282
|
+
;
|
|
482
283
|
(env.links ??= []).push({
|
|
483
284
|
raw: hrefLink,
|
|
484
285
|
relative: relativePath,
|
|
485
286
|
absolute: absolutePath
|
|
486
287
|
});
|
|
487
288
|
};
|
|
488
|
-
md.renderer.rules.link_open = (tokens, idx,
|
|
289
|
+
md.renderer.rules.link_open = (tokens, idx, opts, env, self) => {
|
|
489
290
|
handleLinkOpen(tokens, idx, env);
|
|
490
|
-
return self.renderToken(tokens, idx,
|
|
291
|
+
return self.renderToken(tokens, idx, opts);
|
|
491
292
|
};
|
|
492
|
-
md.renderer.rules.link_close = (tokens, idx,
|
|
293
|
+
md.renderer.rules.link_close = (tokens, idx, opts, _env, self) => {
|
|
493
294
|
if (hasOpenInternalLink) {
|
|
494
295
|
hasOpenInternalLink = false;
|
|
495
296
|
tokens[idx].tag = internalTag;
|
|
496
297
|
}
|
|
497
|
-
return self.renderToken(tokens, idx,
|
|
298
|
+
return self.renderToken(tokens, idx, opts);
|
|
498
299
|
};
|
|
499
300
|
};
|
|
500
301
|
|
|
302
|
+
// src/plugins/vPrePlugin/resolveVPre.ts
|
|
303
|
+
var resolveVPre = (info) => {
|
|
304
|
+
if (/:v-pre\b/.test(info)) {
|
|
305
|
+
return true;
|
|
306
|
+
}
|
|
307
|
+
if (/:no-v-pre\b/.test(info)) {
|
|
308
|
+
return false;
|
|
309
|
+
}
|
|
310
|
+
return null;
|
|
311
|
+
};
|
|
312
|
+
|
|
313
|
+
// src/plugins/vPrePlugin/vPrePlugin.ts
|
|
314
|
+
var vPrePlugin = (md, { inline = true, block = true } = {}) => {
|
|
315
|
+
const rawFence = md.renderer.rules.fence;
|
|
316
|
+
md.renderer.rules.fence = (...args) => {
|
|
317
|
+
const [tokens, idx] = args;
|
|
318
|
+
const token = tokens[idx];
|
|
319
|
+
const info = token.info ? md.utils.unescapeAll(token.info).trim() : "";
|
|
320
|
+
let result = rawFence(...args);
|
|
321
|
+
if (resolveVPre(info) ?? block) {
|
|
322
|
+
result = `<pre v-pre${result.slice("<pre".length)}`;
|
|
323
|
+
}
|
|
324
|
+
return result;
|
|
325
|
+
};
|
|
326
|
+
if (inline) {
|
|
327
|
+
const rawInlineCodeRule = md.renderer.rules.code_inline;
|
|
328
|
+
md.renderer.rules.code_inline = (...args) => {
|
|
329
|
+
const result = rawInlineCodeRule(...args);
|
|
330
|
+
return `<code v-pre${result.slice("<code".length)}`;
|
|
331
|
+
};
|
|
332
|
+
}
|
|
333
|
+
};
|
|
334
|
+
|
|
501
335
|
// src/markdown.ts
|
|
502
336
|
var createMarkdown = ({
|
|
503
337
|
anchor,
|
|
504
338
|
assets,
|
|
339
|
+
// eslint-disable-next-line @typescript-eslint/no-deprecated
|
|
505
340
|
code,
|
|
341
|
+
vPre,
|
|
506
342
|
component,
|
|
507
343
|
emoji,
|
|
508
344
|
frontmatter,
|
|
@@ -535,8 +371,11 @@ var createMarkdown = ({
|
|
|
535
371
|
if (assets !== false) {
|
|
536
372
|
md.use(assetsPlugin, assets);
|
|
537
373
|
}
|
|
538
|
-
if (code
|
|
539
|
-
|
|
374
|
+
if (code) {
|
|
375
|
+
logger2.warn(
|
|
376
|
+
`\`markdown.code\` option has been removed, please use '@vuepress/plugin-shiki' or '@vuepress/plugin-prismjs' instead.
|
|
377
|
+
See https://vuepress.vuejs.org/reference/config.html#markdown-code`
|
|
378
|
+
);
|
|
540
379
|
}
|
|
541
380
|
if (component !== false) {
|
|
542
381
|
md.use(componentPlugin);
|
|
@@ -580,12 +419,14 @@ var createMarkdown = ({
|
|
|
580
419
|
if (title !== false) {
|
|
581
420
|
md.use(titlePlugin);
|
|
582
421
|
}
|
|
422
|
+
if (vPre !== false) {
|
|
423
|
+
md.use(vPrePlugin, vPre);
|
|
424
|
+
}
|
|
583
425
|
return md;
|
|
584
426
|
};
|
|
585
427
|
export {
|
|
586
428
|
anchorPlugin,
|
|
587
429
|
assetsPlugin,
|
|
588
|
-
codePlugin,
|
|
589
430
|
componentPlugin,
|
|
590
431
|
createMarkdown,
|
|
591
432
|
emojiPlugin,
|
|
@@ -595,5 +436,6 @@ export {
|
|
|
595
436
|
linksPlugin,
|
|
596
437
|
sfcPlugin,
|
|
597
438
|
titlePlugin,
|
|
598
|
-
tocPlugin
|
|
439
|
+
tocPlugin,
|
|
440
|
+
vPrePlugin
|
|
599
441
|
};
|
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.20",
|
|
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.
|
|
31
|
-
"@mdit-vue/plugin-frontmatter": "^2.
|
|
32
|
-
"@mdit-vue/plugin-headers": "^2.
|
|
33
|
-
"@mdit-vue/plugin-sfc": "^2.
|
|
34
|
-
"@mdit-vue/plugin-title": "^2.
|
|
35
|
-
"@mdit-vue/plugin-toc": "^2.
|
|
36
|
-
"@mdit-vue/shared": "^2.
|
|
37
|
-
"@mdit-vue/types": "^2.
|
|
38
|
-
"@types/markdown-it": "^
|
|
39
|
-
"@types/markdown-it-emoji": "^
|
|
40
|
-
"markdown-it": "^14.
|
|
41
|
-
"markdown-it-anchor": "^
|
|
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.2",
|
|
39
|
+
"@types/markdown-it-emoji": "^3.0.1",
|
|
40
|
+
"markdown-it": "^14.1.0",
|
|
41
|
+
"markdown-it-anchor": "^9.2.0",
|
|
42
42
|
"markdown-it-emoji": "^3.0.0",
|
|
43
43
|
"mdurl": "^2.0.0",
|
|
44
|
-
"@vuepress/shared": "2.0.0-rc.
|
|
45
|
-
"@vuepress/utils": "2.0.0-rc.
|
|
44
|
+
"@vuepress/shared": "2.0.0-rc.20",
|
|
45
|
+
"@vuepress/utils": "2.0.0-rc.20"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
|
-
"@types/mdurl": "^
|
|
48
|
+
"@types/mdurl": "^2.0.0"
|
|
49
49
|
},
|
|
50
50
|
"publishConfig": {
|
|
51
51
|
"access": "public"
|