@vuepress/markdown 2.0.0-beta.50-pre → 2.0.0-beta.50-pre.1
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 +272 -0
- package/dist/index.js +583 -0
- package/package.json +4 -4
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
import { SfcPluginOptions } from '@mdit-vue/plugin-sfc';
|
|
2
|
+
export { MarkdownSfcBlocks, SfcPluginOptions, sfcPlugin } from '@mdit-vue/plugin-sfc';
|
|
3
|
+
import { MarkdownItEnv } from '@mdit-vue/types';
|
|
4
|
+
import { PageHeader, PageFrontmatter } from '@vuepress/shared';
|
|
5
|
+
import MarkdownIt, { PluginWithOptions } from 'markdown-it';
|
|
6
|
+
import { FrontmatterPluginOptions } from '@mdit-vue/plugin-frontmatter';
|
|
7
|
+
export { FrontmatterPluginOptions, frontmatterPlugin } from '@mdit-vue/plugin-frontmatter';
|
|
8
|
+
import { HeadersPluginOptions } from '@mdit-vue/plugin-headers';
|
|
9
|
+
export { HeadersPluginOptions, headersPlugin } from '@mdit-vue/plugin-headers';
|
|
10
|
+
import { TocPluginOptions } from '@mdit-vue/plugin-toc';
|
|
11
|
+
export { TocPluginOptions, tocPlugin } from '@mdit-vue/plugin-toc';
|
|
12
|
+
import anchorPlugin from 'markdown-it-anchor';
|
|
13
|
+
export { default as anchorPlugin } from 'markdown-it-anchor';
|
|
14
|
+
import emojiPlugin from 'markdown-it-emoji';
|
|
15
|
+
export { default as emojiPlugin } from 'markdown-it-emoji';
|
|
16
|
+
export { ComponentPluginOptions, componentPlugin } from '@mdit-vue/plugin-component';
|
|
17
|
+
export { titlePlugin } from '@mdit-vue/plugin-title';
|
|
18
|
+
import { RuleBlock } from 'markdown-it/lib/parser_block.js';
|
|
19
|
+
|
|
20
|
+
declare type AnchorPluginOptions = anchorPlugin.AnchorOptions;
|
|
21
|
+
|
|
22
|
+
interface AssetsPluginOptions {
|
|
23
|
+
/**
|
|
24
|
+
* Prefix to add to relative assets links
|
|
25
|
+
*/
|
|
26
|
+
relativePathPrefix?: string;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Plugin to handle assets links
|
|
30
|
+
*/
|
|
31
|
+
declare const assetsPlugin: PluginWithOptions<AssetsPluginOptions>;
|
|
32
|
+
|
|
33
|
+
declare const resolveLink: (link: string, relativePathPrefix: string, env: MarkdownEnv) => string;
|
|
34
|
+
|
|
35
|
+
interface CodePluginOptions {
|
|
36
|
+
/**
|
|
37
|
+
* Enable highlight lines or not
|
|
38
|
+
*/
|
|
39
|
+
highlightLines?: boolean;
|
|
40
|
+
/**
|
|
41
|
+
* Enable line numbers or not
|
|
42
|
+
*
|
|
43
|
+
* - A `boolean` value is to enable line numbers or not.
|
|
44
|
+
* - A `number` value is the minimum number of lines to enable line numbers
|
|
45
|
+
*/
|
|
46
|
+
lineNumbers?: boolean | number;
|
|
47
|
+
/**
|
|
48
|
+
* Wrap the `<pre>` tag with an extra `<div>` or not. Do not disable it unless you
|
|
49
|
+
* understand what's it for
|
|
50
|
+
*
|
|
51
|
+
* - Required for `highlightLines`
|
|
52
|
+
* - Required for `lineNumbers`
|
|
53
|
+
* - Required for language display of default theme
|
|
54
|
+
*/
|
|
55
|
+
preWrapper?: boolean;
|
|
56
|
+
/**
|
|
57
|
+
* Add `v-pre` directive or not
|
|
58
|
+
*/
|
|
59
|
+
vPre?: {
|
|
60
|
+
/**
|
|
61
|
+
* Add `v-pre` directive to `<pre>` tag of code block or not
|
|
62
|
+
*/
|
|
63
|
+
block?: boolean;
|
|
64
|
+
/**
|
|
65
|
+
* Add `v-pre` directive to `<code>` tag of inline code or not
|
|
66
|
+
*/
|
|
67
|
+
inline?: boolean;
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Code plugin
|
|
72
|
+
*/
|
|
73
|
+
declare const codePlugin: PluginWithOptions<CodePluginOptions>;
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Language type for syntax highlight
|
|
77
|
+
*/
|
|
78
|
+
interface HighlightLanguage {
|
|
79
|
+
/**
|
|
80
|
+
* Name of the language
|
|
81
|
+
*
|
|
82
|
+
* The name to be used for the class name,
|
|
83
|
+
* e.g. `class="language-typescript"`
|
|
84
|
+
*/
|
|
85
|
+
name: string;
|
|
86
|
+
/**
|
|
87
|
+
* Extension of the language
|
|
88
|
+
*
|
|
89
|
+
* The file extension, which will be used for the
|
|
90
|
+
* class name, e.g. `class="ext-ts"`
|
|
91
|
+
*/
|
|
92
|
+
ext: string;
|
|
93
|
+
/**
|
|
94
|
+
* Aliases that point to this language
|
|
95
|
+
*
|
|
96
|
+
* Do not conflict with other languages
|
|
97
|
+
*/
|
|
98
|
+
aliases: string[];
|
|
99
|
+
}
|
|
100
|
+
declare const languageBash: HighlightLanguage;
|
|
101
|
+
declare const languageCsharp: HighlightLanguage;
|
|
102
|
+
declare const languageDocker: HighlightLanguage;
|
|
103
|
+
declare const languageFsharp: HighlightLanguage;
|
|
104
|
+
declare const languageJavascript: HighlightLanguage;
|
|
105
|
+
declare const languageKotlin: HighlightLanguage;
|
|
106
|
+
declare const languageMarkdown: HighlightLanguage;
|
|
107
|
+
declare const languagePython: HighlightLanguage;
|
|
108
|
+
declare const languageRuby: HighlightLanguage;
|
|
109
|
+
declare const languageRust: HighlightLanguage;
|
|
110
|
+
declare const languageStylus: HighlightLanguage;
|
|
111
|
+
declare const languageTypescript: HighlightLanguage;
|
|
112
|
+
declare const languageYaml: HighlightLanguage;
|
|
113
|
+
|
|
114
|
+
declare type HighlightLinesRange = [number, number];
|
|
115
|
+
/**
|
|
116
|
+
* Resolve highlight-lines ranges from token info
|
|
117
|
+
*/
|
|
118
|
+
declare const resolveHighlightLines: (info: string) => HighlightLinesRange[] | null;
|
|
119
|
+
/**
|
|
120
|
+
* Check if a line number is in ranges
|
|
121
|
+
*/
|
|
122
|
+
declare const isHighlightLine: (lineNumber: number, ranges: HighlightLinesRange[]) => boolean;
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Resolve language for highlight from token info
|
|
126
|
+
*/
|
|
127
|
+
declare const resolveLanguage: (info: string) => HighlightLanguage;
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Resolve the `:line-numbers` / `:no-line-numbers` mark from token info
|
|
131
|
+
*/
|
|
132
|
+
declare const resolveLineNumbers: (info: string) => boolean | null;
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Resolve the `:v-pre` / `:no-v-pre` mark from token info
|
|
136
|
+
*/
|
|
137
|
+
declare const resolveVPre: (info: string) => boolean | null;
|
|
138
|
+
|
|
139
|
+
declare type EmojiPluginOptions = emojiPlugin.Options;
|
|
140
|
+
|
|
141
|
+
interface ImportCodePluginOptions {
|
|
142
|
+
/**
|
|
143
|
+
* A function to handle the import path
|
|
144
|
+
*/
|
|
145
|
+
handleImportPath?: (str: string) => string;
|
|
146
|
+
}
|
|
147
|
+
declare const importCodePlugin: PluginWithOptions<ImportCodePluginOptions>;
|
|
148
|
+
|
|
149
|
+
declare const createImportCodeBlockRule: ({ handleImportPath }: ImportCodePluginOptions) => RuleBlock;
|
|
150
|
+
|
|
151
|
+
interface ImportCodeTokenMeta {
|
|
152
|
+
importPath: string;
|
|
153
|
+
lineStart: number;
|
|
154
|
+
lineEnd?: number;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
declare const resolveImportCode: ({ importPath, lineStart, lineEnd }: ImportCodeTokenMeta, { filePath }: MarkdownEnv) => {
|
|
158
|
+
importFilePath: string | null;
|
|
159
|
+
importCode: string;
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
interface LinksPluginOptions {
|
|
163
|
+
/**
|
|
164
|
+
* Tag for internal links
|
|
165
|
+
*
|
|
166
|
+
* @default 'RouterLink'
|
|
167
|
+
*/
|
|
168
|
+
internalTag?: 'a' | 'RouterLink';
|
|
169
|
+
/**
|
|
170
|
+
* Additional attributes for external links
|
|
171
|
+
*
|
|
172
|
+
* @default
|
|
173
|
+
* ```js
|
|
174
|
+
* ({
|
|
175
|
+
* target: '_blank',
|
|
176
|
+
* rel: 'noopener noreferrer',
|
|
177
|
+
* })
|
|
178
|
+
* ```
|
|
179
|
+
*/
|
|
180
|
+
externalAttrs?: Record<string, string>;
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Process links in markdown file
|
|
184
|
+
*
|
|
185
|
+
* - internal links: convert them into `<RouterLink>`
|
|
186
|
+
* - external links: add extra attrs and external icon
|
|
187
|
+
*/
|
|
188
|
+
declare const linksPlugin: PluginWithOptions<LinksPluginOptions>;
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Resolve relative and absolute paths according to the `base` and `filePathRelative`
|
|
192
|
+
*/
|
|
193
|
+
declare const resolvePaths: (rawPath: string, base: string, filePathRelative: string | null) => {
|
|
194
|
+
absolutePath: string;
|
|
195
|
+
relativePath: string;
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
declare type Markdown = MarkdownIt;
|
|
199
|
+
|
|
200
|
+
interface MarkdownOptions extends MarkdownIt.Options {
|
|
201
|
+
anchor?: false | AnchorPluginOptions;
|
|
202
|
+
assets?: false | AssetsPluginOptions;
|
|
203
|
+
code?: false | CodePluginOptions;
|
|
204
|
+
component?: false;
|
|
205
|
+
emoji?: false | EmojiPluginOptions;
|
|
206
|
+
frontmatter?: false | FrontmatterPluginOptions;
|
|
207
|
+
headers?: false | HeadersPluginOptions;
|
|
208
|
+
title?: false;
|
|
209
|
+
importCode?: false | ImportCodePluginOptions;
|
|
210
|
+
links?: false | LinksPluginOptions;
|
|
211
|
+
sfc?: false | SfcPluginOptions;
|
|
212
|
+
slugify?: MarkdownSlugifyFunction;
|
|
213
|
+
toc?: false | TocPluginOptions;
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Headers in markdown file
|
|
217
|
+
*/
|
|
218
|
+
declare type MarkdownHeader = PageHeader;
|
|
219
|
+
/**
|
|
220
|
+
* Internal links in markdown file
|
|
221
|
+
*
|
|
222
|
+
* Used for file existence check
|
|
223
|
+
*/
|
|
224
|
+
interface MarkdownLink {
|
|
225
|
+
raw: string;
|
|
226
|
+
relative: string;
|
|
227
|
+
absolute: string;
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* The `env` object to be passed to markdown-it render function
|
|
231
|
+
*
|
|
232
|
+
* Input some meta data for markdown file parsing and rendering
|
|
233
|
+
*
|
|
234
|
+
* Output some resources from the markdown file
|
|
235
|
+
*/
|
|
236
|
+
interface MarkdownEnv extends MarkdownItEnv {
|
|
237
|
+
/**
|
|
238
|
+
* Base / publicPath of current site
|
|
239
|
+
*/
|
|
240
|
+
base?: string;
|
|
241
|
+
/**
|
|
242
|
+
* Absolute file path of the markdown file
|
|
243
|
+
*/
|
|
244
|
+
filePath?: string | null;
|
|
245
|
+
/**
|
|
246
|
+
* Relative file path of the markdown file
|
|
247
|
+
*/
|
|
248
|
+
filePathRelative?: string | null;
|
|
249
|
+
/**
|
|
250
|
+
* Frontmatter of the markdown file
|
|
251
|
+
*/
|
|
252
|
+
frontmatter?: PageFrontmatter;
|
|
253
|
+
/**
|
|
254
|
+
* Imported file that extracted by importCodePlugin
|
|
255
|
+
*/
|
|
256
|
+
importedFiles?: string[];
|
|
257
|
+
/**
|
|
258
|
+
* Links that extracted by linksPlugin
|
|
259
|
+
*/
|
|
260
|
+
links?: MarkdownLink[];
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* Type of `slugify` function
|
|
264
|
+
*/
|
|
265
|
+
declare type MarkdownSlugifyFunction = (str: string) => string;
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* Create vuepress customized markdown-it instance
|
|
269
|
+
*/
|
|
270
|
+
declare const createMarkdown: ({ anchor, assets, code, component, emoji, frontmatter, headers, title, importCode, links, sfc, slugify, toc, ...markdownItOptions }?: MarkdownOptions) => Markdown;
|
|
271
|
+
|
|
272
|
+
export { AnchorPluginOptions, AssetsPluginOptions, CodePluginOptions, EmojiPluginOptions, HighlightLanguage, HighlightLinesRange, ImportCodePluginOptions, ImportCodeTokenMeta, LinksPluginOptions, Markdown, MarkdownEnv, MarkdownHeader, MarkdownLink, MarkdownOptions, MarkdownSlugifyFunction, assetsPlugin, codePlugin, createImportCodeBlockRule, createMarkdown, importCodePlugin, isHighlightLine, languageBash, languageCsharp, languageDocker, languageFsharp, languageJavascript, languageKotlin, languageMarkdown, languagePython, languageRuby, languageRust, languageStylus, languageTypescript, languageYaml, linksPlugin, resolveHighlightLines, resolveImportCode, resolveLanguage, resolveLineNumbers, resolveLink, resolvePaths, resolveVPre };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,583 @@
|
|
|
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
|
+
// src/markdown.ts
|
|
8
|
+
import { slugify as defaultSlugify } from "@mdit-vue/shared";
|
|
9
|
+
import MarkdownIt from "markdown-it";
|
|
10
|
+
|
|
11
|
+
// src/plugins.ts
|
|
12
|
+
import {
|
|
13
|
+
componentPlugin
|
|
14
|
+
} from "@mdit-vue/plugin-component";
|
|
15
|
+
import {
|
|
16
|
+
frontmatterPlugin
|
|
17
|
+
} from "@mdit-vue/plugin-frontmatter";
|
|
18
|
+
import {
|
|
19
|
+
headersPlugin
|
|
20
|
+
} from "@mdit-vue/plugin-headers";
|
|
21
|
+
import { sfcPlugin } from "@mdit-vue/plugin-sfc";
|
|
22
|
+
import { titlePlugin } from "@mdit-vue/plugin-title";
|
|
23
|
+
import { tocPlugin } from "@mdit-vue/plugin-toc";
|
|
24
|
+
|
|
25
|
+
// src/plugins/anchorPlugin.ts
|
|
26
|
+
import anchorPlugin from "markdown-it-anchor";
|
|
27
|
+
|
|
28
|
+
// src/plugins/assetsPlugin/resolveLink.ts
|
|
29
|
+
import { path } from "@vuepress/utils";
|
|
30
|
+
import { decode } from "mdurl";
|
|
31
|
+
var resolveLink = (link, relativePathPrefix, env) => {
|
|
32
|
+
let resolvedLink = decode(link);
|
|
33
|
+
if (/^\.{1,2}\//.test(link) && env.filePathRelative) {
|
|
34
|
+
resolvedLink = `${relativePathPrefix}/${path.join(
|
|
35
|
+
path.dirname(env.filePathRelative),
|
|
36
|
+
resolvedLink
|
|
37
|
+
)}`;
|
|
38
|
+
}
|
|
39
|
+
return resolvedLink;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
// src/plugins/assetsPlugin/assetsPlugin.ts
|
|
43
|
+
var assetsPlugin = (md, { relativePathPrefix = "@source" } = {}) => {
|
|
44
|
+
const rawImageRule = md.renderer.rules.image;
|
|
45
|
+
md.renderer.rules.image = (tokens, idx, options, env, self) => {
|
|
46
|
+
const token = tokens[idx];
|
|
47
|
+
const link = token.attrGet("src");
|
|
48
|
+
if (link) {
|
|
49
|
+
token.attrSet("src", resolveLink(link, relativePathPrefix, env));
|
|
50
|
+
}
|
|
51
|
+
return rawImageRule(tokens, idx, options, env, self);
|
|
52
|
+
};
|
|
53
|
+
const createHtmlRule = (rawHtmlRule) => (tokens, idx, options, env, self) => {
|
|
54
|
+
tokens[idx].content = tokens[idx].content.replace(
|
|
55
|
+
/(<img\b.*?src=")([^"]*)(")/gs,
|
|
56
|
+
(_, prefix, src, suffix) => `${prefix}${resolveLink(
|
|
57
|
+
src.trim(),
|
|
58
|
+
relativePathPrefix,
|
|
59
|
+
env
|
|
60
|
+
)}${suffix}`
|
|
61
|
+
).replace(
|
|
62
|
+
/(<img\b.*?srcset=")([^"]*)(")/gs,
|
|
63
|
+
(_, prefix, srcset, suffix) => `${prefix}${srcset.split(",").map(
|
|
64
|
+
(item) => item.trim().replace(
|
|
65
|
+
/^([^ ]*?)([ \n].*)?$/,
|
|
66
|
+
(_2, url, descriptor = "") => `${resolveLink(
|
|
67
|
+
url.trim(),
|
|
68
|
+
relativePathPrefix,
|
|
69
|
+
env
|
|
70
|
+
)}${descriptor.replace(/[ \n]+/g, " ").trimEnd()}`
|
|
71
|
+
)
|
|
72
|
+
).join(", ")}${suffix}`
|
|
73
|
+
);
|
|
74
|
+
return rawHtmlRule(tokens, idx, options, env, self);
|
|
75
|
+
};
|
|
76
|
+
const rawHtmlBlockRule = md.renderer.rules.html_block;
|
|
77
|
+
const rawHtmlInlineRule = md.renderer.rules.html_inline;
|
|
78
|
+
md.renderer.rules.html_block = createHtmlRule(rawHtmlBlockRule);
|
|
79
|
+
md.renderer.rules.html_inline = createHtmlRule(rawHtmlInlineRule);
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
// src/plugins/codePlugin/resolveHighlightLines.ts
|
|
83
|
+
var resolveHighlightLines = (info) => {
|
|
84
|
+
const match = info.match(/{([\d,-]+)}/);
|
|
85
|
+
if (match === null) {
|
|
86
|
+
return null;
|
|
87
|
+
}
|
|
88
|
+
return match[1].split(",").map((item) => {
|
|
89
|
+
const range = item.split("-");
|
|
90
|
+
if (range.length === 1) {
|
|
91
|
+
range.push(range[0]);
|
|
92
|
+
}
|
|
93
|
+
return range.map((str) => Number.parseInt(str, 10));
|
|
94
|
+
});
|
|
95
|
+
};
|
|
96
|
+
var isHighlightLine = (lineNumber, ranges) => ranges.some(([start, end]) => lineNumber >= start && lineNumber <= end);
|
|
97
|
+
|
|
98
|
+
// src/plugins/codePlugin/languages.ts
|
|
99
|
+
var languages_exports = {};
|
|
100
|
+
__export(languages_exports, {
|
|
101
|
+
languageBash: () => languageBash,
|
|
102
|
+
languageCsharp: () => languageCsharp,
|
|
103
|
+
languageDocker: () => languageDocker,
|
|
104
|
+
languageFsharp: () => languageFsharp,
|
|
105
|
+
languageJavascript: () => languageJavascript,
|
|
106
|
+
languageKotlin: () => languageKotlin,
|
|
107
|
+
languageMarkdown: () => languageMarkdown,
|
|
108
|
+
languagePython: () => languagePython,
|
|
109
|
+
languageRuby: () => languageRuby,
|
|
110
|
+
languageRust: () => languageRust,
|
|
111
|
+
languageStylus: () => languageStylus,
|
|
112
|
+
languageTypescript: () => languageTypescript,
|
|
113
|
+
languageYaml: () => languageYaml
|
|
114
|
+
});
|
|
115
|
+
var languageBash = {
|
|
116
|
+
name: "bash",
|
|
117
|
+
ext: "sh",
|
|
118
|
+
aliases: ["bash", "sh", "shell", "zsh"]
|
|
119
|
+
};
|
|
120
|
+
var languageCsharp = {
|
|
121
|
+
name: "csharp",
|
|
122
|
+
ext: "cs",
|
|
123
|
+
aliases: ["cs", "csharp"]
|
|
124
|
+
};
|
|
125
|
+
var languageDocker = {
|
|
126
|
+
name: "docker",
|
|
127
|
+
ext: "docker",
|
|
128
|
+
aliases: ["docker", "dockerfile"]
|
|
129
|
+
};
|
|
130
|
+
var languageFsharp = {
|
|
131
|
+
name: "fsharp",
|
|
132
|
+
ext: "fs",
|
|
133
|
+
aliases: ["fs", "fsharp"]
|
|
134
|
+
};
|
|
135
|
+
var languageJavascript = {
|
|
136
|
+
name: "javascript",
|
|
137
|
+
ext: "js",
|
|
138
|
+
aliases: ["javascript", "js"]
|
|
139
|
+
};
|
|
140
|
+
var languageKotlin = {
|
|
141
|
+
name: "kotlin",
|
|
142
|
+
ext: "kt",
|
|
143
|
+
aliases: ["kotlin", "kt"]
|
|
144
|
+
};
|
|
145
|
+
var languageMarkdown = {
|
|
146
|
+
name: "markdown",
|
|
147
|
+
ext: "md",
|
|
148
|
+
aliases: ["markdown", "md"]
|
|
149
|
+
};
|
|
150
|
+
var languagePython = {
|
|
151
|
+
name: "python",
|
|
152
|
+
ext: "py",
|
|
153
|
+
aliases: ["py", "python"]
|
|
154
|
+
};
|
|
155
|
+
var languageRuby = {
|
|
156
|
+
name: "ruby",
|
|
157
|
+
ext: "rb",
|
|
158
|
+
aliases: ["rb", "ruby"]
|
|
159
|
+
};
|
|
160
|
+
var languageRust = {
|
|
161
|
+
name: "rust",
|
|
162
|
+
ext: "rs",
|
|
163
|
+
aliases: ["rs", "rust"]
|
|
164
|
+
};
|
|
165
|
+
var languageStylus = {
|
|
166
|
+
name: "stylus",
|
|
167
|
+
ext: "styl",
|
|
168
|
+
aliases: ["styl", "stylus"]
|
|
169
|
+
};
|
|
170
|
+
var languageTypescript = {
|
|
171
|
+
name: "typescript",
|
|
172
|
+
ext: "ts",
|
|
173
|
+
aliases: ["ts", "typescript"]
|
|
174
|
+
};
|
|
175
|
+
var languageYaml = {
|
|
176
|
+
name: "yaml",
|
|
177
|
+
ext: "yml",
|
|
178
|
+
aliases: ["yaml", "yml"]
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
// src/plugins/codePlugin/resolveLanguage.ts
|
|
182
|
+
var languagesMap;
|
|
183
|
+
var getLanguagesMap = () => {
|
|
184
|
+
if (!languagesMap) {
|
|
185
|
+
languagesMap = Object.values(languages_exports).reduce((result, item) => {
|
|
186
|
+
item.aliases.forEach((alias) => {
|
|
187
|
+
result[alias] = item;
|
|
188
|
+
});
|
|
189
|
+
return result;
|
|
190
|
+
}, {});
|
|
191
|
+
}
|
|
192
|
+
return languagesMap;
|
|
193
|
+
};
|
|
194
|
+
var resolveLanguage = (info) => {
|
|
195
|
+
const alias = info.match(/^([^ :[{]+)/)?.[1] || "text";
|
|
196
|
+
return getLanguagesMap()[alias] ?? {
|
|
197
|
+
name: alias,
|
|
198
|
+
ext: alias,
|
|
199
|
+
aliases: [alias]
|
|
200
|
+
};
|
|
201
|
+
};
|
|
202
|
+
|
|
203
|
+
// src/plugins/codePlugin/resolveLineNumbers.ts
|
|
204
|
+
var resolveLineNumbers = (info) => {
|
|
205
|
+
if (/:line-numbers\b/.test(info)) {
|
|
206
|
+
return true;
|
|
207
|
+
}
|
|
208
|
+
if (/:no-line-numbers\b/.test(info)) {
|
|
209
|
+
return false;
|
|
210
|
+
}
|
|
211
|
+
return null;
|
|
212
|
+
};
|
|
213
|
+
|
|
214
|
+
// src/plugins/codePlugin/resolveVPre.ts
|
|
215
|
+
var resolveVPre = (info) => {
|
|
216
|
+
if (/:v-pre\b/.test(info)) {
|
|
217
|
+
return true;
|
|
218
|
+
}
|
|
219
|
+
if (/:no-v-pre\b/.test(info)) {
|
|
220
|
+
return false;
|
|
221
|
+
}
|
|
222
|
+
return null;
|
|
223
|
+
};
|
|
224
|
+
|
|
225
|
+
// src/plugins/codePlugin/codePlugin.ts
|
|
226
|
+
var codePlugin = (md, {
|
|
227
|
+
highlightLines = true,
|
|
228
|
+
lineNumbers = true,
|
|
229
|
+
preWrapper = true,
|
|
230
|
+
vPre: { block: vPreBlock = true, inline: vPreInline = true } = {}
|
|
231
|
+
} = {}) => {
|
|
232
|
+
md.renderer.rules.fence = (tokens, idx, options, env, slf) => {
|
|
233
|
+
const token = tokens[idx];
|
|
234
|
+
const info = token.info ? md.utils.unescapeAll(token.info).trim() : "";
|
|
235
|
+
const language = resolveLanguage(info);
|
|
236
|
+
const languageClass = `${options.langPrefix}${language.name}`;
|
|
237
|
+
const code = options.highlight?.(token.content, language.name, "") || md.utils.escapeHtml(token.content);
|
|
238
|
+
let result = code.startsWith("<pre") ? code : `<pre class="${languageClass}"><code>${code}</code></pre>`;
|
|
239
|
+
const useVPre = resolveVPre(info) ?? vPreBlock;
|
|
240
|
+
if (useVPre) {
|
|
241
|
+
result = `<pre v-pre${result.slice("<pre".length)}`;
|
|
242
|
+
}
|
|
243
|
+
if (!preWrapper) {
|
|
244
|
+
return result;
|
|
245
|
+
}
|
|
246
|
+
const lines = code.split("\n").slice(0, -1);
|
|
247
|
+
const highlightLinesRanges = highlightLines ? resolveHighlightLines(info) : null;
|
|
248
|
+
if (highlightLinesRanges) {
|
|
249
|
+
const highlightLinesCode = lines.map((_, index) => {
|
|
250
|
+
if (isHighlightLine(index + 1, highlightLinesRanges)) {
|
|
251
|
+
return '<div class="highlight-line"> </div>';
|
|
252
|
+
}
|
|
253
|
+
return "<br>";
|
|
254
|
+
}).join("");
|
|
255
|
+
result = `${result}<div class="highlight-lines">${highlightLinesCode}</div>`;
|
|
256
|
+
}
|
|
257
|
+
const useLineNumbers = resolveLineNumbers(info) ?? (typeof lineNumbers === "number" ? lines.length >= lineNumbers : lineNumbers);
|
|
258
|
+
if (useLineNumbers) {
|
|
259
|
+
const lineNumbersCode = lines.map(() => `<div class="line-number"></div>`).join("");
|
|
260
|
+
result = `${result}<div class="line-numbers" aria-hidden="true">${lineNumbersCode}</div>`;
|
|
261
|
+
}
|
|
262
|
+
result = `<div class="${languageClass} ext-${language.ext}${useLineNumbers ? " line-numbers-mode" : ""}">${result}</div>`;
|
|
263
|
+
return result;
|
|
264
|
+
};
|
|
265
|
+
if (vPreInline) {
|
|
266
|
+
const rawInlineCodeRule = md.renderer.rules.code_inline;
|
|
267
|
+
md.renderer.rules.code_inline = (tokens, idx, options, env, slf) => {
|
|
268
|
+
const result = rawInlineCodeRule(tokens, idx, options, env, slf);
|
|
269
|
+
return `<code v-pre${result.slice("<code".length)}`;
|
|
270
|
+
};
|
|
271
|
+
}
|
|
272
|
+
};
|
|
273
|
+
|
|
274
|
+
// src/plugins/emojiPlugin.ts
|
|
275
|
+
import emojiPlugin from "markdown-it-emoji";
|
|
276
|
+
|
|
277
|
+
// src/plugins/importCodePlugin/createImportCodeBlockRule.ts
|
|
278
|
+
import { path as path2 } from "@vuepress/utils";
|
|
279
|
+
var MIN_LENGTH = 9;
|
|
280
|
+
var START_CODES = [64, 91, 99, 111, 100, 101];
|
|
281
|
+
var SYNTAX_RE = /^@\[code(?:{(?:(\d+)?-(\d+)?)})?(?: ([^\]]+))?\]\(([^)]*)\)/;
|
|
282
|
+
var createImportCodeBlockRule = ({ handleImportPath = (str) => str }) => (state, startLine, endLine, silent) => {
|
|
283
|
+
if (state.sCount[startLine] - state.blkIndent >= 4) {
|
|
284
|
+
return false;
|
|
285
|
+
}
|
|
286
|
+
const pos = state.bMarks[startLine] + state.tShift[startLine];
|
|
287
|
+
const max = state.eMarks[startLine];
|
|
288
|
+
if (pos + MIN_LENGTH > max)
|
|
289
|
+
return false;
|
|
290
|
+
for (let i = 0; i < START_CODES.length; i += 1) {
|
|
291
|
+
if (state.src.charCodeAt(pos + i) !== START_CODES[i]) {
|
|
292
|
+
return false;
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
const match = state.src.slice(pos, max).match(SYNTAX_RE);
|
|
296
|
+
if (!match)
|
|
297
|
+
return false;
|
|
298
|
+
if (silent)
|
|
299
|
+
return true;
|
|
300
|
+
const [, lineStart, lineEnd, info, importPath] = match;
|
|
301
|
+
const meta = {
|
|
302
|
+
importPath: handleImportPath(importPath),
|
|
303
|
+
lineStart: lineStart ? Number.parseInt(lineStart, 10) : 0,
|
|
304
|
+
lineEnd: lineEnd ? Number.parseInt(lineEnd, 10) : void 0
|
|
305
|
+
};
|
|
306
|
+
const token = state.push("import_code", "code", 0);
|
|
307
|
+
token.info = info ?? path2.extname(meta.importPath).slice(1);
|
|
308
|
+
token.markup = "```";
|
|
309
|
+
token.map = [startLine, startLine + 1];
|
|
310
|
+
token.meta = meta;
|
|
311
|
+
state.line = startLine + 1;
|
|
312
|
+
return true;
|
|
313
|
+
};
|
|
314
|
+
|
|
315
|
+
// src/plugins/importCodePlugin/resolveImportCode.ts
|
|
316
|
+
import { fs, path as path3 } from "@vuepress/utils";
|
|
317
|
+
var resolveImportCode = ({ importPath, lineStart, lineEnd }, { filePath }) => {
|
|
318
|
+
let importFilePath = importPath;
|
|
319
|
+
if (!path3.isAbsolute(importPath)) {
|
|
320
|
+
if (!filePath) {
|
|
321
|
+
return {
|
|
322
|
+
importFilePath: null,
|
|
323
|
+
importCode: "Error when resolving path"
|
|
324
|
+
};
|
|
325
|
+
}
|
|
326
|
+
importFilePath = path3.resolve(filePath, "..", importPath);
|
|
327
|
+
}
|
|
328
|
+
if (!fs.existsSync(importFilePath)) {
|
|
329
|
+
return {
|
|
330
|
+
importFilePath,
|
|
331
|
+
importCode: "File not found"
|
|
332
|
+
};
|
|
333
|
+
}
|
|
334
|
+
const fileContent = fs.readFileSync(importFilePath).toString();
|
|
335
|
+
return {
|
|
336
|
+
importFilePath,
|
|
337
|
+
importCode: fileContent.split("\n").slice(lineStart ? lineStart - 1 : lineStart, lineEnd).join("\n").replace(/\n?$/, "\n")
|
|
338
|
+
};
|
|
339
|
+
};
|
|
340
|
+
|
|
341
|
+
// src/plugins/importCodePlugin/importCodePlugin.ts
|
|
342
|
+
var importCodePlugin = (md, options = {}) => {
|
|
343
|
+
md.block.ruler.before(
|
|
344
|
+
"fence",
|
|
345
|
+
"import_code",
|
|
346
|
+
createImportCodeBlockRule(options),
|
|
347
|
+
{
|
|
348
|
+
alt: ["paragraph", "reference", "blockquote", "list"]
|
|
349
|
+
}
|
|
350
|
+
);
|
|
351
|
+
md.renderer.rules.import_code = (tokens, idx, options2, env, slf) => {
|
|
352
|
+
const token = tokens[idx];
|
|
353
|
+
const { importFilePath, importCode } = resolveImportCode(token.meta, env);
|
|
354
|
+
token.content = importCode;
|
|
355
|
+
if (importFilePath) {
|
|
356
|
+
const importedFiles = env.importedFiles || (env.importedFiles = []);
|
|
357
|
+
importedFiles.push(importFilePath);
|
|
358
|
+
}
|
|
359
|
+
return md.renderer.rules.fence(tokens, idx, options2, env, slf);
|
|
360
|
+
};
|
|
361
|
+
};
|
|
362
|
+
|
|
363
|
+
// src/plugins/linksPlugin/linksPlugin.ts
|
|
364
|
+
import { isLinkExternal } from "@vuepress/shared";
|
|
365
|
+
|
|
366
|
+
// src/plugins/linksPlugin/resolvePaths.ts
|
|
367
|
+
import { removeLeadingSlash } from "@vuepress/shared";
|
|
368
|
+
import { path as path4 } from "@vuepress/utils";
|
|
369
|
+
var resolvePaths = (rawPath, base, filePathRelative) => {
|
|
370
|
+
let absolutePath;
|
|
371
|
+
let relativePath;
|
|
372
|
+
if (rawPath.startsWith("/")) {
|
|
373
|
+
if (rawPath.endsWith(".md")) {
|
|
374
|
+
absolutePath = path4.join(base, rawPath);
|
|
375
|
+
relativePath = removeLeadingSlash(rawPath);
|
|
376
|
+
} else {
|
|
377
|
+
absolutePath = rawPath;
|
|
378
|
+
relativePath = path4.relative(base, absolutePath);
|
|
379
|
+
}
|
|
380
|
+
} else {
|
|
381
|
+
if (filePathRelative) {
|
|
382
|
+
relativePath = path4.join(
|
|
383
|
+
path4.dirname(encodeURI(filePathRelative)),
|
|
384
|
+
rawPath
|
|
385
|
+
);
|
|
386
|
+
absolutePath = path4.join(base, relativePath);
|
|
387
|
+
} else {
|
|
388
|
+
relativePath = rawPath.replace(/^(?:\.\/)?(.*)$/, "$1");
|
|
389
|
+
absolutePath = relativePath;
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
return {
|
|
393
|
+
absolutePath,
|
|
394
|
+
relativePath
|
|
395
|
+
};
|
|
396
|
+
};
|
|
397
|
+
|
|
398
|
+
// src/plugins/linksPlugin/linksPlugin.ts
|
|
399
|
+
var linksPlugin = (md, options = {}) => {
|
|
400
|
+
const internalTag = options.internalTag || "RouterLink";
|
|
401
|
+
const externalAttrs = {
|
|
402
|
+
target: "_blank",
|
|
403
|
+
rel: "noopener noreferrer",
|
|
404
|
+
...options.externalAttrs
|
|
405
|
+
};
|
|
406
|
+
let hasOpenInternalLink = false;
|
|
407
|
+
const handleLinkOpen = (tokens, idx, env) => {
|
|
408
|
+
const token = tokens[idx];
|
|
409
|
+
const hrefIndex = token.attrIndex("href");
|
|
410
|
+
if (hrefIndex < 0) {
|
|
411
|
+
return;
|
|
412
|
+
}
|
|
413
|
+
const hrefAttr = token.attrs[hrefIndex];
|
|
414
|
+
const hrefLink = hrefAttr[1];
|
|
415
|
+
const { base = "/", filePathRelative = null } = env;
|
|
416
|
+
if (isLinkExternal(hrefLink, base)) {
|
|
417
|
+
Object.entries(externalAttrs).forEach(
|
|
418
|
+
([key, val]) => token.attrSet(key, val)
|
|
419
|
+
);
|
|
420
|
+
return;
|
|
421
|
+
}
|
|
422
|
+
const internalLinkMatch = hrefLink.match(
|
|
423
|
+
/^((?:.*)(?:\/|\.md|\.html))(#.*)?$/
|
|
424
|
+
);
|
|
425
|
+
if (!internalLinkMatch) {
|
|
426
|
+
return;
|
|
427
|
+
}
|
|
428
|
+
const rawPath = internalLinkMatch[1];
|
|
429
|
+
const rawHash = internalLinkMatch[2] || "";
|
|
430
|
+
const { relativePath, absolutePath } = resolvePaths(
|
|
431
|
+
rawPath,
|
|
432
|
+
base,
|
|
433
|
+
filePathRelative
|
|
434
|
+
);
|
|
435
|
+
const normalizedPath = absolutePath.replace(new RegExp(`^${base}`), "/").replace(/(^|\/)(README|index).md$/i, "$1").replace(/\.md$/, ".html");
|
|
436
|
+
if (internalTag === "RouterLink") {
|
|
437
|
+
token.tag = internalTag;
|
|
438
|
+
hrefAttr[0] = "to";
|
|
439
|
+
hasOpenInternalLink = true;
|
|
440
|
+
}
|
|
441
|
+
hrefAttr[1] = `${normalizedPath}${rawHash}`;
|
|
442
|
+
const links = env.links || (env.links = []);
|
|
443
|
+
links.push({
|
|
444
|
+
raw: hrefLink,
|
|
445
|
+
relative: relativePath,
|
|
446
|
+
absolute: absolutePath
|
|
447
|
+
});
|
|
448
|
+
};
|
|
449
|
+
md.renderer.rules.link_open = (tokens, idx, options2, env, self) => {
|
|
450
|
+
handleLinkOpen(tokens, idx, env);
|
|
451
|
+
return self.renderToken(tokens, idx, options2);
|
|
452
|
+
};
|
|
453
|
+
md.renderer.rules.link_close = (tokens, idx, options2, env, self) => {
|
|
454
|
+
if (hasOpenInternalLink) {
|
|
455
|
+
hasOpenInternalLink = false;
|
|
456
|
+
tokens[idx].tag = internalTag;
|
|
457
|
+
}
|
|
458
|
+
return self.renderToken(tokens, idx, options2);
|
|
459
|
+
};
|
|
460
|
+
};
|
|
461
|
+
|
|
462
|
+
// src/markdown.ts
|
|
463
|
+
var createMarkdown = ({
|
|
464
|
+
anchor,
|
|
465
|
+
assets,
|
|
466
|
+
code,
|
|
467
|
+
component,
|
|
468
|
+
emoji,
|
|
469
|
+
frontmatter,
|
|
470
|
+
headers,
|
|
471
|
+
title,
|
|
472
|
+
importCode,
|
|
473
|
+
links,
|
|
474
|
+
sfc,
|
|
475
|
+
slugify = defaultSlugify,
|
|
476
|
+
toc,
|
|
477
|
+
...markdownItOptions
|
|
478
|
+
} = {}) => {
|
|
479
|
+
const md = MarkdownIt({
|
|
480
|
+
...markdownItOptions,
|
|
481
|
+
html: true
|
|
482
|
+
});
|
|
483
|
+
if (emoji !== false) {
|
|
484
|
+
md.use(emojiPlugin, emoji);
|
|
485
|
+
}
|
|
486
|
+
if (anchor !== false) {
|
|
487
|
+
md.use(anchorPlugin, {
|
|
488
|
+
level: [1, 2, 3, 4, 5, 6],
|
|
489
|
+
slugify,
|
|
490
|
+
permalink: anchorPlugin.permalink.ariaHidden({
|
|
491
|
+
class: "header-anchor",
|
|
492
|
+
symbol: "#",
|
|
493
|
+
space: true,
|
|
494
|
+
placement: "before"
|
|
495
|
+
}),
|
|
496
|
+
...anchor
|
|
497
|
+
});
|
|
498
|
+
}
|
|
499
|
+
if (toc !== false) {
|
|
500
|
+
md.use(tocPlugin, {
|
|
501
|
+
level: [2, 3],
|
|
502
|
+
slugify,
|
|
503
|
+
linkTag: "router-link",
|
|
504
|
+
...toc
|
|
505
|
+
});
|
|
506
|
+
}
|
|
507
|
+
if (headers !== false) {
|
|
508
|
+
md.use(headersPlugin, {
|
|
509
|
+
level: [2, 3],
|
|
510
|
+
slugify,
|
|
511
|
+
...headers
|
|
512
|
+
});
|
|
513
|
+
}
|
|
514
|
+
if (title !== false) {
|
|
515
|
+
md.use(titlePlugin);
|
|
516
|
+
}
|
|
517
|
+
if (component !== false) {
|
|
518
|
+
md.use(componentPlugin);
|
|
519
|
+
}
|
|
520
|
+
if (frontmatter !== false) {
|
|
521
|
+
md.use(frontmatterPlugin, {
|
|
522
|
+
...frontmatter,
|
|
523
|
+
grayMatterOptions: {
|
|
524
|
+
excerpt: true,
|
|
525
|
+
excerpt_separator: "<!-- more -->",
|
|
526
|
+
...frontmatter?.grayMatterOptions
|
|
527
|
+
}
|
|
528
|
+
});
|
|
529
|
+
}
|
|
530
|
+
if (assets !== false) {
|
|
531
|
+
md.use(assetsPlugin, assets);
|
|
532
|
+
}
|
|
533
|
+
if (sfc !== false) {
|
|
534
|
+
md.use(sfcPlugin, sfc);
|
|
535
|
+
}
|
|
536
|
+
if (links !== false) {
|
|
537
|
+
md.use(linksPlugin, links);
|
|
538
|
+
}
|
|
539
|
+
if (code !== false) {
|
|
540
|
+
md.use(codePlugin, code);
|
|
541
|
+
}
|
|
542
|
+
if (importCode !== false) {
|
|
543
|
+
md.use(importCodePlugin, importCode);
|
|
544
|
+
}
|
|
545
|
+
return md;
|
|
546
|
+
};
|
|
547
|
+
export {
|
|
548
|
+
anchorPlugin,
|
|
549
|
+
assetsPlugin,
|
|
550
|
+
codePlugin,
|
|
551
|
+
componentPlugin,
|
|
552
|
+
createImportCodeBlockRule,
|
|
553
|
+
createMarkdown,
|
|
554
|
+
emojiPlugin,
|
|
555
|
+
frontmatterPlugin,
|
|
556
|
+
headersPlugin,
|
|
557
|
+
importCodePlugin,
|
|
558
|
+
isHighlightLine,
|
|
559
|
+
languageBash,
|
|
560
|
+
languageCsharp,
|
|
561
|
+
languageDocker,
|
|
562
|
+
languageFsharp,
|
|
563
|
+
languageJavascript,
|
|
564
|
+
languageKotlin,
|
|
565
|
+
languageMarkdown,
|
|
566
|
+
languagePython,
|
|
567
|
+
languageRuby,
|
|
568
|
+
languageRust,
|
|
569
|
+
languageStylus,
|
|
570
|
+
languageTypescript,
|
|
571
|
+
languageYaml,
|
|
572
|
+
linksPlugin,
|
|
573
|
+
resolveHighlightLines,
|
|
574
|
+
resolveImportCode,
|
|
575
|
+
resolveLanguage,
|
|
576
|
+
resolveLineNumbers,
|
|
577
|
+
resolveLink,
|
|
578
|
+
resolvePaths,
|
|
579
|
+
resolveVPre,
|
|
580
|
+
sfcPlugin,
|
|
581
|
+
titlePlugin,
|
|
582
|
+
tocPlugin
|
|
583
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vuepress/markdown",
|
|
3
|
-
"version": "2.0.0-beta.50-pre",
|
|
3
|
+
"version": "2.0.0-beta.50-pre.1",
|
|
4
4
|
"description": "Markdown package of VuePress",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"vuepress",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"main": "./dist/index.js",
|
|
25
25
|
"types": "./dist/index.d.ts",
|
|
26
26
|
"files": [
|
|
27
|
-
"
|
|
27
|
+
"dist"
|
|
28
28
|
],
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"@mdit-vue/plugin-component": "^0.9.0",
|
|
@@ -37,8 +37,8 @@
|
|
|
37
37
|
"@mdit-vue/types": "^0.9.0",
|
|
38
38
|
"@types/markdown-it": "^12.2.3",
|
|
39
39
|
"@types/markdown-it-emoji": "^2.0.2",
|
|
40
|
-
"@vuepress/shared": "2.0.0-beta.50-pre",
|
|
41
|
-
"@vuepress/utils": "2.0.0-beta.50-pre",
|
|
40
|
+
"@vuepress/shared": "2.0.0-beta.50-pre.1",
|
|
41
|
+
"@vuepress/utils": "2.0.0-beta.50-pre.1",
|
|
42
42
|
"markdown-it": "^13.0.1",
|
|
43
43
|
"markdown-it-anchor": "^8.6.4",
|
|
44
44
|
"markdown-it-emoji": "^2.0.2",
|