@vuepress/markdown 2.0.0-beta.22 → 2.0.0-beta.27
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/lib/plugins/anchorPlugin.d.ts +2 -3
- package/lib/plugins/anchorPlugin.js +2 -2
- package/lib/plugins/assetsPlugin/assetsPlugin.js +2 -2
- package/lib/plugins/assetsPlugin/resolveLink.js +1 -1
- package/lib/plugins/codePlugin/codePlugin.d.ts +4 -1
- package/lib/plugins/codePlugin/codePlugin.js +15 -17
- package/lib/plugins/extractHeadersPlugin.js +1 -1
- package/lib/plugins/extractTitlePlugin.js +1 -1
- package/lib/plugins/importCodePlugin/importCodePlugin.js +2 -2
- package/lib/plugins/linksPlugin/linksPlugin.js +2 -2
- package/lib/plugins/linksPlugin/resolvePaths.js +3 -1
- package/lib/plugins/tocPlugin/createRenderHeaders.js +5 -5
- package/lib/plugins/tocPlugin/tocPlugin.js +3 -3
- package/lib/types.d.ts +1 -1
- package/lib/utils/resolveHeadersFromTokens.d.ts +1 -1
- package/lib/utils/resolveHeadersFromTokens.js +2 -2
- package/lib/utils/resolveTitleFromToken.d.ts +1 -1
- package/lib/utils/resolveTitleFromToken.js +1 -1
- package/package.json +7 -7
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
export declare type AnchorPluginOptions = AnchorOptions;
|
|
1
|
+
import anchorPlugin from 'markdown-it-anchor';
|
|
2
|
+
export declare type AnchorPluginOptions = anchorPlugin.AnchorOptions;
|
|
4
3
|
export { anchorPlugin };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.anchorPlugin = void 0;
|
|
4
|
-
const
|
|
5
|
-
exports.anchorPlugin =
|
|
4
|
+
const markdown_it_anchor_1 = require("markdown-it-anchor");
|
|
5
|
+
exports.anchorPlugin = markdown_it_anchor_1.default;
|
|
@@ -14,14 +14,14 @@ const assetsPlugin = (md, { relativePathPrefix = '@source' } = {}) => {
|
|
|
14
14
|
const link = token.attrGet('src');
|
|
15
15
|
if (link) {
|
|
16
16
|
// replace the original link with resolved link
|
|
17
|
-
token.attrSet('src', resolveLink_1.resolveLink(link, relativePathPrefix, env));
|
|
17
|
+
token.attrSet('src', (0, resolveLink_1.resolveLink)(link, relativePathPrefix, env));
|
|
18
18
|
}
|
|
19
19
|
return rawImageRule(tokens, idx, options, env, self);
|
|
20
20
|
};
|
|
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}${resolveLink_1.resolveLink(link, relativePathPrefix, env)}${suffix}`);
|
|
24
|
+
tokens[idx].content = tokens[idx].content.replace(/^( *<img\b.*src=")([^"]*)(")/s, (_, 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;
|
|
@@ -5,7 +5,7 @@ const utils_1 = require("@vuepress/utils");
|
|
|
5
5
|
const mdurl_1 = require("mdurl");
|
|
6
6
|
const resolveLink = (link, relativePathPrefix, env) => {
|
|
7
7
|
// decode link to ensure bundler can find the file correctly
|
|
8
|
-
let resolvedLink = mdurl_1.decode(link);
|
|
8
|
+
let resolvedLink = (0, mdurl_1.decode)(link);
|
|
9
9
|
// if the link is relative path, and the `env.filePathRelative` exists
|
|
10
10
|
// add `@source` alias to the link
|
|
11
11
|
if (/^\.{1,2}\//.test(link) && env.filePathRelative) {
|
|
@@ -6,8 +6,11 @@ export interface CodePluginOptions {
|
|
|
6
6
|
highlightLines?: boolean;
|
|
7
7
|
/**
|
|
8
8
|
* Enable line numbers or not
|
|
9
|
+
*
|
|
10
|
+
* - A `boolean` value is to enable line numbers or not.
|
|
11
|
+
* - A `number` value is the minimum number of lines to enable line numbers
|
|
9
12
|
*/
|
|
10
|
-
lineNumbers?: boolean;
|
|
13
|
+
lineNumbers?: boolean | number;
|
|
11
14
|
/**
|
|
12
15
|
* Wrap the `<pre>` tag with an extra `<div>` or not. Do not disable it unless you
|
|
13
16
|
* understand what's it for
|
|
@@ -15,27 +15,18 @@ const codePlugin = (md, { highlightLines = true, lineNumbers = true, preWrapper
|
|
|
15
15
|
const token = tokens[idx];
|
|
16
16
|
// get token info
|
|
17
17
|
const info = token.info ? md.utils.unescapeAll(token.info).trim() : '';
|
|
18
|
-
// resolve highlight line ranges from token info
|
|
19
|
-
let highlightLinesRanges = null;
|
|
20
|
-
if (highlightLines) {
|
|
21
|
-
highlightLinesRanges = resolveHighlightLines_1.resolveHighlightLines(info);
|
|
22
|
-
}
|
|
23
|
-
// resolve line-numbers mark from token info
|
|
24
|
-
const useLineNumbers = (_a = resolveLineNumbers_1.resolveLineNumbers(info)) !== null && _a !== void 0 ? _a : lineNumbers;
|
|
25
|
-
// resolve v-pre mark from token info
|
|
26
|
-
const useVPre = (_b = resolveVPre_1.resolveVPre(info)) !== null && _b !== void 0 ? _b : vPre;
|
|
27
18
|
// resolve language from token info
|
|
28
|
-
const language = resolveLanguage_1.resolveLanguage(info);
|
|
29
|
-
// the result of code and lang
|
|
30
|
-
let code = token.content;
|
|
31
|
-
// try to highlight code
|
|
32
|
-
code =
|
|
33
|
-
((_c = options.highlight) === null || _c === void 0 ? void 0 : _c.call(options, code, language.name, '')) || md.utils.escapeHtml(code);
|
|
19
|
+
const language = (0, resolveLanguage_1.resolveLanguage)(info);
|
|
34
20
|
const languageClass = `${options.langPrefix}${language.name}`;
|
|
21
|
+
// try to get highlighted code
|
|
22
|
+
const code = ((_a = options.highlight) === null || _a === void 0 ? void 0 : _a.call(options, token.content, language.name, '')) ||
|
|
23
|
+
md.utils.escapeHtml(token.content);
|
|
35
24
|
// wrap highlighted code with `<pre>` and `<code>`
|
|
36
25
|
let result = code.startsWith('<pre')
|
|
37
26
|
? code
|
|
38
27
|
: `<pre class="${languageClass}"><code>${code}</code></pre>`;
|
|
28
|
+
// resolve v-pre mark from token info
|
|
29
|
+
const useVPre = (_b = (0, resolveVPre_1.resolveVPre)(info)) !== null && _b !== void 0 ? _b : vPre;
|
|
39
30
|
if (useVPre) {
|
|
40
31
|
result = `<pre v-pre${result.slice('<pre'.length)}`;
|
|
41
32
|
}
|
|
@@ -45,12 +36,15 @@ const codePlugin = (md, { highlightLines = true, lineNumbers = true, preWrapper
|
|
|
45
36
|
}
|
|
46
37
|
// code fences always have an ending `\n`, so we should trim the last line
|
|
47
38
|
const lines = code.split('\n').slice(0, -1);
|
|
39
|
+
// resolve highlight line ranges from token info
|
|
40
|
+
const highlightLinesRanges = highlightLines
|
|
41
|
+
? (0, resolveHighlightLines_1.resolveHighlightLines)(info)
|
|
42
|
+
: null;
|
|
48
43
|
// generate highlight lines
|
|
49
44
|
if (highlightLinesRanges) {
|
|
50
|
-
const ranges = highlightLinesRanges;
|
|
51
45
|
const highlightLinesCode = lines
|
|
52
46
|
.map((_, index) => {
|
|
53
|
-
if (resolveHighlightLines_1.isHighlightLine(index + 1,
|
|
47
|
+
if ((0, resolveHighlightLines_1.isHighlightLine)(index + 1, highlightLinesRanges)) {
|
|
54
48
|
return '<div class="highlight-line"> </div>';
|
|
55
49
|
}
|
|
56
50
|
return '<br>';
|
|
@@ -58,6 +52,10 @@ const codePlugin = (md, { highlightLines = true, lineNumbers = true, preWrapper
|
|
|
58
52
|
.join('');
|
|
59
53
|
result = `${result}<div class="highlight-lines">${highlightLinesCode}</div>`;
|
|
60
54
|
}
|
|
55
|
+
// resolve line-numbers mark from token info
|
|
56
|
+
const useLineNumbers = (_c = (0, resolveLineNumbers_1.resolveLineNumbers)(info)) !== null && _c !== void 0 ? _c : (typeof lineNumbers === 'number'
|
|
57
|
+
? lines.length >= lineNumbers
|
|
58
|
+
: lineNumbers);
|
|
61
59
|
// generate line numbers
|
|
62
60
|
if (useLineNumbers) {
|
|
63
61
|
// generate line numbers code
|
|
@@ -12,7 +12,7 @@ const extractHeadersPlugin = (md, { level = [2, 3], slugify = utils_1.slugify, f
|
|
|
12
12
|
// push the rule to the end of the chain
|
|
13
13
|
// resolve headers from the parsed tokens
|
|
14
14
|
md.core.ruler.push('resolveExtractHeaders', (state) => {
|
|
15
|
-
headers = utils_1.resolveHeadersFromTokens(state.tokens, {
|
|
15
|
+
headers = (0, utils_1.resolveHeadersFromTokens)(state.tokens, {
|
|
16
16
|
level,
|
|
17
17
|
allowHtml: false,
|
|
18
18
|
escapeText: false,
|
|
@@ -12,7 +12,7 @@ const extractTitlePlugin = (md) => {
|
|
|
12
12
|
md.core.ruler.push('resolveExtractTitle', (state) => {
|
|
13
13
|
const tokenIdx = state.tokens.findIndex((token) => token.tag === 'h1');
|
|
14
14
|
if (tokenIdx > -1) {
|
|
15
|
-
title = utils_1.resolveTitleFromToken(state.tokens[tokenIdx + 1], {
|
|
15
|
+
title = (0, utils_1.resolveTitleFromToken)(state.tokens[tokenIdx + 1], {
|
|
16
16
|
escapeText: false,
|
|
17
17
|
allowHtml: false,
|
|
18
18
|
});
|
|
@@ -5,14 +5,14 @@ const createImportCodeBlockRule_1 = require("./createImportCodeBlockRule");
|
|
|
5
5
|
const resolveImportCode_1 = require("./resolveImportCode");
|
|
6
6
|
const importCodePlugin = (md, options = {}) => {
|
|
7
7
|
// add import_code block rule
|
|
8
|
-
md.block.ruler.before('fence', 'import_code', createImportCodeBlockRule_1.createImportCodeBlockRule(options), {
|
|
8
|
+
md.block.ruler.before('fence', 'import_code', (0, createImportCodeBlockRule_1.createImportCodeBlockRule)(options), {
|
|
9
9
|
alt: ['paragraph', 'reference', 'blockquote', 'list'],
|
|
10
10
|
});
|
|
11
11
|
// add import_code renderer rule
|
|
12
12
|
md.renderer.rules.import_code = (tokens, idx, options, env, slf) => {
|
|
13
13
|
const token = tokens[idx];
|
|
14
14
|
// use imported code as token content
|
|
15
|
-
const { importFilePath, importCode } = resolveImportCode_1.resolveImportCode(token.meta, env);
|
|
15
|
+
const { importFilePath, importCode } = (0, resolveImportCode_1.resolveImportCode)(token.meta, env);
|
|
16
16
|
token.content = importCode;
|
|
17
17
|
// extract imported files to env
|
|
18
18
|
if (importFilePath) {
|
|
@@ -40,7 +40,7 @@ const linksPlugin = (md, options = {}) => {
|
|
|
40
40
|
// get `base` and `filePathRelative` from `env`
|
|
41
41
|
const { base = '/', filePathRelative = null, frontmatter = {} } = env;
|
|
42
42
|
// check if a link is an external link
|
|
43
|
-
if (shared_1.isLinkExternal(hrefLink, base)) {
|
|
43
|
+
if ((0, shared_1.isLinkExternal)(hrefLink, base)) {
|
|
44
44
|
// set `externalAttrs` to current token
|
|
45
45
|
Object.entries(externalAttrs).forEach(([key, val]) => token.attrSet(key, val));
|
|
46
46
|
// check if we should render external icon
|
|
@@ -65,7 +65,7 @@ const linksPlugin = (md, options = {}) => {
|
|
|
65
65
|
const rawPath = internalLinkMatch[1];
|
|
66
66
|
const rawHash = internalLinkMatch[2] || '';
|
|
67
67
|
// resolve relative and absolute path
|
|
68
|
-
const { relativePath, absolutePath } = resolvePaths_1.resolvePaths(rawPath, base, filePathRelative);
|
|
68
|
+
const { relativePath, absolutePath } = (0, resolvePaths_1.resolvePaths)(rawPath, base, filePathRelative);
|
|
69
69
|
// normalize markdown file path to route path
|
|
70
70
|
//
|
|
71
71
|
// we are removing the `base` from absolute path because it should not be
|
|
@@ -18,7 +18,9 @@ const resolvePaths = (rawPath, base, filePathRelative) => {
|
|
|
18
18
|
if (filePathRelative) {
|
|
19
19
|
// if `filePathRelative` is available
|
|
20
20
|
// resolve relative path according to `filePathRelative`
|
|
21
|
-
relativePath = utils_1.path.join(
|
|
21
|
+
relativePath = utils_1.path.join(
|
|
22
|
+
// file path may contain non-ASCII characters
|
|
23
|
+
utils_1.path.dirname(encodeURI(filePathRelative)), rawPath);
|
|
22
24
|
// resolve absolute path according to `base`
|
|
23
25
|
absolutePath = utils_1.path.join(base, relativePath);
|
|
24
26
|
}
|
|
@@ -3,12 +3,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.createRenderHeaders = void 0;
|
|
4
4
|
const shared_1 = require("@vuepress/shared");
|
|
5
5
|
const createRenderHeaders = ({ listTag, listClass, itemClass, linkTag, linkClass, }) => {
|
|
6
|
-
const listTagString = shared_1.htmlEscape(listTag);
|
|
7
|
-
const listClassString = listClass ? ` class="${shared_1.htmlEscape(listClass)}"` : '';
|
|
6
|
+
const listTagString = (0, shared_1.htmlEscape)(listTag);
|
|
7
|
+
const listClassString = listClass ? ` class="${(0, shared_1.htmlEscape)(listClass)}"` : '';
|
|
8
8
|
const itemTagString = 'li';
|
|
9
|
-
const itemClassString = itemClass ? ` class="${shared_1.htmlEscape(itemClass)}"` : '';
|
|
10
|
-
const linkTagString = shared_1.htmlEscape(linkTag);
|
|
11
|
-
const linkClassString = linkClass ? ` class="${shared_1.htmlEscape(linkClass)}` : '';
|
|
9
|
+
const itemClassString = itemClass ? ` class="${(0, shared_1.htmlEscape)(itemClass)}"` : '';
|
|
10
|
+
const linkTagString = (0, shared_1.htmlEscape)(linkTag);
|
|
11
|
+
const linkClassString = linkClass ? ` class="${(0, shared_1.htmlEscape)(linkClass)}` : '';
|
|
12
12
|
const linkTo = (slug) => linkTag === 'RouterLink' ? ` to="#${slug}"` : ` href="#${slug}"`;
|
|
13
13
|
const renderHeaders = (headers) => `\
|
|
14
14
|
<${listTagString}${listClassString}>\
|
|
@@ -20,7 +20,7 @@ const tocPlugin = (md, { pattern = /^\[\[toc\]\]$/i, slugify = utils_1.slugify,
|
|
|
20
20
|
// push the rule to the end of the chain
|
|
21
21
|
// resolve headers from the parsed tokens
|
|
22
22
|
md.core.ruler.push('resolveTocHeaders', (state) => {
|
|
23
|
-
headers = utils_1.resolveHeadersFromTokens(state.tokens, {
|
|
23
|
+
headers = (0, utils_1.resolveHeadersFromTokens)(state.tokens, {
|
|
24
24
|
level,
|
|
25
25
|
allowHtml: true,
|
|
26
26
|
escapeText: true,
|
|
@@ -30,14 +30,14 @@ const tocPlugin = (md, { pattern = /^\[\[toc\]\]$/i, slugify = utils_1.slugify,
|
|
|
30
30
|
return true;
|
|
31
31
|
});
|
|
32
32
|
// add toc syntax as a block rule
|
|
33
|
-
md.block.ruler.before('heading', 'toc', createTocBlockRule_1.createTocBlockRule({
|
|
33
|
+
md.block.ruler.before('heading', 'toc', (0, createTocBlockRule_1.createTocBlockRule)({
|
|
34
34
|
pattern,
|
|
35
35
|
containerTag,
|
|
36
36
|
containerClass,
|
|
37
37
|
}), {
|
|
38
38
|
alt: ['paragraph', 'reference', 'blockquote'],
|
|
39
39
|
});
|
|
40
|
-
const renderHeaders = createRenderHeaders_1.createRenderHeaders({
|
|
40
|
+
const renderHeaders = (0, createRenderHeaders_1.createRenderHeaders)({
|
|
41
41
|
listTag,
|
|
42
42
|
listClass,
|
|
43
43
|
itemClass,
|
package/lib/types.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import * as MarkdownIt from 'markdown-it';
|
|
2
1
|
import type { PageFrontmatter, PageHeader } from '@vuepress/shared';
|
|
2
|
+
import type * as MarkdownIt from 'markdown-it';
|
|
3
3
|
import type { AnchorPluginOptions, AssetsPluginOptions, CodePluginOptions, EmojiPluginOptions, ExtractHeadersPluginOptions, HoistTagsPluginOptions, ImportCodePluginOptions, LinksPluginOptions, TocPluginOptions } from './plugins';
|
|
4
4
|
export declare type Markdown = MarkdownIt;
|
|
5
5
|
export interface MarkdownOptions extends MarkdownIt.Options {
|
|
@@ -44,7 +44,7 @@ const resolveHeadersFromTokens = (tokens, { level, allowHtml, escapeText, slugif
|
|
|
44
44
|
if (!nextToken) {
|
|
45
45
|
return;
|
|
46
46
|
}
|
|
47
|
-
const title = resolveTitleFromToken_1.resolveTitleFromToken(nextToken, {
|
|
47
|
+
const title = (0, resolveTitleFromToken_1.resolveTitleFromToken)(nextToken, {
|
|
48
48
|
allowHtml,
|
|
49
49
|
escapeText,
|
|
50
50
|
});
|
|
@@ -54,7 +54,7 @@ const resolveHeadersFromTokens = (tokens, { level, allowHtml, escapeText, slugif
|
|
|
54
54
|
// push the header to tree
|
|
55
55
|
push({
|
|
56
56
|
level: headerLevel,
|
|
57
|
-
title: shared_1.isFunction(format) ? format(title) : title,
|
|
57
|
+
title: (0, shared_1.isFunction)(format) ? format(title) : title,
|
|
58
58
|
slug,
|
|
59
59
|
children: [],
|
|
60
60
|
});
|
|
@@ -30,7 +30,7 @@ const resolveTitleFromToken = (token, { allowHtml, escapeText, }) => {
|
|
|
30
30
|
if (escapeText) {
|
|
31
31
|
// escape the content of 'code_inline' and 'text'
|
|
32
32
|
if (item.type === 'code_inline' || item.type === 'text') {
|
|
33
|
-
return `${result}${shared_1.htmlEscape(item.content)}`;
|
|
33
|
+
return `${result}${(0, shared_1.htmlEscape)(item.content)}`;
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
36
|
// keep the content of 'emoji' and 'html_inline'
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vuepress/markdown",
|
|
3
|
-
"version": "2.0.0-beta.
|
|
3
|
+
"version": "2.0.0-beta.27",
|
|
4
4
|
"description": "Markdown package of VuePress",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"vuepress",
|
|
@@ -26,16 +26,16 @@
|
|
|
26
26
|
"clean": "rimraf lib *.tsbuildinfo"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@types/markdown-it": "^12.
|
|
30
|
-
"@vuepress/shared": "2.0.0-beta.
|
|
31
|
-
"@vuepress/utils": "2.0.0-beta.
|
|
32
|
-
"markdown-it": "^12.
|
|
33
|
-
"markdown-it-anchor": "^8.1
|
|
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",
|
|
33
|
+
"markdown-it-anchor": "^8.4.1",
|
|
34
34
|
"markdown-it-emoji": "^2.0.0",
|
|
35
35
|
"mdurl": "^1.0.1"
|
|
36
36
|
},
|
|
37
37
|
"publishConfig": {
|
|
38
38
|
"access": "public"
|
|
39
39
|
},
|
|
40
|
-
"gitHead": "
|
|
40
|
+
"gitHead": "2671a94fe6864e215eb84f318b7e657744a0bc5d"
|
|
41
41
|
}
|