@vuepress/markdown 2.0.0-beta.46 → 2.0.0-beta.49
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/index.d.ts +0 -1
- package/lib/index.js +0 -1
- package/lib/markdown.d.ts +1 -1
- package/lib/markdown.js +28 -17
- package/lib/plugins/emojiPlugin.d.ts +3 -25
- package/lib/plugins/emojiPlugin.js +2 -2
- package/lib/plugins/index.d.ts +6 -5
- package/lib/plugins/index.js +6 -5
- package/lib/types.d.ts +13 -18
- package/package.json +12 -3
- package/lib/plugins/customComponentPlugin/customComponentPlugin.d.ts +0 -6
- package/lib/plugins/customComponentPlugin/customComponentPlugin.js +0 -18
- package/lib/plugins/customComponentPlugin/htmlBlockRule.d.ts +0 -2
- package/lib/plugins/customComponentPlugin/htmlBlockRule.js +0 -90
- package/lib/plugins/customComponentPlugin/htmlInlineRule.d.ts +0 -2
- package/lib/plugins/customComponentPlugin/htmlInlineRule.js +0 -40
- package/lib/plugins/customComponentPlugin/htmlRe.d.ts +0 -2
- package/lib/plugins/customComponentPlugin/htmlRe.js +0 -33
- package/lib/plugins/customComponentPlugin/index.d.ts +0 -6
- package/lib/plugins/customComponentPlugin/index.js +0 -22
- package/lib/plugins/customComponentPlugin/inlineTags.d.ts +0 -18
- package/lib/plugins/customComponentPlugin/inlineTags.js +0 -78
- package/lib/plugins/customComponentPlugin/vueReservedTags.d.ts +0 -6
- package/lib/plugins/customComponentPlugin/vueReservedTags.js +0 -17
- package/lib/plugins/extractHeadersPlugin.d.ts +0 -27
- package/lib/plugins/extractHeadersPlugin.js +0 -32
- package/lib/plugins/extractTitlePlugin.d.ts +0 -5
- package/lib/plugins/extractTitlePlugin.js +0 -33
- package/lib/plugins/hoistTagsPlugin.d.ts +0 -12
- package/lib/plugins/hoistTagsPlugin.js +0 -27
- package/lib/plugins/tocPlugin/createRenderHeaders.d.ts +0 -5
- package/lib/plugins/tocPlugin/createRenderHeaders.js +0 -28
- package/lib/plugins/tocPlugin/createTocBlockRule.d.ts +0 -11
- package/lib/plugins/tocPlugin/createTocBlockRule.js +0 -50
- package/lib/plugins/tocPlugin/index.d.ts +0 -3
- package/lib/plugins/tocPlugin/index.js +0 -19
- package/lib/plugins/tocPlugin/tocPlugin.d.ts +0 -65
- package/lib/plugins/tocPlugin/tocPlugin.js +0 -56
- package/lib/utils/index.d.ts +0 -3
- package/lib/utils/index.js +0 -19
- package/lib/utils/resolveHeadersFromTokens.d.ts +0 -12
- package/lib/utils/resolveHeadersFromTokens.js +0 -63
- package/lib/utils/resolveTitleFromToken.d.ts +0 -10
- package/lib/utils/resolveTitleFromToken.js +0 -37
- package/lib/utils/slugify.d.ts +0 -1
- package/lib/utils/slugify.js +0 -24
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
package/lib/markdown.d.ts
CHANGED
|
@@ -2,4 +2,4 @@ import type { Markdown, MarkdownOptions } from './types';
|
|
|
2
2
|
/**
|
|
3
3
|
* Create vuepress customized markdown-it instance
|
|
4
4
|
*/
|
|
5
|
-
export declare const createMarkdown: ({ anchor, assets, code,
|
|
5
|
+
export declare const createMarkdown: ({ anchor, assets, code, component, emoji, frontmatter, headers, title, importCode, links, sfc, slugify, toc, ...markdownItOptions }?: MarkdownOptions) => Markdown;
|
package/lib/markdown.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createMarkdown = void 0;
|
|
4
|
+
const shared_1 = require("@mdit-vue/shared");
|
|
4
5
|
const MarkdownIt = require("markdown-it");
|
|
5
6
|
const plugins_1 = require("./plugins");
|
|
6
|
-
const utils_1 = require("./utils");
|
|
7
7
|
/**
|
|
8
8
|
* Create vuepress customized markdown-it instance
|
|
9
9
|
*/
|
|
10
|
-
const createMarkdown = ({ anchor, assets, code,
|
|
10
|
+
const createMarkdown = ({ anchor, assets, code, component, emoji, frontmatter, headers, title, importCode, links, sfc, slugify = shared_1.slugify, toc, ...markdownItOptions } = {}) => {
|
|
11
11
|
// create raw markdown-it instance
|
|
12
12
|
const md = MarkdownIt({
|
|
13
13
|
...markdownItOptions,
|
|
@@ -25,7 +25,7 @@ const createMarkdown = ({ anchor, assets, code, customComponent, emoji, extractH
|
|
|
25
25
|
if (anchor !== false) {
|
|
26
26
|
md.use(plugins_1.anchorPlugin, {
|
|
27
27
|
level: [1, 2, 3, 4, 5, 6],
|
|
28
|
-
slugify
|
|
28
|
+
slugify,
|
|
29
29
|
permalink: plugins_1.anchorPlugin.permalink.ariaHidden({
|
|
30
30
|
class: 'header-anchor',
|
|
31
31
|
symbol: '#',
|
|
@@ -39,37 +39,48 @@ const createMarkdown = ({ anchor, assets, code, customComponent, emoji, extractH
|
|
|
39
39
|
if (toc !== false) {
|
|
40
40
|
md.use(plugins_1.tocPlugin, {
|
|
41
41
|
level: [2, 3],
|
|
42
|
-
slugify
|
|
43
|
-
linkTag: '
|
|
42
|
+
slugify,
|
|
43
|
+
linkTag: 'router-link',
|
|
44
44
|
...toc,
|
|
45
45
|
});
|
|
46
46
|
}
|
|
47
47
|
// extract headers into env
|
|
48
|
-
if (
|
|
49
|
-
md.use(plugins_1.
|
|
48
|
+
if (headers !== false) {
|
|
49
|
+
md.use(plugins_1.headersPlugin, {
|
|
50
50
|
level: [2, 3],
|
|
51
|
-
slugify
|
|
52
|
-
...
|
|
51
|
+
slugify,
|
|
52
|
+
...headers,
|
|
53
53
|
});
|
|
54
54
|
}
|
|
55
55
|
// extract title into env
|
|
56
|
-
if (
|
|
57
|
-
md.use(plugins_1.
|
|
56
|
+
if (title !== false) {
|
|
57
|
+
md.use(plugins_1.titlePlugin);
|
|
58
58
|
}
|
|
59
59
|
// =====================================================
|
|
60
60
|
// following plugins modify or replace the rule in place
|
|
61
61
|
// and have no conflicts, so the order is not important
|
|
62
|
-
// treat unknown html tags as
|
|
63
|
-
if (
|
|
64
|
-
md.use(plugins_1.
|
|
62
|
+
// treat unknown html tags as components
|
|
63
|
+
if (component !== false) {
|
|
64
|
+
md.use(plugins_1.componentPlugin);
|
|
65
|
+
}
|
|
66
|
+
// extract frontmatter and excerpt into env
|
|
67
|
+
if (frontmatter !== false) {
|
|
68
|
+
md.use(plugins_1.frontmatterPlugin, {
|
|
69
|
+
...frontmatter,
|
|
70
|
+
grayMatterOptions: {
|
|
71
|
+
excerpt: true,
|
|
72
|
+
excerpt_separator: '<!-- more -->',
|
|
73
|
+
...frontmatter?.grayMatterOptions,
|
|
74
|
+
},
|
|
75
|
+
});
|
|
65
76
|
}
|
|
66
77
|
// replace relative link of assets with absolute link
|
|
67
78
|
if (assets !== false) {
|
|
68
79
|
md.use(plugins_1.assetsPlugin, assets);
|
|
69
80
|
}
|
|
70
|
-
//
|
|
71
|
-
if (
|
|
72
|
-
md.use(plugins_1.
|
|
81
|
+
// extract vue SFC blocks into env
|
|
82
|
+
if (sfc !== false) {
|
|
83
|
+
md.use(plugins_1.sfcPlugin, sfc);
|
|
73
84
|
}
|
|
74
85
|
// process external and internal links
|
|
75
86
|
if (links !== false) {
|
|
@@ -1,25 +1,3 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
*
|
|
5
|
-
* @see https://github.com/markdown-it/markdown-it-emoji
|
|
6
|
-
*/
|
|
7
|
-
export interface EmojiPluginOptions {
|
|
8
|
-
/**
|
|
9
|
-
* rewrite available emoji definitions
|
|
10
|
-
*
|
|
11
|
-
* @example `{ name1: char1, name2: char2, ... }`
|
|
12
|
-
*/
|
|
13
|
-
defs?: Record<string, string>;
|
|
14
|
-
/**
|
|
15
|
-
* disable all emojis except whitelisted
|
|
16
|
-
*/
|
|
17
|
-
enabled?: string[];
|
|
18
|
-
/**
|
|
19
|
-
* rewrite default shortcuts
|
|
20
|
-
*
|
|
21
|
-
* @example `{ "smile": [ ":)", ":-)" ], "laughing": ":D" }`
|
|
22
|
-
*/
|
|
23
|
-
shortcuts?: Record<string, string | string[]>;
|
|
24
|
-
}
|
|
25
|
-
export declare const emojiPlugin: PluginWithOptions<EmojiPluginOptions>;
|
|
1
|
+
import * as emojiPlugin from 'markdown-it-emoji';
|
|
2
|
+
export declare type EmojiPluginOptions = emojiPlugin.Options;
|
|
3
|
+
export { emojiPlugin };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.emojiPlugin = void 0;
|
|
4
|
-
const
|
|
5
|
-
exports.emojiPlugin =
|
|
4
|
+
const emojiPlugin = require("markdown-it-emoji");
|
|
5
|
+
exports.emojiPlugin = emojiPlugin;
|
package/lib/plugins/index.d.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
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';
|
|
1
7
|
export * from './anchorPlugin';
|
|
2
8
|
export * from './assetsPlugin';
|
|
3
9
|
export * from './codePlugin';
|
|
4
|
-
export * from './customComponentPlugin';
|
|
5
10
|
export * from './emojiPlugin';
|
|
6
|
-
export * from './extractHeadersPlugin';
|
|
7
|
-
export * from './extractTitlePlugin';
|
|
8
|
-
export * from './hoistTagsPlugin';
|
|
9
11
|
export * from './importCodePlugin';
|
|
10
12
|
export * from './linksPlugin';
|
|
11
|
-
export * from './tocPlugin';
|
package/lib/plugins/index.js
CHANGED
|
@@ -14,14 +14,15 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
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);
|
|
17
23
|
__exportStar(require("./anchorPlugin"), exports);
|
|
18
24
|
__exportStar(require("./assetsPlugin"), exports);
|
|
19
25
|
__exportStar(require("./codePlugin"), exports);
|
|
20
|
-
__exportStar(require("./customComponentPlugin"), exports);
|
|
21
26
|
__exportStar(require("./emojiPlugin"), exports);
|
|
22
|
-
__exportStar(require("./extractHeadersPlugin"), exports);
|
|
23
|
-
__exportStar(require("./extractTitlePlugin"), exports);
|
|
24
|
-
__exportStar(require("./hoistTagsPlugin"), exports);
|
|
25
27
|
__exportStar(require("./importCodePlugin"), exports);
|
|
26
28
|
__exportStar(require("./linksPlugin"), exports);
|
|
27
|
-
__exportStar(require("./tocPlugin"), exports);
|
package/lib/types.d.ts
CHANGED
|
@@ -1,18 +1,21 @@
|
|
|
1
|
+
import type { MarkdownItEnv } from '@mdit-vue/types';
|
|
1
2
|
import type { PageFrontmatter, PageHeader } from '@vuepress/shared';
|
|
2
3
|
import type * as MarkdownIt from 'markdown-it';
|
|
3
|
-
import type { AnchorPluginOptions, AssetsPluginOptions, CodePluginOptions, EmojiPluginOptions,
|
|
4
|
+
import type { AnchorPluginOptions, AssetsPluginOptions, CodePluginOptions, EmojiPluginOptions, FrontmatterPluginOptions, HeadersPluginOptions, ImportCodePluginOptions, LinksPluginOptions, SfcPluginOptions, TocPluginOptions } from './plugins';
|
|
4
5
|
export declare type Markdown = MarkdownIt;
|
|
5
6
|
export interface MarkdownOptions extends MarkdownIt.Options {
|
|
6
7
|
anchor?: false | AnchorPluginOptions;
|
|
7
8
|
assets?: false | AssetsPluginOptions;
|
|
8
9
|
code?: false | CodePluginOptions;
|
|
9
|
-
|
|
10
|
+
component?: false;
|
|
10
11
|
emoji?: false | EmojiPluginOptions;
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
frontmatter?: false | FrontmatterPluginOptions;
|
|
13
|
+
headers?: false | HeadersPluginOptions;
|
|
14
|
+
title?: false;
|
|
14
15
|
importCode?: false | ImportCodePluginOptions;
|
|
15
16
|
links?: false | LinksPluginOptions;
|
|
17
|
+
sfc?: false | SfcPluginOptions;
|
|
18
|
+
slugify?: MarkdownSlugifyFunction;
|
|
16
19
|
toc?: false | TocPluginOptions;
|
|
17
20
|
}
|
|
18
21
|
/**
|
|
@@ -36,7 +39,7 @@ export interface MarkdownLink {
|
|
|
36
39
|
*
|
|
37
40
|
* Output some resources from the markdown file
|
|
38
41
|
*/
|
|
39
|
-
export interface MarkdownEnv {
|
|
42
|
+
export interface MarkdownEnv extends MarkdownItEnv {
|
|
40
43
|
/**
|
|
41
44
|
* Base / publicPath of current site
|
|
42
45
|
*/
|
|
@@ -53,14 +56,6 @@ export interface MarkdownEnv {
|
|
|
53
56
|
* Frontmatter of the markdown file
|
|
54
57
|
*/
|
|
55
58
|
frontmatter?: PageFrontmatter;
|
|
56
|
-
/**
|
|
57
|
-
* Headers that extracted by extractHeadersPlugin
|
|
58
|
-
*/
|
|
59
|
-
headers?: MarkdownHeader[];
|
|
60
|
-
/**
|
|
61
|
-
* Hoisted tags that extracted by hoistTagsPlugin
|
|
62
|
-
*/
|
|
63
|
-
hoistedTags?: string[];
|
|
64
59
|
/**
|
|
65
60
|
* Imported file that extracted by importCodePlugin
|
|
66
61
|
*/
|
|
@@ -69,8 +64,8 @@ export interface MarkdownEnv {
|
|
|
69
64
|
* Links that extracted by linksPlugin
|
|
70
65
|
*/
|
|
71
66
|
links?: MarkdownLink[];
|
|
72
|
-
/**
|
|
73
|
-
* Title that extracted by extractTitlePlugin
|
|
74
|
-
*/
|
|
75
|
-
title?: string;
|
|
76
67
|
}
|
|
68
|
+
/**
|
|
69
|
+
* Type of `slugify` function
|
|
70
|
+
*/
|
|
71
|
+
export declare type MarkdownSlugifyFunction = (str: string) => string;
|
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.49",
|
|
4
4
|
"description": "Markdown package of VuePress",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"vuepress",
|
|
@@ -22,9 +22,18 @@
|
|
|
22
22
|
"lib"
|
|
23
23
|
],
|
|
24
24
|
"dependencies": {
|
|
25
|
+
"@mdit-vue/plugin-component": "^0.6.0",
|
|
26
|
+
"@mdit-vue/plugin-frontmatter": "^0.6.0",
|
|
27
|
+
"@mdit-vue/plugin-headers": "^0.6.0",
|
|
28
|
+
"@mdit-vue/plugin-sfc": "^0.6.0",
|
|
29
|
+
"@mdit-vue/plugin-title": "^0.6.0",
|
|
30
|
+
"@mdit-vue/plugin-toc": "^0.6.0",
|
|
31
|
+
"@mdit-vue/shared": "^0.6.0",
|
|
32
|
+
"@mdit-vue/types": "^0.6.0",
|
|
25
33
|
"@types/markdown-it": "^12.2.3",
|
|
26
|
-
"@
|
|
27
|
-
"@vuepress/
|
|
34
|
+
"@types/markdown-it-emoji": "^2.0.2",
|
|
35
|
+
"@vuepress/shared": "2.0.0-beta.49",
|
|
36
|
+
"@vuepress/utils": "2.0.0-beta.49",
|
|
28
37
|
"markdown-it": "^13.0.1",
|
|
29
38
|
"markdown-it-anchor": "^8.6.4",
|
|
30
39
|
"markdown-it-emoji": "^2.0.2",
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.customComponentPlugin = void 0;
|
|
4
|
-
const htmlBlockRule_1 = require("./htmlBlockRule");
|
|
5
|
-
const htmlInlineRule_1 = require("./htmlInlineRule");
|
|
6
|
-
/**
|
|
7
|
-
* Replacing the default htmlBlock rule to allow using custom components
|
|
8
|
-
* in markdown
|
|
9
|
-
*/
|
|
10
|
-
const customComponentPlugin = (md) => {
|
|
11
|
-
// override default html block ruler
|
|
12
|
-
md.block.ruler.at('html_block', htmlBlockRule_1.htmlBlockRule, {
|
|
13
|
-
alt: ['paragraph', 'reference', 'blockquote'],
|
|
14
|
-
});
|
|
15
|
-
// override default html inline ruler
|
|
16
|
-
md.inline.ruler.at('html_inline', htmlInlineRule_1.htmlInlineRule);
|
|
17
|
-
};
|
|
18
|
-
exports.customComponentPlugin = customComponentPlugin;
|
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.htmlBlockRule = void 0;
|
|
4
|
-
const blockNames = require("markdown-it/lib/common/html_blocks");
|
|
5
|
-
const htmlRe_1 = require("./htmlRe");
|
|
6
|
-
const inlineTags_1 = require("./inlineTags");
|
|
7
|
-
const vueReservedTags_1 = require("./vueReservedTags");
|
|
8
|
-
// Forked and modified from 'markdown-it/lib/rules_block/html_block.js'
|
|
9
|
-
// An array of opening and corresponding closing sequences for html tags,
|
|
10
|
-
// last argument defines whether it can terminate a paragraph or not
|
|
11
|
-
const HTML_SEQUENCES = [
|
|
12
|
-
[/^<(script|pre|style)(?=(\s|>|$))/i, /<\/(script|pre|style)>/i, true],
|
|
13
|
-
[/^<!--/, /-->/, true],
|
|
14
|
-
[/^<\?/, /\?>/, true],
|
|
15
|
-
[/^<![A-Z]/, />/, true],
|
|
16
|
-
[/^<!\[CDATA\[/, /\]\]>/, true],
|
|
17
|
-
// MODIFIED HERE: Treat vue reserved tags as block tags
|
|
18
|
-
[
|
|
19
|
-
new RegExp('^</?(' + vueReservedTags_1.vueReservedTags.join('|') + ')(?=(\\s|/?>|$))', 'i'),
|
|
20
|
-
/^$/,
|
|
21
|
-
true,
|
|
22
|
-
],
|
|
23
|
-
// MODIFIED HERE: Treat unknown tags as block tags (custom components), excluding known inline tags
|
|
24
|
-
[
|
|
25
|
-
new RegExp('^</?(?!(' + inlineTags_1.inlineTags.join('|') + ')(?![\\w-]))\\w[\\w-]*[\\s/>]'),
|
|
26
|
-
/^$/,
|
|
27
|
-
true,
|
|
28
|
-
],
|
|
29
|
-
[
|
|
30
|
-
new RegExp('^</?(' + blockNames.join('|') + ')(?=(\\s|/?>|$))', 'i'),
|
|
31
|
-
/^$/,
|
|
32
|
-
true,
|
|
33
|
-
],
|
|
34
|
-
[new RegExp(htmlRe_1.HTML_OPEN_CLOSE_TAG_RE.source + '\\s*$'), /^$/, false],
|
|
35
|
-
];
|
|
36
|
-
const htmlBlockRule = (state, startLine, endLine, silent) => {
|
|
37
|
-
let i;
|
|
38
|
-
let nextLine;
|
|
39
|
-
let lineText;
|
|
40
|
-
let pos = state.bMarks[startLine] + state.tShift[startLine];
|
|
41
|
-
let max = state.eMarks[startLine];
|
|
42
|
-
// if it's indented more than 3 spaces, it should be a code block
|
|
43
|
-
if (state.sCount[startLine] - state.blkIndent >= 4) {
|
|
44
|
-
return false;
|
|
45
|
-
}
|
|
46
|
-
if (!state.md.options.html) {
|
|
47
|
-
return false;
|
|
48
|
-
}
|
|
49
|
-
if (state.src.charCodeAt(pos) !== 0x3c /* < */) {
|
|
50
|
-
return false;
|
|
51
|
-
}
|
|
52
|
-
lineText = state.src.slice(pos, max);
|
|
53
|
-
for (i = 0; i < HTML_SEQUENCES.length; i++) {
|
|
54
|
-
if (HTML_SEQUENCES[i][0].test(lineText)) {
|
|
55
|
-
break;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
if (i === HTML_SEQUENCES.length) {
|
|
59
|
-
return false;
|
|
60
|
-
}
|
|
61
|
-
if (silent) {
|
|
62
|
-
// true if this sequence can be a terminator, false otherwise
|
|
63
|
-
return HTML_SEQUENCES[i][2];
|
|
64
|
-
}
|
|
65
|
-
nextLine = startLine + 1;
|
|
66
|
-
// If we are here - we detected HTML block.
|
|
67
|
-
// Let's roll down till block end.
|
|
68
|
-
if (!HTML_SEQUENCES[i][1].test(lineText)) {
|
|
69
|
-
for (; nextLine < endLine; nextLine++) {
|
|
70
|
-
if (state.sCount[nextLine] < state.blkIndent) {
|
|
71
|
-
break;
|
|
72
|
-
}
|
|
73
|
-
pos = state.bMarks[nextLine] + state.tShift[nextLine];
|
|
74
|
-
max = state.eMarks[nextLine];
|
|
75
|
-
lineText = state.src.slice(pos, max);
|
|
76
|
-
if (HTML_SEQUENCES[i][1].test(lineText)) {
|
|
77
|
-
if (lineText.length !== 0) {
|
|
78
|
-
nextLine++;
|
|
79
|
-
}
|
|
80
|
-
break;
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
state.line = nextLine;
|
|
85
|
-
const token = state.push('html_block', '', 0);
|
|
86
|
-
token.map = [startLine, nextLine];
|
|
87
|
-
token.content = state.getLines(startLine, nextLine, state.blkIndent, true);
|
|
88
|
-
return true;
|
|
89
|
-
};
|
|
90
|
-
exports.htmlBlockRule = htmlBlockRule;
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.htmlInlineRule = void 0;
|
|
4
|
-
const htmlRe_1 = require("./htmlRe");
|
|
5
|
-
// Forked and modified from 'markdown-it/lib/rules_inline/html_inline.js'
|
|
6
|
-
const isLetter = (ch) => {
|
|
7
|
-
const lc = ch | 0x20; // to lower case
|
|
8
|
-
return lc >= 0x61 /* a */ && lc <= 0x7a; /* z */
|
|
9
|
-
};
|
|
10
|
-
const htmlInlineRule = (state, silent) => {
|
|
11
|
-
const pos = state.pos;
|
|
12
|
-
if (!state.md.options.html) {
|
|
13
|
-
return false;
|
|
14
|
-
}
|
|
15
|
-
// Check start
|
|
16
|
-
const max = state.posMax;
|
|
17
|
-
if (state.src.charCodeAt(pos) !== 0x3c /* < */ || pos + 2 >= max) {
|
|
18
|
-
return false;
|
|
19
|
-
}
|
|
20
|
-
// Quick fail on second char
|
|
21
|
-
const ch = state.src.charCodeAt(pos + 1);
|
|
22
|
-
if (ch !== 0x21 /* ! */ &&
|
|
23
|
-
ch !== 0x3f /* ? */ &&
|
|
24
|
-
ch !== 0x2f /* / */ &&
|
|
25
|
-
!isLetter(ch)) {
|
|
26
|
-
return false;
|
|
27
|
-
}
|
|
28
|
-
// MODIFIED HERE: Tweak the original HTML_TAG_RE
|
|
29
|
-
const match = state.src.slice(pos).match(htmlRe_1.HTML_TAG_RE);
|
|
30
|
-
if (!match) {
|
|
31
|
-
return false;
|
|
32
|
-
}
|
|
33
|
-
if (!silent) {
|
|
34
|
-
const token = state.push('html_inline', '', 0);
|
|
35
|
-
token.content = state.src.slice(pos, pos + match[0].length);
|
|
36
|
-
}
|
|
37
|
-
state.pos += match[0].length;
|
|
38
|
-
return true;
|
|
39
|
-
};
|
|
40
|
-
exports.htmlInlineRule = htmlInlineRule;
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/* eslint-disable @typescript-eslint/naming-convention */
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.HTML_OPEN_CLOSE_TAG_RE = exports.HTML_TAG_RE = void 0;
|
|
5
|
-
// Forked and modified from 'markdown-it/lib/common/html_re.js'
|
|
6
|
-
// Regexps to match html elements
|
|
7
|
-
// MODIFIED HERE: Support `@` as the first char of attr name
|
|
8
|
-
const attr_name = '[a-zA-Z_:@][a-zA-Z0-9:._-]*';
|
|
9
|
-
const unquoted = '[^"\'=<>`\\x00-\\x20]+';
|
|
10
|
-
const single_quoted = "'[^']*'";
|
|
11
|
-
const double_quoted = '"[^"]*"';
|
|
12
|
-
const attr_value = '(?:' + unquoted + '|' + single_quoted + '|' + double_quoted + ')';
|
|
13
|
-
const attribute = '(?:\\s+' + attr_name + '(?:\\s*=\\s*' + attr_value + ')?)';
|
|
14
|
-
const open_tag = '<[A-Za-z][A-Za-z0-9\\-]*' + attribute + '*\\s*\\/?>';
|
|
15
|
-
const close_tag = '<\\/[A-Za-z][A-Za-z0-9\\-]*\\s*>';
|
|
16
|
-
const comment = '<!---->|<!--(?:-?[^>-])(?:-?[^-])*-->';
|
|
17
|
-
const processing = '<[?][\\s\\S]*?[?]>';
|
|
18
|
-
const declaration = '<![A-Z]+\\s+[^>]*>';
|
|
19
|
-
const cdata = '<!\\[CDATA\\[[\\s\\S]*?\\]\\]>';
|
|
20
|
-
exports.HTML_TAG_RE = new RegExp('^(?:' +
|
|
21
|
-
open_tag +
|
|
22
|
-
'|' +
|
|
23
|
-
close_tag +
|
|
24
|
-
'|' +
|
|
25
|
-
comment +
|
|
26
|
-
'|' +
|
|
27
|
-
processing +
|
|
28
|
-
'|' +
|
|
29
|
-
declaration +
|
|
30
|
-
'|' +
|
|
31
|
-
cdata +
|
|
32
|
-
')');
|
|
33
|
-
exports.HTML_OPEN_CLOSE_TAG_RE = new RegExp('^(?:' + open_tag + '|' + close_tag + ')');
|
|
@@ -1,22 +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("./customComponentPlugin"), exports);
|
|
18
|
-
__exportStar(require("./htmlBlockRule"), exports);
|
|
19
|
-
__exportStar(require("./htmlInlineRule"), exports);
|
|
20
|
-
__exportStar(require("./htmlRe"), exports);
|
|
21
|
-
__exportStar(require("./inlineTags"), exports);
|
|
22
|
-
__exportStar(require("./vueReservedTags"), exports);
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* According to markdown spec, all non-block html tags are treated as "inline"
|
|
3
|
-
* tags (wrapped with <p></p>), including those "unknown" tags
|
|
4
|
-
*
|
|
5
|
-
* Therefore, markdown-it processes "inline" tags and "unknown" tags in the same
|
|
6
|
-
* way, and does not care if a tag is "inline" or "unknown"
|
|
7
|
-
*
|
|
8
|
-
* As we want to take those "unknown" tags as custom components, we should
|
|
9
|
-
* treat them as "block" tags
|
|
10
|
-
*
|
|
11
|
-
* So we have to distinguish between "inline" and "unknown" tags ourselves
|
|
12
|
-
*
|
|
13
|
-
* The inline tags list comes from MDN
|
|
14
|
-
*
|
|
15
|
-
* @see https://spec.commonmark.org/0.29/#raw-html
|
|
16
|
-
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/Inline_elements
|
|
17
|
-
*/
|
|
18
|
-
export declare const inlineTags: string[];
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.inlineTags = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* According to markdown spec, all non-block html tags are treated as "inline"
|
|
6
|
-
* tags (wrapped with <p></p>), including those "unknown" tags
|
|
7
|
-
*
|
|
8
|
-
* Therefore, markdown-it processes "inline" tags and "unknown" tags in the same
|
|
9
|
-
* way, and does not care if a tag is "inline" or "unknown"
|
|
10
|
-
*
|
|
11
|
-
* As we want to take those "unknown" tags as custom components, we should
|
|
12
|
-
* treat them as "block" tags
|
|
13
|
-
*
|
|
14
|
-
* So we have to distinguish between "inline" and "unknown" tags ourselves
|
|
15
|
-
*
|
|
16
|
-
* The inline tags list comes from MDN
|
|
17
|
-
*
|
|
18
|
-
* @see https://spec.commonmark.org/0.29/#raw-html
|
|
19
|
-
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/Inline_elements
|
|
20
|
-
*/
|
|
21
|
-
exports.inlineTags = [
|
|
22
|
-
'a',
|
|
23
|
-
'abbr',
|
|
24
|
-
'acronym',
|
|
25
|
-
'audio',
|
|
26
|
-
'b',
|
|
27
|
-
'bdi',
|
|
28
|
-
'bdo',
|
|
29
|
-
'big',
|
|
30
|
-
'br',
|
|
31
|
-
'button',
|
|
32
|
-
'canvas',
|
|
33
|
-
'cite',
|
|
34
|
-
'code',
|
|
35
|
-
'data',
|
|
36
|
-
'datalist',
|
|
37
|
-
'del',
|
|
38
|
-
'dfn',
|
|
39
|
-
'em',
|
|
40
|
-
'embed',
|
|
41
|
-
'i',
|
|
42
|
-
/* iframe is treated as HTML blocks in markdown spec */
|
|
43
|
-
// 'iframe',
|
|
44
|
-
'img',
|
|
45
|
-
'input',
|
|
46
|
-
'ins',
|
|
47
|
-
'kbd',
|
|
48
|
-
'label',
|
|
49
|
-
'map',
|
|
50
|
-
'mark',
|
|
51
|
-
'meter',
|
|
52
|
-
'noscript',
|
|
53
|
-
'object',
|
|
54
|
-
'output',
|
|
55
|
-
'picture',
|
|
56
|
-
'progress',
|
|
57
|
-
'q',
|
|
58
|
-
'ruby',
|
|
59
|
-
's',
|
|
60
|
-
'samp',
|
|
61
|
-
'script',
|
|
62
|
-
'select',
|
|
63
|
-
'slot',
|
|
64
|
-
'small',
|
|
65
|
-
'span',
|
|
66
|
-
'strong',
|
|
67
|
-
'sub',
|
|
68
|
-
'sup',
|
|
69
|
-
'svg',
|
|
70
|
-
'template',
|
|
71
|
-
'textarea',
|
|
72
|
-
'time',
|
|
73
|
-
'u',
|
|
74
|
-
'tt',
|
|
75
|
-
'var',
|
|
76
|
-
'video',
|
|
77
|
-
'wbr',
|
|
78
|
-
];
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.vueReservedTags = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Vue reserved tags
|
|
6
|
-
*
|
|
7
|
-
* @see https://vuejs.org/api/built-in-components.html
|
|
8
|
-
*/
|
|
9
|
-
exports.vueReservedTags = [
|
|
10
|
-
'template',
|
|
11
|
-
'component',
|
|
12
|
-
'transition',
|
|
13
|
-
'transition-group',
|
|
14
|
-
'keep-alive',
|
|
15
|
-
'slot',
|
|
16
|
-
'teleport',
|
|
17
|
-
];
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import type { PluginWithOptions } from 'markdown-it';
|
|
2
|
-
export interface ExtractHeadersPluginOptions {
|
|
3
|
-
/**
|
|
4
|
-
* Heading level that going to be extracted to the `env`
|
|
5
|
-
*
|
|
6
|
-
* Should be a subset of markdown-it-anchor's `level` option
|
|
7
|
-
* to ensure the link is existed
|
|
8
|
-
*/
|
|
9
|
-
level?: number[];
|
|
10
|
-
/**
|
|
11
|
-
* A custom slugify function
|
|
12
|
-
*
|
|
13
|
-
* Should use the same slugify function with markdown-it-anchor
|
|
14
|
-
* to ensure the link is matched
|
|
15
|
-
*/
|
|
16
|
-
slugify?: (str: string) => string;
|
|
17
|
-
/**
|
|
18
|
-
* A function for formatting headers
|
|
19
|
-
*/
|
|
20
|
-
format?: (str: string) => string;
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Extracting markdown headers to env
|
|
24
|
-
*
|
|
25
|
-
* Would be used for generating sidebar nav and toc
|
|
26
|
-
*/
|
|
27
|
-
export declare const extractHeadersPlugin: PluginWithOptions<ExtractHeadersPluginOptions>;
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.extractHeadersPlugin = void 0;
|
|
4
|
-
const utils_1 = require("../utils");
|
|
5
|
-
/**
|
|
6
|
-
* Extracting markdown headers to env
|
|
7
|
-
*
|
|
8
|
-
* Would be used for generating sidebar nav and toc
|
|
9
|
-
*/
|
|
10
|
-
const extractHeadersPlugin = (md, { level = [2, 3], slugify = utils_1.slugify, format, } = {}) => {
|
|
11
|
-
let headers;
|
|
12
|
-
// push the rule to the end of the chain
|
|
13
|
-
// resolve headers from the parsed tokens
|
|
14
|
-
md.core.ruler.push('resolveExtractHeaders', (state) => {
|
|
15
|
-
headers = (0, utils_1.resolveHeadersFromTokens)(state.tokens, {
|
|
16
|
-
level,
|
|
17
|
-
allowHtml: false,
|
|
18
|
-
escapeText: false,
|
|
19
|
-
slugify,
|
|
20
|
-
format,
|
|
21
|
-
});
|
|
22
|
-
return true;
|
|
23
|
-
});
|
|
24
|
-
// extract headers to env
|
|
25
|
-
const render = md.render.bind(md);
|
|
26
|
-
md.render = (src, env = {}) => {
|
|
27
|
-
const result = render(src, env);
|
|
28
|
-
env.headers = headers;
|
|
29
|
-
return result;
|
|
30
|
-
};
|
|
31
|
-
};
|
|
32
|
-
exports.extractHeadersPlugin = extractHeadersPlugin;
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.extractTitlePlugin = void 0;
|
|
4
|
-
const utils_1 = require("../utils");
|
|
5
|
-
/**
|
|
6
|
-
* Extracting markdown title to env
|
|
7
|
-
*/
|
|
8
|
-
const extractTitlePlugin = (md) => {
|
|
9
|
-
let title;
|
|
10
|
-
// push the rule to the end of the chain
|
|
11
|
-
// resolve title from the parsed tokens
|
|
12
|
-
md.core.ruler.push('resolveExtractTitle', (state) => {
|
|
13
|
-
const tokenIdx = state.tokens.findIndex((token) => token.tag === 'h1');
|
|
14
|
-
if (tokenIdx > -1) {
|
|
15
|
-
title = (0, utils_1.resolveTitleFromToken)(state.tokens[tokenIdx + 1], {
|
|
16
|
-
escapeText: false,
|
|
17
|
-
allowHtml: false,
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
else {
|
|
21
|
-
title = '';
|
|
22
|
-
}
|
|
23
|
-
return true;
|
|
24
|
-
});
|
|
25
|
-
// extract title to env
|
|
26
|
-
const render = md.render.bind(md);
|
|
27
|
-
md.render = (src, env = {}) => {
|
|
28
|
-
const result = render(src, env);
|
|
29
|
-
env.title = env.frontmatter?.title ?? title;
|
|
30
|
-
return result;
|
|
31
|
-
};
|
|
32
|
-
};
|
|
33
|
-
exports.extractTitlePlugin = extractTitlePlugin;
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { PluginWithOptions } from 'markdown-it';
|
|
2
|
-
export interface HoistTagsPluginOptions {
|
|
3
|
-
customBlocks?: string[];
|
|
4
|
-
}
|
|
5
|
-
/**
|
|
6
|
-
* Avoid rendering vue SFC script / style blocks
|
|
7
|
-
*
|
|
8
|
-
* Extract them into env
|
|
9
|
-
*
|
|
10
|
-
* Hoist them to vue SFC root level in following process
|
|
11
|
-
*/
|
|
12
|
-
export declare const hoistTagsPlugin: PluginWithOptions<HoistTagsPluginOptions>;
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.hoistTagsPlugin = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Avoid rendering vue SFC script / style blocks
|
|
6
|
-
*
|
|
7
|
-
* Extract them into env
|
|
8
|
-
*
|
|
9
|
-
* Hoist them to vue SFC root level in following process
|
|
10
|
-
*/
|
|
11
|
-
const hoistTagsPlugin = (md, { customBlocks = [] } = {}) => {
|
|
12
|
-
// hoist <script>, <style> and other user defined tags
|
|
13
|
-
const hoistTags = Array.from(new Set(['script', 'style', ...customBlocks]));
|
|
14
|
-
const hoistTagsRegexp = new RegExp(`^<(${hoistTags.join('|')})(?=(\\s|>|$))`, 'i');
|
|
15
|
-
const rawRule = md.renderer.rules.html_block;
|
|
16
|
-
md.renderer.rules.html_block = (tokens, idx, options, env, self) => {
|
|
17
|
-
const content = tokens[idx].content;
|
|
18
|
-
const hoistedTags = env.hoistedTags || (env.hoistedTags = []);
|
|
19
|
-
// record the hoisted tags to env and do not render them
|
|
20
|
-
if (hoistTagsRegexp.test(content.trim())) {
|
|
21
|
-
hoistedTags.push(content);
|
|
22
|
-
return '';
|
|
23
|
-
}
|
|
24
|
-
return rawRule(tokens, idx, options, env, self);
|
|
25
|
-
};
|
|
26
|
-
};
|
|
27
|
-
exports.hoistTagsPlugin = hoistTagsPlugin;
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import type { MarkdownHeader } from '../../types';
|
|
2
|
-
import type { TocPluginOptions } from './tocPlugin';
|
|
3
|
-
declare type RenderHeadersFn = (headers: MarkdownHeader[]) => string;
|
|
4
|
-
export declare const createRenderHeaders: ({ listTag, listClass, itemClass, linkTag, linkClass, }: Pick<Required<TocPluginOptions>, 'listTag' | 'listClass' | 'itemClass' | 'linkTag' | 'linkClass'>) => RenderHeadersFn;
|
|
5
|
-
export {};
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createRenderHeaders = void 0;
|
|
4
|
-
const shared_1 = require("@vuepress/shared");
|
|
5
|
-
const createRenderHeaders = ({ listTag, listClass, itemClass, linkTag, linkClass, }) => {
|
|
6
|
-
const listTagString = (0, shared_1.htmlEscape)(listTag);
|
|
7
|
-
const listClassString = listClass ? ` class="${(0, shared_1.htmlEscape)(listClass)}"` : '';
|
|
8
|
-
const itemTagString = 'li';
|
|
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
|
-
const linkTo = (slug) => linkTag === 'RouterLink' ? ` to="#${slug}"` : ` href="#${slug}"`;
|
|
13
|
-
const renderHeaders = (headers) => `\
|
|
14
|
-
<${listTagString}${listClassString}>\
|
|
15
|
-
${headers
|
|
16
|
-
.map((header) => `\
|
|
17
|
-
<${itemTagString}${itemClassString}${itemClassString}>\
|
|
18
|
-
<${linkTagString}${linkClassString}${linkTo(header.slug)}>\
|
|
19
|
-
${header.title}\
|
|
20
|
-
</${linkTagString}>\
|
|
21
|
-
${header.children.length > 0 ? renderHeaders(header.children) : ''}\
|
|
22
|
-
</${itemTagString}>\
|
|
23
|
-
`)
|
|
24
|
-
.join('')}\
|
|
25
|
-
</${listTagString}>`;
|
|
26
|
-
return renderHeaders;
|
|
27
|
-
};
|
|
28
|
-
exports.createRenderHeaders = createRenderHeaders;
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { RuleBlock } from 'markdown-it/lib/parser_block';
|
|
2
|
-
import type { TocPluginOptions } from './tocPlugin';
|
|
3
|
-
/**
|
|
4
|
-
* Forked and modified from markdown-it-toc-done-right
|
|
5
|
-
*
|
|
6
|
-
* - remove the `inlineOptions` support
|
|
7
|
-
* - use markdown-it default renderer to render token whenever possible
|
|
8
|
-
*
|
|
9
|
-
* @see https://github.com/nagaozen/markdown-it-toc-done-right
|
|
10
|
-
*/
|
|
11
|
-
export declare const createTocBlockRule: ({ pattern, containerTag, containerClass, }: Pick<Required<TocPluginOptions>, 'pattern' | 'containerTag' | 'containerClass'>) => RuleBlock;
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createTocBlockRule = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Forked and modified from markdown-it-toc-done-right
|
|
6
|
-
*
|
|
7
|
-
* - remove the `inlineOptions` support
|
|
8
|
-
* - use markdown-it default renderer to render token whenever possible
|
|
9
|
-
*
|
|
10
|
-
* @see https://github.com/nagaozen/markdown-it-toc-done-right
|
|
11
|
-
*/
|
|
12
|
-
const createTocBlockRule = ({ pattern, containerTag, containerClass, }) => {
|
|
13
|
-
return (state, startLine, endLine, silent) => {
|
|
14
|
-
// if it's indented more than 3 spaces, it should be a code block
|
|
15
|
-
if (state.sCount[startLine] - state.blkIndent >= 4) {
|
|
16
|
-
return false;
|
|
17
|
-
}
|
|
18
|
-
const pos = state.bMarks[startLine] + state.tShift[startLine];
|
|
19
|
-
const max = state.eMarks[startLine];
|
|
20
|
-
// use whitespace as a line tokenizer and extract the first token
|
|
21
|
-
// to test against the placeholder anchored pattern, rejecting if false
|
|
22
|
-
const lineFirstToken = state.src.slice(pos, max).split(' ')[0];
|
|
23
|
-
if (!pattern.test(lineFirstToken))
|
|
24
|
-
return false;
|
|
25
|
-
if (silent)
|
|
26
|
-
return true;
|
|
27
|
-
state.line = startLine + 1;
|
|
28
|
-
// generate toc_open token
|
|
29
|
-
// will be rendered by markdown-it default renderer
|
|
30
|
-
const tokenOpen = state.push('toc_open', containerTag, 1);
|
|
31
|
-
tokenOpen.markup = '';
|
|
32
|
-
tokenOpen.map = [startLine, state.line];
|
|
33
|
-
if (containerClass) {
|
|
34
|
-
tokenOpen.attrSet('class', containerClass);
|
|
35
|
-
}
|
|
36
|
-
// generate toc_body token
|
|
37
|
-
// will be rendered by our custom renderer
|
|
38
|
-
const tokenBody = state.push('toc_body', '', 0);
|
|
39
|
-
tokenBody.markup = lineFirstToken;
|
|
40
|
-
tokenBody.map = [startLine, state.line];
|
|
41
|
-
tokenBody.hidden = true;
|
|
42
|
-
// generate toc_close token
|
|
43
|
-
// will be rendered by markdown-it default renderer
|
|
44
|
-
const tokenClose = state.push('toc_close', containerTag, -1);
|
|
45
|
-
tokenClose.markup = '';
|
|
46
|
-
tokenBody.map = [startLine, state.line];
|
|
47
|
-
return true;
|
|
48
|
-
};
|
|
49
|
-
};
|
|
50
|
-
exports.createTocBlockRule = createTocBlockRule;
|
|
@@ -1,19 +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("./createRenderHeaders"), exports);
|
|
18
|
-
__exportStar(require("./createTocBlockRule"), exports);
|
|
19
|
-
__exportStar(require("./tocPlugin"), exports);
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import type { PluginWithOptions } from 'markdown-it';
|
|
2
|
-
export interface TocPluginOptions {
|
|
3
|
-
/**
|
|
4
|
-
* The pattern serving as the TOC placeholder in your markdown
|
|
5
|
-
*/
|
|
6
|
-
pattern?: RegExp;
|
|
7
|
-
/**
|
|
8
|
-
* A custom slugify function
|
|
9
|
-
*
|
|
10
|
-
* Should use the same slugify function with markdown-it-anchor
|
|
11
|
-
* to ensure the link is matched
|
|
12
|
-
*/
|
|
13
|
-
slugify?: (str: string) => string;
|
|
14
|
-
/**
|
|
15
|
-
* A function for formatting headers
|
|
16
|
-
*/
|
|
17
|
-
format?: (str: string) => string;
|
|
18
|
-
/**
|
|
19
|
-
* Heading level that going to be extracted to the `env`
|
|
20
|
-
*
|
|
21
|
-
* Should be a subset of markdown-it-anchor's `level` option
|
|
22
|
-
* to ensure the link is existed
|
|
23
|
-
*/
|
|
24
|
-
level?: number[];
|
|
25
|
-
/**
|
|
26
|
-
* HTML tag of container
|
|
27
|
-
*/
|
|
28
|
-
containerTag?: string;
|
|
29
|
-
/**
|
|
30
|
-
* The class for container
|
|
31
|
-
*/
|
|
32
|
-
containerClass?: string;
|
|
33
|
-
/**
|
|
34
|
-
* HTML tag of list
|
|
35
|
-
*/
|
|
36
|
-
listTag?: 'ul' | 'ol';
|
|
37
|
-
/**
|
|
38
|
-
* The class for list
|
|
39
|
-
*/
|
|
40
|
-
listClass?: string;
|
|
41
|
-
/**
|
|
42
|
-
* The class for the <li> tag
|
|
43
|
-
*/
|
|
44
|
-
itemClass?: string;
|
|
45
|
-
/**
|
|
46
|
-
* The tag for the link inside <li>
|
|
47
|
-
*/
|
|
48
|
-
linkTag?: 'a' | 'RouterLink';
|
|
49
|
-
/**
|
|
50
|
-
* The class for the link tag inside <li>
|
|
51
|
-
*/
|
|
52
|
-
linkClass?: string;
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* Generate table of contents
|
|
56
|
-
*
|
|
57
|
-
* Forked and modified from markdown-it-toc-done-right:
|
|
58
|
-
*
|
|
59
|
-
* - Allows `html_inline` tags in headings to support vue components
|
|
60
|
-
* - Allows render `<RouterLink>` instead of `<a>` for links
|
|
61
|
-
* - Code refactor and optimizations
|
|
62
|
-
*
|
|
63
|
-
* @see https://github.com/nagaozen/markdown-it-toc-done-right
|
|
64
|
-
*/
|
|
65
|
-
export declare const tocPlugin: PluginWithOptions<TocPluginOptions>;
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.tocPlugin = void 0;
|
|
4
|
-
const utils_1 = require("../../utils");
|
|
5
|
-
const createRenderHeaders_1 = require("./createRenderHeaders");
|
|
6
|
-
const createTocBlockRule_1 = require("./createTocBlockRule");
|
|
7
|
-
/**
|
|
8
|
-
* Generate table of contents
|
|
9
|
-
*
|
|
10
|
-
* Forked and modified from markdown-it-toc-done-right:
|
|
11
|
-
*
|
|
12
|
-
* - Allows `html_inline` tags in headings to support vue components
|
|
13
|
-
* - Allows render `<RouterLink>` instead of `<a>` for links
|
|
14
|
-
* - Code refactor and optimizations
|
|
15
|
-
*
|
|
16
|
-
* @see https://github.com/nagaozen/markdown-it-toc-done-right
|
|
17
|
-
*/
|
|
18
|
-
const tocPlugin = (md, { pattern = /^\[\[toc\]\]$/i, slugify = utils_1.slugify, format, level = [2, 3], containerTag = 'nav', containerClass = 'table-of-contents', listTag = 'ul', listClass = '', itemClass = '', linkTag = 'a', linkClass = '', } = {}) => {
|
|
19
|
-
let headers;
|
|
20
|
-
// push the rule to the end of the chain
|
|
21
|
-
// resolve headers from the parsed tokens
|
|
22
|
-
md.core.ruler.push('resolveTocHeaders', (state) => {
|
|
23
|
-
headers = (0, utils_1.resolveHeadersFromTokens)(state.tokens, {
|
|
24
|
-
level,
|
|
25
|
-
allowHtml: true,
|
|
26
|
-
escapeText: true,
|
|
27
|
-
slugify,
|
|
28
|
-
format,
|
|
29
|
-
});
|
|
30
|
-
return true;
|
|
31
|
-
});
|
|
32
|
-
// add toc syntax as a block rule
|
|
33
|
-
md.block.ruler.before('heading', 'toc', (0, createTocBlockRule_1.createTocBlockRule)({
|
|
34
|
-
pattern,
|
|
35
|
-
containerTag,
|
|
36
|
-
containerClass,
|
|
37
|
-
}), {
|
|
38
|
-
alt: ['paragraph', 'reference', 'blockquote'],
|
|
39
|
-
});
|
|
40
|
-
const renderHeaders = (0, createRenderHeaders_1.createRenderHeaders)({
|
|
41
|
-
listTag,
|
|
42
|
-
listClass,
|
|
43
|
-
itemClass,
|
|
44
|
-
linkTag,
|
|
45
|
-
linkClass,
|
|
46
|
-
});
|
|
47
|
-
// custom toc_body render rule
|
|
48
|
-
md.renderer.rules.toc_body = () => {
|
|
49
|
-
/* istanbul ignore if */
|
|
50
|
-
if (!headers) {
|
|
51
|
-
return '';
|
|
52
|
-
}
|
|
53
|
-
return renderHeaders(headers);
|
|
54
|
-
};
|
|
55
|
-
};
|
|
56
|
-
exports.tocPlugin = tocPlugin;
|
package/lib/utils/index.d.ts
DELETED
package/lib/utils/index.js
DELETED
|
@@ -1,19 +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("./resolveHeadersFromTokens"), exports);
|
|
18
|
-
__exportStar(require("./resolveTitleFromToken"), exports);
|
|
19
|
-
__exportStar(require("./slugify"), exports);
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type * as Token from 'markdown-it/lib/token';
|
|
2
|
-
import type { MarkdownHeader } from '../types';
|
|
3
|
-
/**
|
|
4
|
-
* Resolve headers from markdown-it tokens
|
|
5
|
-
*/
|
|
6
|
-
export declare const resolveHeadersFromTokens: (tokens: Token[], { level, allowHtml, escapeText, slugify, format, }: {
|
|
7
|
-
level: number[];
|
|
8
|
-
allowHtml: boolean;
|
|
9
|
-
escapeText: boolean;
|
|
10
|
-
slugify: (str: string) => string;
|
|
11
|
-
format?: ((str: string) => string) | undefined;
|
|
12
|
-
}) => MarkdownHeader[];
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.resolveHeadersFromTokens = void 0;
|
|
4
|
-
const shared_1 = require("@vuepress/shared");
|
|
5
|
-
const resolveTitleFromToken_1 = require("./resolveTitleFromToken");
|
|
6
|
-
/**
|
|
7
|
-
* Resolve headers from markdown-it tokens
|
|
8
|
-
*/
|
|
9
|
-
const resolveHeadersFromTokens = (tokens, { level, allowHtml, escapeText, slugify, format, }) => {
|
|
10
|
-
// store the result of headers
|
|
11
|
-
const headers = [];
|
|
12
|
-
// a temp headers stack for generating the headers tree
|
|
13
|
-
const stack = [];
|
|
14
|
-
// push a header to the headers tree
|
|
15
|
-
const push = (header) => {
|
|
16
|
-
while (stack.length !== 0 && header.level <= stack[0].level) {
|
|
17
|
-
stack.shift();
|
|
18
|
-
}
|
|
19
|
-
if (stack.length === 0) {
|
|
20
|
-
headers.push(header);
|
|
21
|
-
stack.push(header);
|
|
22
|
-
}
|
|
23
|
-
else {
|
|
24
|
-
stack[0].children.push(header);
|
|
25
|
-
stack.unshift(header);
|
|
26
|
-
}
|
|
27
|
-
};
|
|
28
|
-
tokens.forEach((_, idx) => {
|
|
29
|
-
const token = tokens[idx];
|
|
30
|
-
// if the token type does not match, skip
|
|
31
|
-
if (token?.type !== 'heading_open') {
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
// get the level from the tag, h1 -> 1
|
|
35
|
-
const headerLevel = Number.parseInt(token.tag.slice(1), 10);
|
|
36
|
-
// if the level should not be extracted, skip
|
|
37
|
-
if (!level.includes(headerLevel)) {
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
40
|
-
// the next token of 'heading_open' contains the heading content
|
|
41
|
-
const nextToken = tokens[idx + 1];
|
|
42
|
-
// if the next token does not exist, skip
|
|
43
|
-
if (!nextToken) {
|
|
44
|
-
return;
|
|
45
|
-
}
|
|
46
|
-
const title = (0, resolveTitleFromToken_1.resolveTitleFromToken)(nextToken, {
|
|
47
|
-
allowHtml,
|
|
48
|
-
escapeText,
|
|
49
|
-
});
|
|
50
|
-
// the id of the heading anchor is the slugify result of markdown-it-anchor
|
|
51
|
-
// if the id does not exist, slugify the title ourselves
|
|
52
|
-
const slug = token.attrGet('id') ?? slugify(title);
|
|
53
|
-
// push the header to tree
|
|
54
|
-
push({
|
|
55
|
-
level: headerLevel,
|
|
56
|
-
title: (0, shared_1.isFunction)(format) ? format(title) : title,
|
|
57
|
-
slug,
|
|
58
|
-
children: [],
|
|
59
|
-
});
|
|
60
|
-
});
|
|
61
|
-
return headers;
|
|
62
|
-
};
|
|
63
|
-
exports.resolveHeadersFromTokens = resolveHeadersFromTokens;
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type * as Token from 'markdown-it/lib/token';
|
|
2
|
-
/**
|
|
3
|
-
* Resolve header title from markdown-it token
|
|
4
|
-
*
|
|
5
|
-
* Typically using the next token of `heading_open` token
|
|
6
|
-
*/
|
|
7
|
-
export declare const resolveTitleFromToken: (token: Token, { allowHtml, escapeText, }: {
|
|
8
|
-
allowHtml: boolean;
|
|
9
|
-
escapeText: boolean;
|
|
10
|
-
}) => string;
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.resolveTitleFromToken = void 0;
|
|
4
|
-
const shared_1 = require("@vuepress/shared");
|
|
5
|
-
/**
|
|
6
|
-
* Resolve header title from markdown-it token
|
|
7
|
-
*
|
|
8
|
-
* Typically using the next token of `heading_open` token
|
|
9
|
-
*/
|
|
10
|
-
const resolveTitleFromToken = (token, { allowHtml, escapeText, }) => {
|
|
11
|
-
// children of the token contains the parsed result of the heading title
|
|
12
|
-
const children = token.children ?? [];
|
|
13
|
-
// type of tokens to be included in the heading title
|
|
14
|
-
const titleTokenTypes = ['text', 'emoji', 'code_inline'];
|
|
15
|
-
// include 'html_inline' or not
|
|
16
|
-
if (allowHtml) {
|
|
17
|
-
titleTokenTypes.push('html_inline');
|
|
18
|
-
}
|
|
19
|
-
// filter the token type to be included in the title
|
|
20
|
-
const titleTokens = children.filter((item) => titleTokenTypes.includes(item.type) &&
|
|
21
|
-
// filter permalink symbol that generated by markdown-it-anchor
|
|
22
|
-
!item.meta?.isPermalinkSymbol);
|
|
23
|
-
// get title from tokens
|
|
24
|
-
return titleTokens
|
|
25
|
-
.reduce((result, item) => {
|
|
26
|
-
if (escapeText) {
|
|
27
|
-
// escape the content of 'code_inline' and 'text'
|
|
28
|
-
if (item.type === 'code_inline' || item.type === 'text') {
|
|
29
|
-
return `${result}${(0, shared_1.htmlEscape)(item.content)}`;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
// keep the content of 'emoji' and 'html_inline'
|
|
33
|
-
return `${result}${item.content}`;
|
|
34
|
-
}, '')
|
|
35
|
-
.trim();
|
|
36
|
-
};
|
|
37
|
-
exports.resolveTitleFromToken = resolveTitleFromToken;
|
package/lib/utils/slugify.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const slugify: (str: string) => string;
|
package/lib/utils/slugify.js
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.slugify = void 0;
|
|
4
|
-
// eslint-disable-next-line no-control-regex
|
|
5
|
-
const rControl = /[\u0000-\u001f]/g;
|
|
6
|
-
const rSpecial = /[\s~`!@#$%^&*()\-_+=[\]{}|\\;:"'“”‘’<>,.?/]+/g;
|
|
7
|
-
const rCombining = /[\u0300-\u036F]/g;
|
|
8
|
-
const slugify = (str) => str
|
|
9
|
-
.normalize('NFKD')
|
|
10
|
-
// Remove accents
|
|
11
|
-
.replace(rCombining, '')
|
|
12
|
-
// Remove control characters
|
|
13
|
-
.replace(rControl, '')
|
|
14
|
-
// Replace special characters
|
|
15
|
-
.replace(rSpecial, '-')
|
|
16
|
-
// Remove continuos separators
|
|
17
|
-
.replace(/-{2,}/g, '-')
|
|
18
|
-
// Remove prefixing and trailing separators
|
|
19
|
-
.replace(/^-+|-+$/g, '')
|
|
20
|
-
// ensure it doesn't start with a number (#121)
|
|
21
|
-
.replace(/^(\d)/, '_$1')
|
|
22
|
-
// lowercase
|
|
23
|
-
.toLowerCase();
|
|
24
|
-
exports.slugify = slugify;
|