@vuepress/markdown 2.0.0-beta.48 → 2.0.0-beta.50-pre

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.
Files changed (85) hide show
  1. package/package.json +39 -8
  2. package/lib/index.d.ts +0 -4
  3. package/lib/index.js +0 -20
  4. package/lib/markdown.d.ts +0 -5
  5. package/lib/markdown.js +0 -88
  6. package/lib/plugins/anchorPlugin.d.ts +0 -3
  7. package/lib/plugins/anchorPlugin.js +0 -5
  8. package/lib/plugins/assetsPlugin/assetsPlugin.d.ts +0 -11
  9. package/lib/plugins/assetsPlugin/assetsPlugin.js +0 -41
  10. package/lib/plugins/assetsPlugin/index.d.ts +0 -2
  11. package/lib/plugins/assetsPlugin/index.js +0 -18
  12. package/lib/plugins/assetsPlugin/resolveLink.d.ts +0 -2
  13. package/lib/plugins/assetsPlugin/resolveLink.js +0 -16
  14. package/lib/plugins/codePlugin/codePlugin.d.ts +0 -40
  15. package/lib/plugins/codePlugin/codePlugin.js +0 -78
  16. package/lib/plugins/codePlugin/index.d.ts +0 -6
  17. package/lib/plugins/codePlugin/index.js +0 -22
  18. package/lib/plugins/codePlugin/languages.d.ts +0 -38
  19. package/lib/plugins/codePlugin/languages.js +0 -68
  20. package/lib/plugins/codePlugin/resolveHighlightLines.d.ts +0 -9
  21. package/lib/plugins/codePlugin/resolveHighlightLines.js +0 -28
  22. package/lib/plugins/codePlugin/resolveLanguage.d.ts +0 -5
  23. package/lib/plugins/codePlugin/resolveLanguage.js +0 -40
  24. package/lib/plugins/codePlugin/resolveLineNumbers.d.ts +0 -4
  25. package/lib/plugins/codePlugin/resolveLineNumbers.js +0 -16
  26. package/lib/plugins/codePlugin/resolveVPre.d.ts +0 -4
  27. package/lib/plugins/codePlugin/resolveVPre.js +0 -16
  28. package/lib/plugins/customComponentPlugin/customComponentPlugin.d.ts +0 -6
  29. package/lib/plugins/customComponentPlugin/customComponentPlugin.js +0 -18
  30. package/lib/plugins/customComponentPlugin/htmlBlockRule.d.ts +0 -2
  31. package/lib/plugins/customComponentPlugin/htmlBlockRule.js +0 -90
  32. package/lib/plugins/customComponentPlugin/htmlInlineRule.d.ts +0 -2
  33. package/lib/plugins/customComponentPlugin/htmlInlineRule.js +0 -40
  34. package/lib/plugins/customComponentPlugin/htmlRe.d.ts +0 -2
  35. package/lib/plugins/customComponentPlugin/htmlRe.js +0 -33
  36. package/lib/plugins/customComponentPlugin/index.d.ts +0 -6
  37. package/lib/plugins/customComponentPlugin/index.js +0 -22
  38. package/lib/plugins/customComponentPlugin/inlineTags.d.ts +0 -18
  39. package/lib/plugins/customComponentPlugin/inlineTags.js +0 -78
  40. package/lib/plugins/customComponentPlugin/vueReservedTags.d.ts +0 -6
  41. package/lib/plugins/customComponentPlugin/vueReservedTags.js +0 -17
  42. package/lib/plugins/emojiPlugin.d.ts +0 -25
  43. package/lib/plugins/emojiPlugin.js +0 -5
  44. package/lib/plugins/extractHeadersPlugin.d.ts +0 -28
  45. package/lib/plugins/extractHeadersPlugin.js +0 -32
  46. package/lib/plugins/extractTitlePlugin.d.ts +0 -5
  47. package/lib/plugins/extractTitlePlugin.js +0 -33
  48. package/lib/plugins/hoistTagsPlugin.d.ts +0 -12
  49. package/lib/plugins/hoistTagsPlugin.js +0 -27
  50. package/lib/plugins/importCodePlugin/createImportCodeBlockRule.d.ts +0 -3
  51. package/lib/plugins/importCodePlugin/createImportCodeBlockRule.js +0 -52
  52. package/lib/plugins/importCodePlugin/importCodePlugin.d.ts +0 -8
  53. package/lib/plugins/importCodePlugin/importCodePlugin.js +0 -26
  54. package/lib/plugins/importCodePlugin/index.d.ts +0 -4
  55. package/lib/plugins/importCodePlugin/index.js +0 -20
  56. package/lib/plugins/importCodePlugin/resolveImportCode.d.ts +0 -6
  57. package/lib/plugins/importCodePlugin/resolveImportCode.js +0 -37
  58. package/lib/plugins/importCodePlugin/types.d.ts +0 -5
  59. package/lib/plugins/importCodePlugin/types.js +0 -2
  60. package/lib/plugins/index.d.ts +0 -11
  61. package/lib/plugins/index.js +0 -27
  62. package/lib/plugins/linksPlugin/index.d.ts +0 -2
  63. package/lib/plugins/linksPlugin/index.js +0 -18
  64. package/lib/plugins/linksPlugin/linksPlugin.d.ts +0 -28
  65. package/lib/plugins/linksPlugin/linksPlugin.js +0 -98
  66. package/lib/plugins/linksPlugin/resolvePaths.d.ts +0 -7
  67. package/lib/plugins/linksPlugin/resolvePaths.js +0 -51
  68. package/lib/plugins/tocPlugin/createRenderHeaders.d.ts +0 -5
  69. package/lib/plugins/tocPlugin/createRenderHeaders.js +0 -28
  70. package/lib/plugins/tocPlugin/createTocBlockRule.d.ts +0 -11
  71. package/lib/plugins/tocPlugin/createTocBlockRule.js +0 -50
  72. package/lib/plugins/tocPlugin/index.d.ts +0 -3
  73. package/lib/plugins/tocPlugin/index.js +0 -19
  74. package/lib/plugins/tocPlugin/tocPlugin.d.ts +0 -66
  75. package/lib/plugins/tocPlugin/tocPlugin.js +0 -56
  76. package/lib/types.d.ts +0 -81
  77. package/lib/types.js +0 -2
  78. package/lib/utils/index.d.ts +0 -3
  79. package/lib/utils/index.js +0 -19
  80. package/lib/utils/resolveHeadersFromTokens.d.ts +0 -12
  81. package/lib/utils/resolveHeadersFromTokens.js +0 -63
  82. package/lib/utils/resolveTitleFromToken.d.ts +0 -10
  83. package/lib/utils/resolveTitleFromToken.js +0 -37
  84. package/lib/utils/vuepressSlugify.d.ts +0 -5
  85. package/lib/utils/vuepressSlugify.js +0 -27
@@ -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,4 +0,0 @@
1
- export * from './createImportCodeBlockRule';
2
- export * from './importCodePlugin';
3
- export * from './resolveImportCode';
4
- export * from './types';
@@ -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;
@@ -1,5 +0,0 @@
1
- export interface ImportCodeTokenMeta {
2
- importPath: string;
3
- lineStart: number;
4
- lineEnd?: number;
5
- }
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,11 +0,0 @@
1
- export * from './anchorPlugin';
2
- export * from './assetsPlugin';
3
- export * from './codePlugin';
4
- export * from './customComponentPlugin';
5
- export * from './emojiPlugin';
6
- export * from './extractHeadersPlugin';
7
- export * from './extractTitlePlugin';
8
- export * from './hoistTagsPlugin';
9
- export * from './importCodePlugin';
10
- export * from './linksPlugin';
11
- export * from './tocPlugin';
@@ -1,27 +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("./anchorPlugin"), exports);
18
- __exportStar(require("./assetsPlugin"), exports);
19
- __exportStar(require("./codePlugin"), exports);
20
- __exportStar(require("./customComponentPlugin"), exports);
21
- __exportStar(require("./emojiPlugin"), exports);
22
- __exportStar(require("./extractHeadersPlugin"), exports);
23
- __exportStar(require("./extractTitlePlugin"), exports);
24
- __exportStar(require("./hoistTagsPlugin"), exports);
25
- __exportStar(require("./importCodePlugin"), exports);
26
- __exportStar(require("./linksPlugin"), exports);
27
- __exportStar(require("./tocPlugin"), exports);
@@ -1,2 +0,0 @@
1
- export * from './linksPlugin';
2
- export * from './resolvePaths';
@@ -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,7 +0,0 @@
1
- /**
2
- * Resolve relative and absolute paths according to the `base` and `filePathRelative`
3
- */
4
- export declare const resolvePaths: (rawPath: string, base: string, filePathRelative: string | null) => {
5
- absolutePath: string;
6
- relativePath: string;
7
- };
@@ -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;
@@ -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,3 +0,0 @@
1
- export * from './createRenderHeaders';
2
- export * from './createTocBlockRule';
3
- export * from './tocPlugin';
@@ -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,66 +0,0 @@
1
- import type { PluginWithOptions } from 'markdown-it';
2
- import type { MarkdownSlugifyFunction } from '../../types';
3
- export interface TocPluginOptions {
4
- /**
5
- * The pattern serving as the TOC placeholder in your markdown
6
- */
7
- pattern?: RegExp;
8
- /**
9
- * A custom slugify function
10
- *
11
- * Should use the same slugify function with markdown-it-anchor
12
- * to ensure the link is matched
13
- */
14
- slugify?: MarkdownSlugifyFunction;
15
- /**
16
- * A function for formatting headers
17
- */
18
- format?: (str: string) => string;
19
- /**
20
- * Heading level that going to be extracted to the `env`
21
- *
22
- * Should be a subset of markdown-it-anchor's `level` option
23
- * to ensure the link is existed
24
- */
25
- level?: number[];
26
- /**
27
- * HTML tag of container
28
- */
29
- containerTag?: string;
30
- /**
31
- * The class for container
32
- */
33
- containerClass?: string;
34
- /**
35
- * HTML tag of list
36
- */
37
- listTag?: 'ul' | 'ol';
38
- /**
39
- * The class for list
40
- */
41
- listClass?: string;
42
- /**
43
- * The class for the <li> tag
44
- */
45
- itemClass?: string;
46
- /**
47
- * The tag for the link inside <li>
48
- */
49
- linkTag?: 'a' | 'RouterLink';
50
- /**
51
- * The class for the link tag inside <li>
52
- */
53
- linkClass?: string;
54
- }
55
- /**
56
- * Generate table of contents
57
- *
58
- * Forked and modified from markdown-it-toc-done-right:
59
- *
60
- * - Allows `html_inline` tags in headings to support vue components
61
- * - Allows render `<RouterLink>` instead of `<a>` for links
62
- * - Code refactor and optimizations
63
- *
64
- * @see https://github.com/nagaozen/markdown-it-toc-done-right
65
- */
66
- 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.vuepressSlugify, 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;