@vuepress/markdown 2.0.0-beta.49 → 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 +38 -16
- package/lib/index.d.ts +0 -3
- package/lib/index.js +0 -19
- package/lib/markdown.d.ts +0 -5
- package/lib/markdown.js +0 -99
- package/lib/plugins/anchorPlugin.d.ts +0 -3
- package/lib/plugins/anchorPlugin.js +0 -5
- package/lib/plugins/assetsPlugin/assetsPlugin.d.ts +0 -11
- package/lib/plugins/assetsPlugin/assetsPlugin.js +0 -41
- package/lib/plugins/assetsPlugin/index.d.ts +0 -2
- package/lib/plugins/assetsPlugin/index.js +0 -18
- package/lib/plugins/assetsPlugin/resolveLink.d.ts +0 -2
- package/lib/plugins/assetsPlugin/resolveLink.js +0 -16
- package/lib/plugins/codePlugin/codePlugin.d.ts +0 -40
- package/lib/plugins/codePlugin/codePlugin.js +0 -78
- package/lib/plugins/codePlugin/index.d.ts +0 -6
- package/lib/plugins/codePlugin/index.js +0 -22
- package/lib/plugins/codePlugin/languages.d.ts +0 -38
- package/lib/plugins/codePlugin/languages.js +0 -68
- package/lib/plugins/codePlugin/resolveHighlightLines.d.ts +0 -9
- package/lib/plugins/codePlugin/resolveHighlightLines.js +0 -28
- package/lib/plugins/codePlugin/resolveLanguage.d.ts +0 -5
- package/lib/plugins/codePlugin/resolveLanguage.js +0 -40
- package/lib/plugins/codePlugin/resolveLineNumbers.d.ts +0 -4
- package/lib/plugins/codePlugin/resolveLineNumbers.js +0 -16
- package/lib/plugins/codePlugin/resolveVPre.d.ts +0 -4
- package/lib/plugins/codePlugin/resolveVPre.js +0 -16
- package/lib/plugins/emojiPlugin.d.ts +0 -3
- package/lib/plugins/emojiPlugin.js +0 -5
- package/lib/plugins/importCodePlugin/createImportCodeBlockRule.d.ts +0 -3
- package/lib/plugins/importCodePlugin/createImportCodeBlockRule.js +0 -52
- package/lib/plugins/importCodePlugin/importCodePlugin.d.ts +0 -8
- package/lib/plugins/importCodePlugin/importCodePlugin.js +0 -26
- package/lib/plugins/importCodePlugin/index.d.ts +0 -4
- package/lib/plugins/importCodePlugin/index.js +0 -20
- package/lib/plugins/importCodePlugin/resolveImportCode.d.ts +0 -6
- package/lib/plugins/importCodePlugin/resolveImportCode.js +0 -37
- package/lib/plugins/importCodePlugin/types.d.ts +0 -5
- package/lib/plugins/importCodePlugin/types.js +0 -2
- package/lib/plugins/index.d.ts +0 -12
- package/lib/plugins/index.js +0 -28
- package/lib/plugins/linksPlugin/index.d.ts +0 -2
- package/lib/plugins/linksPlugin/index.js +0 -18
- package/lib/plugins/linksPlugin/linksPlugin.d.ts +0 -28
- package/lib/plugins/linksPlugin/linksPlugin.js +0 -98
- package/lib/plugins/linksPlugin/resolvePaths.d.ts +0 -7
- package/lib/plugins/linksPlugin/resolvePaths.js +0 -51
- package/lib/types.d.ts +0 -71
- package/lib/types.js +0 -2
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createImportCodeBlockRule = void 0;
|
|
4
|
-
const utils_1 = require("@vuepress/utils");
|
|
5
|
-
// min length of the import code syntax, i.e. '@[code]()'
|
|
6
|
-
const MIN_LENGTH = 9;
|
|
7
|
-
// char codes of '@[code'
|
|
8
|
-
const START_CODES = [64, 91, 99, 111, 100, 101];
|
|
9
|
-
// regexp to match the import syntax
|
|
10
|
-
const SYNTAX_RE = /^@\[code(?:{(?:(\d+)?-(\d+)?)})?(?: ([^\]]+))?\]\(([^)]*)\)/;
|
|
11
|
-
const createImportCodeBlockRule = ({ handleImportPath = (str) => str }) => (state, startLine, endLine, silent) => {
|
|
12
|
-
// if it's indented more than 3 spaces, it should be a code block
|
|
13
|
-
/* istanbul ignore if */
|
|
14
|
-
if (state.sCount[startLine] - state.blkIndent >= 4) {
|
|
15
|
-
return false;
|
|
16
|
-
}
|
|
17
|
-
const pos = state.bMarks[startLine] + state.tShift[startLine];
|
|
18
|
-
const max = state.eMarks[startLine];
|
|
19
|
-
// return false if the length is shorter than min length
|
|
20
|
-
if (pos + MIN_LENGTH > max)
|
|
21
|
-
return false;
|
|
22
|
-
// check if it's matched the start
|
|
23
|
-
for (let i = 0; i < START_CODES.length; i += 1) {
|
|
24
|
-
if (state.src.charCodeAt(pos + i) !== START_CODES[i]) {
|
|
25
|
-
return false;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
// check if it's matched the syntax
|
|
29
|
-
const match = state.src.slice(pos, max).match(SYNTAX_RE);
|
|
30
|
-
if (!match)
|
|
31
|
-
return false;
|
|
32
|
-
// return true as we have matched the syntax
|
|
33
|
-
if (silent)
|
|
34
|
-
return true;
|
|
35
|
-
const [, lineStart, lineEnd, info, importPath] = match;
|
|
36
|
-
const meta = {
|
|
37
|
-
importPath: handleImportPath(importPath),
|
|
38
|
-
lineStart: lineStart ? Number.parseInt(lineStart, 10) : 0,
|
|
39
|
-
lineEnd: lineEnd ? Number.parseInt(lineEnd, 10) : undefined,
|
|
40
|
-
};
|
|
41
|
-
// create a import_code token
|
|
42
|
-
const token = state.push('import_code', 'code', 0);
|
|
43
|
-
// use user specified info, or fallback to file ext
|
|
44
|
-
token.info = info ?? utils_1.path.extname(meta.importPath).slice(1);
|
|
45
|
-
token.markup = '```';
|
|
46
|
-
token.map = [startLine, startLine + 1];
|
|
47
|
-
// store token meta to be used in renderer rule
|
|
48
|
-
token.meta = meta;
|
|
49
|
-
state.line = startLine + 1;
|
|
50
|
-
return true;
|
|
51
|
-
};
|
|
52
|
-
exports.createImportCodeBlockRule = createImportCodeBlockRule;
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { PluginWithOptions } from 'markdown-it';
|
|
2
|
-
export interface ImportCodePluginOptions {
|
|
3
|
-
/**
|
|
4
|
-
* A function to handle the import path
|
|
5
|
-
*/
|
|
6
|
-
handleImportPath?: (str: string) => string;
|
|
7
|
-
}
|
|
8
|
-
export declare const importCodePlugin: PluginWithOptions<ImportCodePluginOptions>;
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.importCodePlugin = void 0;
|
|
4
|
-
const createImportCodeBlockRule_1 = require("./createImportCodeBlockRule");
|
|
5
|
-
const resolveImportCode_1 = require("./resolveImportCode");
|
|
6
|
-
const importCodePlugin = (md, options = {}) => {
|
|
7
|
-
// add import_code block rule
|
|
8
|
-
md.block.ruler.before('fence', 'import_code', (0, createImportCodeBlockRule_1.createImportCodeBlockRule)(options), {
|
|
9
|
-
alt: ['paragraph', 'reference', 'blockquote', 'list'],
|
|
10
|
-
});
|
|
11
|
-
// add import_code renderer rule
|
|
12
|
-
md.renderer.rules.import_code = (tokens, idx, options, env, slf) => {
|
|
13
|
-
const token = tokens[idx];
|
|
14
|
-
// use imported code as token content
|
|
15
|
-
const { importFilePath, importCode } = (0, resolveImportCode_1.resolveImportCode)(token.meta, env);
|
|
16
|
-
token.content = importCode;
|
|
17
|
-
// extract imported files to env
|
|
18
|
-
if (importFilePath) {
|
|
19
|
-
const importedFiles = env.importedFiles || (env.importedFiles = []);
|
|
20
|
-
importedFiles.push(importFilePath);
|
|
21
|
-
}
|
|
22
|
-
// render the import_code token as a fence token
|
|
23
|
-
return md.renderer.rules.fence(tokens, idx, options, env, slf);
|
|
24
|
-
};
|
|
25
|
-
};
|
|
26
|
-
exports.importCodePlugin = importCodePlugin;
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./createImportCodeBlockRule"), exports);
|
|
18
|
-
__exportStar(require("./importCodePlugin"), exports);
|
|
19
|
-
__exportStar(require("./resolveImportCode"), exports);
|
|
20
|
-
__exportStar(require("./types"), exports);
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import type { MarkdownEnv } from '../../types';
|
|
2
|
-
import type { ImportCodeTokenMeta } from './types';
|
|
3
|
-
export declare const resolveImportCode: ({ importPath, lineStart, lineEnd }: ImportCodeTokenMeta, { filePath }: MarkdownEnv) => {
|
|
4
|
-
importFilePath: string | null;
|
|
5
|
-
importCode: string;
|
|
6
|
-
};
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.resolveImportCode = void 0;
|
|
4
|
-
const utils_1 = require("@vuepress/utils");
|
|
5
|
-
const resolveImportCode = ({ importPath, lineStart, lineEnd }, { filePath }) => {
|
|
6
|
-
let importFilePath = importPath;
|
|
7
|
-
if (!utils_1.path.isAbsolute(importPath)) {
|
|
8
|
-
// if the importPath is relative path, we need to resolve it
|
|
9
|
-
// according to the markdown filePath
|
|
10
|
-
if (!filePath) {
|
|
11
|
-
return {
|
|
12
|
-
importFilePath: null,
|
|
13
|
-
importCode: 'Error when resolving path',
|
|
14
|
-
};
|
|
15
|
-
}
|
|
16
|
-
importFilePath = utils_1.path.resolve(filePath, '..', importPath);
|
|
17
|
-
}
|
|
18
|
-
// check file existence
|
|
19
|
-
if (!utils_1.fs.existsSync(importFilePath)) {
|
|
20
|
-
return {
|
|
21
|
-
importFilePath,
|
|
22
|
-
importCode: 'File not found',
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
// read file content
|
|
26
|
-
const fileContent = utils_1.fs.readFileSync(importFilePath).toString();
|
|
27
|
-
// resolve partial import
|
|
28
|
-
return {
|
|
29
|
-
importFilePath,
|
|
30
|
-
importCode: fileContent
|
|
31
|
-
.split('\n')
|
|
32
|
-
.slice(lineStart ? lineStart - 1 : lineStart, lineEnd)
|
|
33
|
-
.join('\n')
|
|
34
|
-
.replace(/\n?$/, '\n'),
|
|
35
|
-
};
|
|
36
|
-
};
|
|
37
|
-
exports.resolveImportCode = resolveImportCode;
|
package/lib/plugins/index.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
export * from '@mdit-vue/plugin-component';
|
|
2
|
-
export * from '@mdit-vue/plugin-frontmatter';
|
|
3
|
-
export * from '@mdit-vue/plugin-headers';
|
|
4
|
-
export * from '@mdit-vue/plugin-sfc';
|
|
5
|
-
export * from '@mdit-vue/plugin-title';
|
|
6
|
-
export * from '@mdit-vue/plugin-toc';
|
|
7
|
-
export * from './anchorPlugin';
|
|
8
|
-
export * from './assetsPlugin';
|
|
9
|
-
export * from './codePlugin';
|
|
10
|
-
export * from './emojiPlugin';
|
|
11
|
-
export * from './importCodePlugin';
|
|
12
|
-
export * from './linksPlugin';
|
package/lib/plugins/index.js
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("@mdit-vue/plugin-component"), exports);
|
|
18
|
-
__exportStar(require("@mdit-vue/plugin-frontmatter"), exports);
|
|
19
|
-
__exportStar(require("@mdit-vue/plugin-headers"), exports);
|
|
20
|
-
__exportStar(require("@mdit-vue/plugin-sfc"), exports);
|
|
21
|
-
__exportStar(require("@mdit-vue/plugin-title"), exports);
|
|
22
|
-
__exportStar(require("@mdit-vue/plugin-toc"), exports);
|
|
23
|
-
__exportStar(require("./anchorPlugin"), exports);
|
|
24
|
-
__exportStar(require("./assetsPlugin"), exports);
|
|
25
|
-
__exportStar(require("./codePlugin"), exports);
|
|
26
|
-
__exportStar(require("./emojiPlugin"), exports);
|
|
27
|
-
__exportStar(require("./importCodePlugin"), exports);
|
|
28
|
-
__exportStar(require("./linksPlugin"), exports);
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./linksPlugin"), exports);
|
|
18
|
-
__exportStar(require("./resolvePaths"), exports);
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import type { PluginWithOptions } from 'markdown-it';
|
|
2
|
-
export interface LinksPluginOptions {
|
|
3
|
-
/**
|
|
4
|
-
* Tag for internal links
|
|
5
|
-
*
|
|
6
|
-
* @default 'RouterLink'
|
|
7
|
-
*/
|
|
8
|
-
internalTag?: 'a' | 'RouterLink';
|
|
9
|
-
/**
|
|
10
|
-
* Additional attributes for external links
|
|
11
|
-
*
|
|
12
|
-
* @default
|
|
13
|
-
* ```js
|
|
14
|
-
* ({
|
|
15
|
-
* target: '_blank',
|
|
16
|
-
* rel: 'noopener noreferrer',
|
|
17
|
-
* })
|
|
18
|
-
* ```
|
|
19
|
-
*/
|
|
20
|
-
externalAttrs?: Record<string, string>;
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Process links in markdown file
|
|
24
|
-
*
|
|
25
|
-
* - internal links: convert them into `<RouterLink>`
|
|
26
|
-
* - external links: add extra attrs and external icon
|
|
27
|
-
*/
|
|
28
|
-
export declare const linksPlugin: PluginWithOptions<LinksPluginOptions>;
|
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.linksPlugin = void 0;
|
|
4
|
-
const shared_1 = require("@vuepress/shared");
|
|
5
|
-
const resolvePaths_1 = require("./resolvePaths");
|
|
6
|
-
/**
|
|
7
|
-
* Process links in markdown file
|
|
8
|
-
*
|
|
9
|
-
* - internal links: convert them into `<RouterLink>`
|
|
10
|
-
* - external links: add extra attrs and external icon
|
|
11
|
-
*/
|
|
12
|
-
const linksPlugin = (md, options = {}) => {
|
|
13
|
-
// tag of internal links
|
|
14
|
-
const internalTag = options.internalTag || 'RouterLink';
|
|
15
|
-
// attrs that going to be added to external links
|
|
16
|
-
const externalAttrs = {
|
|
17
|
-
target: '_blank',
|
|
18
|
-
rel: 'noopener noreferrer',
|
|
19
|
-
...options.externalAttrs,
|
|
20
|
-
};
|
|
21
|
-
let hasOpenInternalLink = false;
|
|
22
|
-
const handleLinkOpen = (tokens, idx, env) => {
|
|
23
|
-
// get current token
|
|
24
|
-
const token = tokens[idx];
|
|
25
|
-
// get `href` attr index
|
|
26
|
-
const hrefIndex = token.attrIndex('href');
|
|
27
|
-
// if `href` attr does not exist, skip
|
|
28
|
-
/* istanbul ignore if */
|
|
29
|
-
if (hrefIndex < 0) {
|
|
30
|
-
return;
|
|
31
|
-
}
|
|
32
|
-
// if `href` attr exists, `token.attrs` is not `null`
|
|
33
|
-
const hrefAttr = token.attrs[hrefIndex];
|
|
34
|
-
const hrefLink = hrefAttr[1];
|
|
35
|
-
// get `base` and `filePathRelative` from `env`
|
|
36
|
-
const { base = '/', filePathRelative = null } = env;
|
|
37
|
-
// check if a link is an external link
|
|
38
|
-
if ((0, shared_1.isLinkExternal)(hrefLink, base)) {
|
|
39
|
-
// set `externalAttrs` to current token
|
|
40
|
-
Object.entries(externalAttrs).forEach(([key, val]) => token.attrSet(key, val));
|
|
41
|
-
return;
|
|
42
|
-
}
|
|
43
|
-
// check if a link is an internal link
|
|
44
|
-
const internalLinkMatch = hrefLink.match(/^((?:.*)(?:\/|\.md|\.html))(#.*)?$/);
|
|
45
|
-
if (!internalLinkMatch) {
|
|
46
|
-
return;
|
|
47
|
-
}
|
|
48
|
-
// convert
|
|
49
|
-
// <a href="hrefLink">
|
|
50
|
-
// to
|
|
51
|
-
// <RouterLink to="toProp">
|
|
52
|
-
// notice that the path and hash are encoded by markdown-it
|
|
53
|
-
const rawPath = internalLinkMatch[1];
|
|
54
|
-
const rawHash = internalLinkMatch[2] || '';
|
|
55
|
-
// resolve relative and absolute path
|
|
56
|
-
const { relativePath, absolutePath } = (0, resolvePaths_1.resolvePaths)(rawPath, base, filePathRelative);
|
|
57
|
-
// normalize markdown file path to route path
|
|
58
|
-
//
|
|
59
|
-
// we are removing the `base` from absolute path because it should not be
|
|
60
|
-
// passed to `<RouterLink>`
|
|
61
|
-
//
|
|
62
|
-
// '/foo/index.md' => '/foo/'
|
|
63
|
-
// '/foo/bar.md' => '/foo/bar.html'
|
|
64
|
-
const normalizedPath = absolutePath
|
|
65
|
-
.replace(new RegExp(`^${base}`), '/')
|
|
66
|
-
.replace(/(^|\/)(README|index).md$/i, '$1')
|
|
67
|
-
.replace(/\.md$/, '.html');
|
|
68
|
-
if (internalTag === 'RouterLink') {
|
|
69
|
-
// convert starting tag of internal link to `<RouterLink>`
|
|
70
|
-
token.tag = internalTag;
|
|
71
|
-
// replace the original `href` attr with `to` attr
|
|
72
|
-
hrefAttr[0] = 'to';
|
|
73
|
-
// set `hasOpenInternalLink` to modify the ending tag
|
|
74
|
-
hasOpenInternalLink = true;
|
|
75
|
-
}
|
|
76
|
-
hrefAttr[1] = `${normalizedPath}${rawHash}`;
|
|
77
|
-
// extract internal links for file / page existence check
|
|
78
|
-
const links = env.links || (env.links = []);
|
|
79
|
-
links.push({
|
|
80
|
-
raw: hrefLink,
|
|
81
|
-
relative: relativePath,
|
|
82
|
-
absolute: absolutePath,
|
|
83
|
-
});
|
|
84
|
-
};
|
|
85
|
-
md.renderer.rules.link_open = (tokens, idx, options, env, self) => {
|
|
86
|
-
handleLinkOpen(tokens, idx, env);
|
|
87
|
-
return self.renderToken(tokens, idx, options);
|
|
88
|
-
};
|
|
89
|
-
md.renderer.rules.link_close = (tokens, idx, options, env, self) => {
|
|
90
|
-
// convert ending tag of internal link
|
|
91
|
-
if (hasOpenInternalLink) {
|
|
92
|
-
hasOpenInternalLink = false;
|
|
93
|
-
tokens[idx].tag = internalTag;
|
|
94
|
-
}
|
|
95
|
-
return self.renderToken(tokens, idx, options);
|
|
96
|
-
};
|
|
97
|
-
};
|
|
98
|
-
exports.linksPlugin = linksPlugin;
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.resolvePaths = void 0;
|
|
4
|
-
const shared_1 = require("@vuepress/shared");
|
|
5
|
-
const utils_1 = require("@vuepress/utils");
|
|
6
|
-
/**
|
|
7
|
-
* Resolve relative and absolute paths according to the `base` and `filePathRelative`
|
|
8
|
-
*/
|
|
9
|
-
const resolvePaths = (rawPath, base, filePathRelative) => {
|
|
10
|
-
let absolutePath;
|
|
11
|
-
let relativePath;
|
|
12
|
-
if (rawPath.startsWith('/')) {
|
|
13
|
-
// if raw path is absolute
|
|
14
|
-
if (rawPath.endsWith('.md')) {
|
|
15
|
-
// if raw path is a link to markdown file
|
|
16
|
-
// prepend `base` to the link
|
|
17
|
-
absolutePath = utils_1.path.join(base, rawPath);
|
|
18
|
-
relativePath = (0, shared_1.removeLeadingSlash)(rawPath);
|
|
19
|
-
}
|
|
20
|
-
else {
|
|
21
|
-
// if raw path is a link to other kind of file
|
|
22
|
-
// keep the link as is
|
|
23
|
-
absolutePath = rawPath;
|
|
24
|
-
relativePath = utils_1.path.relative(base, absolutePath);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
else {
|
|
28
|
-
// if raw path is relative
|
|
29
|
-
if (filePathRelative) {
|
|
30
|
-
// if `filePathRelative` is available
|
|
31
|
-
// resolve relative path according to `filePathRelative`
|
|
32
|
-
relativePath = utils_1.path.join(
|
|
33
|
-
// file path may contain non-ASCII characters
|
|
34
|
-
utils_1.path.dirname(encodeURI(filePathRelative)), rawPath);
|
|
35
|
-
// resolve absolute path according to `base`
|
|
36
|
-
absolutePath = utils_1.path.join(base, relativePath);
|
|
37
|
-
}
|
|
38
|
-
else {
|
|
39
|
-
// if `filePathRelative` is not available
|
|
40
|
-
// remove leading './'
|
|
41
|
-
relativePath = rawPath.replace(/^(?:\.\/)?(.*)$/, '$1');
|
|
42
|
-
// just take relative link as absolute link
|
|
43
|
-
absolutePath = relativePath;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
return {
|
|
47
|
-
absolutePath,
|
|
48
|
-
relativePath,
|
|
49
|
-
};
|
|
50
|
-
};
|
|
51
|
-
exports.resolvePaths = resolvePaths;
|
package/lib/types.d.ts
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import type { MarkdownItEnv } from '@mdit-vue/types';
|
|
2
|
-
import type { PageFrontmatter, PageHeader } from '@vuepress/shared';
|
|
3
|
-
import type * as MarkdownIt from 'markdown-it';
|
|
4
|
-
import type { AnchorPluginOptions, AssetsPluginOptions, CodePluginOptions, EmojiPluginOptions, FrontmatterPluginOptions, HeadersPluginOptions, ImportCodePluginOptions, LinksPluginOptions, SfcPluginOptions, TocPluginOptions } from './plugins';
|
|
5
|
-
export declare type Markdown = MarkdownIt;
|
|
6
|
-
export interface MarkdownOptions extends MarkdownIt.Options {
|
|
7
|
-
anchor?: false | AnchorPluginOptions;
|
|
8
|
-
assets?: false | AssetsPluginOptions;
|
|
9
|
-
code?: false | CodePluginOptions;
|
|
10
|
-
component?: false;
|
|
11
|
-
emoji?: false | EmojiPluginOptions;
|
|
12
|
-
frontmatter?: false | FrontmatterPluginOptions;
|
|
13
|
-
headers?: false | HeadersPluginOptions;
|
|
14
|
-
title?: false;
|
|
15
|
-
importCode?: false | ImportCodePluginOptions;
|
|
16
|
-
links?: false | LinksPluginOptions;
|
|
17
|
-
sfc?: false | SfcPluginOptions;
|
|
18
|
-
slugify?: MarkdownSlugifyFunction;
|
|
19
|
-
toc?: false | TocPluginOptions;
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Headers in markdown file
|
|
23
|
-
*/
|
|
24
|
-
export declare type MarkdownHeader = PageHeader;
|
|
25
|
-
/**
|
|
26
|
-
* Internal links in markdown file
|
|
27
|
-
*
|
|
28
|
-
* Used for file existence check
|
|
29
|
-
*/
|
|
30
|
-
export interface MarkdownLink {
|
|
31
|
-
raw: string;
|
|
32
|
-
relative: string;
|
|
33
|
-
absolute: string;
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* The `env` object to be passed to markdown-it render function
|
|
37
|
-
*
|
|
38
|
-
* Input some meta data for markdown file parsing and rendering
|
|
39
|
-
*
|
|
40
|
-
* Output some resources from the markdown file
|
|
41
|
-
*/
|
|
42
|
-
export interface MarkdownEnv extends MarkdownItEnv {
|
|
43
|
-
/**
|
|
44
|
-
* Base / publicPath of current site
|
|
45
|
-
*/
|
|
46
|
-
base?: string;
|
|
47
|
-
/**
|
|
48
|
-
* Absolute file path of the markdown file
|
|
49
|
-
*/
|
|
50
|
-
filePath?: string | null;
|
|
51
|
-
/**
|
|
52
|
-
* Relative file path of the markdown file
|
|
53
|
-
*/
|
|
54
|
-
filePathRelative?: string | null;
|
|
55
|
-
/**
|
|
56
|
-
* Frontmatter of the markdown file
|
|
57
|
-
*/
|
|
58
|
-
frontmatter?: PageFrontmatter;
|
|
59
|
-
/**
|
|
60
|
-
* Imported file that extracted by importCodePlugin
|
|
61
|
-
*/
|
|
62
|
-
importedFiles?: string[];
|
|
63
|
-
/**
|
|
64
|
-
* Links that extracted by linksPlugin
|
|
65
|
-
*/
|
|
66
|
-
links?: MarkdownLink[];
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* Type of `slugify` function
|
|
70
|
-
*/
|
|
71
|
-
export declare type MarkdownSlugifyFunction = (str: string) => string;
|
package/lib/types.js
DELETED