@vuepress/markdown 2.0.0-beta.5 → 2.0.0-beta.50

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 (72) hide show
  1. package/dist/index.d.ts +184 -0
  2. package/dist/index.js +561 -0
  3. package/package.json +48 -17
  4. package/CHANGELOG.md +0 -212
  5. package/lib/index.d.ts +0 -4
  6. package/lib/index.js +0 -16
  7. package/lib/markdown.d.ts +0 -5
  8. package/lib/markdown.js +0 -77
  9. package/lib/plugins/anchorPlugin.d.ts +0 -62
  10. package/lib/plugins/anchorPlugin.js +0 -5
  11. package/lib/plugins/assetsPlugin.d.ts +0 -11
  12. package/lib/plugins/assetsPlugin.js +0 -24
  13. package/lib/plugins/codePlugin/codePlugin.d.ts +0 -28
  14. package/lib/plugins/codePlugin/codePlugin.js +0 -73
  15. package/lib/plugins/codePlugin/index.d.ts +0 -6
  16. package/lib/plugins/codePlugin/index.js +0 -18
  17. package/lib/plugins/codePlugin/languages.d.ts +0 -38
  18. package/lib/plugins/codePlugin/languages.js +0 -68
  19. package/lib/plugins/codePlugin/resolveHighlightLines.d.ts +0 -9
  20. package/lib/plugins/codePlugin/resolveHighlightLines.js +0 -28
  21. package/lib/plugins/codePlugin/resolveLanguage.d.ts +0 -5
  22. package/lib/plugins/codePlugin/resolveLanguage.js +0 -41
  23. package/lib/plugins/codePlugin/resolveLineNumbers.d.ts +0 -4
  24. package/lib/plugins/codePlugin/resolveLineNumbers.js +0 -16
  25. package/lib/plugins/codePlugin/resolveVPre.d.ts +0 -4
  26. package/lib/plugins/codePlugin/resolveVPre.js +0 -16
  27. package/lib/plugins/customComponentPlugin/customComponentPlugin.d.ts +0 -6
  28. package/lib/plugins/customComponentPlugin/customComponentPlugin.js +0 -18
  29. package/lib/plugins/customComponentPlugin/htmlBlockRule.d.ts +0 -2
  30. package/lib/plugins/customComponentPlugin/htmlBlockRule.js +0 -90
  31. package/lib/plugins/customComponentPlugin/htmlInlineRule.d.ts +0 -2
  32. package/lib/plugins/customComponentPlugin/htmlInlineRule.js +0 -40
  33. package/lib/plugins/customComponentPlugin/htmlRe.d.ts +0 -2
  34. package/lib/plugins/customComponentPlugin/htmlRe.js +0 -33
  35. package/lib/plugins/customComponentPlugin/index.d.ts +0 -4
  36. package/lib/plugins/customComponentPlugin/index.js +0 -16
  37. package/lib/plugins/customComponentPlugin/inlineTags.d.ts +0 -18
  38. package/lib/plugins/customComponentPlugin/inlineTags.js +0 -78
  39. package/lib/plugins/customComponentPlugin/vueReservedTags.d.ts +0 -6
  40. package/lib/plugins/customComponentPlugin/vueReservedTags.js +0 -17
  41. package/lib/plugins/emojiPlugin.d.ts +0 -25
  42. package/lib/plugins/emojiPlugin.js +0 -5
  43. package/lib/plugins/extractHeadersPlugin.d.ts +0 -27
  44. package/lib/plugins/extractHeadersPlugin.js +0 -31
  45. package/lib/plugins/hoistTagsPlugin.d.ts +0 -12
  46. package/lib/plugins/hoistTagsPlugin.js +0 -26
  47. package/lib/plugins/index.d.ts +0 -9
  48. package/lib/plugins/index.js +0 -21
  49. package/lib/plugins/linksPlugin/index.d.ts +0 -2
  50. package/lib/plugins/linksPlugin/index.js +0 -14
  51. package/lib/plugins/linksPlugin/linksPlugin.d.ts +0 -11
  52. package/lib/plugins/linksPlugin/linksPlugin.js +0 -104
  53. package/lib/plugins/linksPlugin/resolvePaths.d.ts +0 -7
  54. package/lib/plugins/linksPlugin/resolvePaths.js +0 -38
  55. package/lib/plugins/tocPlugin/createRenderHeaders.d.ts +0 -5
  56. package/lib/plugins/tocPlugin/createRenderHeaders.js +0 -28
  57. package/lib/plugins/tocPlugin/createTocBlockRule.d.ts +0 -11
  58. package/lib/plugins/tocPlugin/createTocBlockRule.js +0 -50
  59. package/lib/plugins/tocPlugin/index.d.ts +0 -3
  60. package/lib/plugins/tocPlugin/index.js +0 -15
  61. package/lib/plugins/tocPlugin/tocPlugin.d.ts +0 -65
  62. package/lib/plugins/tocPlugin/tocPlugin.js +0 -54
  63. package/lib/types.d.ts +0 -58
  64. package/lib/types.js +0 -2
  65. package/lib/utils/index.d.ts +0 -3
  66. package/lib/utils/index.js +0 -15
  67. package/lib/utils/parseEmoji.d.ts +0 -1
  68. package/lib/utils/parseEmoji.js +0 -6
  69. package/lib/utils/resolveHeadersFromTokens.d.ts +0 -11
  70. package/lib/utils/resolveHeadersFromTokens.js +0 -81
  71. package/lib/utils/slugify.d.ts +0 -1
  72. package/lib/utils/slugify.js +0 -24
@@ -1,11 +0,0 @@
1
- import type { PluginWithOptions } from 'markdown-it';
2
- export interface LinksPluginOptions {
3
- externalAttrs?: Record<string, string>;
4
- }
5
- /**
6
- * Process links in markdown file
7
- *
8
- * - internal links: convert them into `<RouterLink>`
9
- * - external links: add extra attrs and add `<OutboundLink/>` before their ending tag
10
- */
11
- export declare const linksPlugin: PluginWithOptions<LinksPluginOptions>;
@@ -1,104 +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 add `<OutboundLink/>` before their ending tag
11
- */
12
- const linksPlugin = (md, options = {}) => {
13
- // attrs that going to be added to external links
14
- const externalAttrs = {
15
- target: '_blank',
16
- rel: 'noopener noreferrer',
17
- ...options.externalAttrs,
18
- };
19
- let hasOpenRouterLink = false;
20
- let hasOpenExternalLink = false;
21
- const handleLinkOpen = (tokens, idx, env) => {
22
- // get current token
23
- const token = tokens[idx];
24
- // get `href` attr index
25
- const hrefIndex = token.attrIndex('href');
26
- // if `href` attr does not exist, skip
27
- /* istanbul ignore if */
28
- if (hrefIndex < 0) {
29
- return;
30
- }
31
- // if `href` attr exists, `token.attrs` is not `null`
32
- const hrefAttr = token.attrs[hrefIndex];
33
- const hrefLink = hrefAttr[1];
34
- // get `base` and `filePathRelative` from `env`
35
- const { base = '/', filePathRelative = null } = env;
36
- // check if a link is an external link
37
- if (shared_1.isLinkExternal(hrefLink, base)) {
38
- // set `externalAttrs` to current token
39
- Object.entries(externalAttrs).forEach(([key, val]) => token.attrSet(key, val));
40
- // only when an external link has `target="_blank"`
41
- // should we add `<OutboundLink/>` before ending tag
42
- if (/\b_blank\b/i.test(externalAttrs.target)) {
43
- hasOpenExternalLink = true;
44
- }
45
- return;
46
- }
47
- // check if a link is an internal link
48
- const internalLinkMatch = hrefLink.match(/^((?:.*)(?:\/|\.md|\.html))(#.*)?$/);
49
- if (internalLinkMatch) {
50
- hasOpenRouterLink = true;
51
- // convert
52
- // <a href="hrefLink">
53
- // to
54
- // <RouterLink to="toProp">
55
- // notice that the path and hash are encoded by markdown-it
56
- const rawPath = internalLinkMatch[1];
57
- const rawHash = internalLinkMatch[2] || '';
58
- // resolve relative and absolute path
59
- const { relativePath, absolutePath } = resolvePaths_1.resolvePaths(rawPath, base, filePathRelative);
60
- // normalize markdown file path to route path
61
- //
62
- // we are removing the `base` from absolute path because it should not be
63
- // passed to `<RouterLink>`
64
- //
65
- // '/foo/index.md' => '/foo/'
66
- // '/foo/bar.md' => '/foo/bar.html'
67
- const normalizedPath = absolutePath
68
- .replace(new RegExp(`^${base}`), '/')
69
- .replace(/(^|\/)(README|index).md$/i, '$1')
70
- .replace(/\.md$/, '.html');
71
- // convert starting tag of internal link to `<RouterLink>`
72
- token.tag = 'RouterLink';
73
- // replace the original `href` attr with `to` attr
74
- hrefAttr[0] = 'to';
75
- hrefAttr[1] = `${normalizedPath}${rawHash}`;
76
- // extract internal links for file / page existence check
77
- const links = env.links || (env.links = []);
78
- links.push({
79
- raw: hrefLink,
80
- relative: relativePath,
81
- absolute: absolutePath,
82
- });
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
- const token = tokens[idx];
91
- // add `<OutboundLink/>` before ending tag of external link
92
- if (hasOpenExternalLink) {
93
- hasOpenExternalLink = false;
94
- return '<OutboundLink/>' + self.renderToken(tokens, idx, options);
95
- }
96
- // convert ending tag of internal link to `</RouterLink>`
97
- if (hasOpenRouterLink) {
98
- hasOpenRouterLink = false;
99
- token.tag = 'RouterLink';
100
- }
101
- return self.renderToken(tokens, idx, options);
102
- };
103
- };
104
- 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,38 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.resolvePaths = void 0;
4
- const utils_1 = require("@vuepress/utils");
5
- /**
6
- * Resolve relative and absolute paths according to the `base` and `filePathRelative`
7
- */
8
- const resolvePaths = (rawPath, base, filePathRelative) => {
9
- let relativePath;
10
- let absolutePath;
11
- if (rawPath.startsWith('/')) {
12
- // if raw path is absolute
13
- absolutePath = rawPath;
14
- relativePath = utils_1.path.relative(base, absolutePath);
15
- }
16
- else {
17
- // if raw path is relative
18
- if (filePathRelative) {
19
- // if `filePathRelative` is available
20
- // resolve relative path according to `filePathRelative`
21
- relativePath = utils_1.path.join(utils_1.path.dirname(filePathRelative), rawPath);
22
- // resolve absolute path according to `base`
23
- absolutePath = utils_1.path.join(base, relativePath);
24
- }
25
- else {
26
- // if `filePathRelative` is not available
27
- // remove leading './'
28
- relativePath = rawPath.replace(/^(?:\.\/)?(.*)$/, '$1');
29
- // just take relative link as absolute link
30
- absolutePath = relativePath;
31
- }
32
- }
33
- return {
34
- absolutePath,
35
- relativePath,
36
- };
37
- };
38
- 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 = shared_1.htmlEscape(listTag);
7
- const listClassString = listClass ? ` class="${shared_1.htmlEscape(listClass)}"` : '';
8
- const itemTagString = 'li';
9
- const itemClassString = itemClass ? ` class="${shared_1.htmlEscape(itemClass)}"` : '';
10
- const linkTagString = shared_1.htmlEscape(linkTag);
11
- const linkClassString = linkClass ? ` class="${shared_1.htmlEscape(linkClass)}` : '';
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,15 +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
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
- }) : (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- o[k2] = m[k];
8
- }));
9
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
- };
12
- Object.defineProperty(exports, "__esModule", { value: true });
13
- __exportStar(require("./createRenderHeaders"), exports);
14
- __exportStar(require("./createTocBlockRule"), exports);
15
- __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,54 +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 = utils_1.resolveHeadersFromTokens(state.tokens, {
24
- level,
25
- allowHtml: true,
26
- slugify,
27
- format,
28
- });
29
- return true;
30
- });
31
- // add toc syntax as a block rule
32
- md.block.ruler.before('heading', 'toc', createTocBlockRule_1.createTocBlockRule({
33
- pattern,
34
- containerTag,
35
- containerClass,
36
- }), {
37
- alt: ['paragraph', 'reference', 'blockquote'],
38
- });
39
- const renderHeaders = createRenderHeaders_1.createRenderHeaders({
40
- listTag,
41
- listClass,
42
- itemClass,
43
- linkTag,
44
- linkClass,
45
- });
46
- // custom toc_body render rule
47
- md.renderer.rules.toc_body = () => {
48
- if (!headers) {
49
- return '';
50
- }
51
- return renderHeaders(headers);
52
- };
53
- };
54
- exports.tocPlugin = tocPlugin;
package/lib/types.d.ts DELETED
@@ -1,58 +0,0 @@
1
- import * as MarkdownIt from 'markdown-it';
2
- import type { PageHeader } from '@vuepress/shared';
3
- import type { AnchorPluginOptions, AssetsPluginOptions, CodePluginOptions, EmojiPluginOptions, ExtractHeadersPluginOptions, HoistTagsPluginOptions, LinksPluginOptions, TocPluginOptions } from './plugins';
4
- export declare type Markdown = MarkdownIt;
5
- export interface MarkdownOptions extends MarkdownIt.Options {
6
- anchor?: false | AnchorPluginOptions;
7
- assets?: false | AssetsPluginOptions;
8
- code?: false | CodePluginOptions;
9
- customComponent?: false;
10
- emoji?: false | EmojiPluginOptions;
11
- extractHeaders?: false | ExtractHeadersPluginOptions;
12
- hoistTags?: false | HoistTagsPluginOptions;
13
- links?: false | LinksPluginOptions;
14
- toc?: false | TocPluginOptions;
15
- }
16
- /**
17
- * Headers in markdown file
18
- */
19
- export declare type MarkdownHeader = PageHeader;
20
- /**
21
- * Internal links in markdown file
22
- *
23
- * Used for file existence check
24
- */
25
- export interface MarkdownLink {
26
- raw: string;
27
- relative: string;
28
- absolute: string;
29
- }
30
- /**
31
- * The `env` object to be passed to markdown-it render function
32
- *
33
- * Input some meta data for markdown file parsing and rendering
34
- *
35
- * Output some resources from the markdown file
36
- */
37
- export interface MarkdownEnv {
38
- /**
39
- * Base / publicPath of current site
40
- */
41
- base?: string;
42
- /**
43
- * Relative file path of the markdown file
44
- */
45
- filePathRelative?: string | null;
46
- /**
47
- * Headers that extracted by extractHeadersPlugin
48
- */
49
- headers?: MarkdownHeader[];
50
- /**
51
- * Hoisted tags that extracted by hoistTagsPlugin
52
- */
53
- hoistedTags?: string[];
54
- /**
55
- * Links that extracted by linksPlugin
56
- */
57
- links?: MarkdownLink[];
58
- }
package/lib/types.js DELETED
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,3 +0,0 @@
1
- export * from './parseEmoji';
2
- export * from './resolveHeadersFromTokens';
3
- export * from './slugify';
@@ -1,15 +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
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
- }) : (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- o[k2] = m[k];
8
- }));
9
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
- };
12
- Object.defineProperty(exports, "__esModule", { value: true });
13
- __exportStar(require("./parseEmoji"), exports);
14
- __exportStar(require("./resolveHeadersFromTokens"), exports);
15
- __exportStar(require("./slugify"), exports);
@@ -1 +0,0 @@
1
- export declare const parseEmoji: (str: string) => string;
@@ -1,6 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parseEmoji = void 0;
4
- const emojiData = require("markdown-it-emoji/lib/data/full.json");
5
- const parseEmoji = (str) => str.replace(/:(.+?):/g, (placeholder, key) => emojiData[key] || placeholder);
6
- exports.parseEmoji = parseEmoji;
@@ -1,11 +0,0 @@
1
- import * as Token from 'markdown-it/lib/token';
2
- import { MarkdownHeader } from '../types';
3
- /**
4
- * Resolve headers from markdown-it tokens
5
- */
6
- export declare const resolveHeadersFromTokens: (tokens: Token[], { level, allowHtml, slugify, format, }: {
7
- level: number[];
8
- allowHtml: boolean;
9
- slugify: (str: string) => string;
10
- format?: ((str: string) => string) | undefined;
11
- }) => MarkdownHeader[];
@@ -1,81 +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
- /**
6
- * Resolve headers from markdown-it tokens
7
- */
8
- const resolveHeadersFromTokens = (tokens, { level, allowHtml, slugify, format, }) => {
9
- // store the result of headers
10
- const headers = [];
11
- // a temp headers stack for generating the headers tree
12
- const stack = [];
13
- // push a header to the headers tree
14
- const push = (header) => {
15
- while (stack.length !== 0 && header.level <= stack[0].level) {
16
- stack.shift();
17
- }
18
- if (stack.length === 0) {
19
- headers.push(header);
20
- stack.push(header);
21
- }
22
- else {
23
- stack[0].children.push(header);
24
- stack.unshift(header);
25
- }
26
- };
27
- tokens.forEach((_, idx) => {
28
- var _a, _b;
29
- const token = tokens[idx];
30
- // if the token type is not matched, skip
31
- if ((token === null || token === void 0 ? void 0 : 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
- // children of the next token contains the parsed result of the heading title
47
- const nextTokenChildren = (_a = nextToken.children) !== null && _a !== void 0 ? _a : [];
48
- // filter tokens for generating heading title
49
- // 'text' and 'code_inline' should be escaped to avoid being treated as html
50
- // 'emoji' and 'html_inline' should be used directly
51
- const titleTokenTypes = ['text', 'emoji', 'code_inline'];
52
- // include 'html_inline' or not
53
- if (allowHtml) {
54
- titleTokenTypes.push('html_inline');
55
- }
56
- const titleTokens = nextTokenChildren.filter((item) => titleTokenTypes.includes(item.type));
57
- // get title from tokens
58
- const title = titleTokens
59
- .reduce((result, item) => {
60
- // escape content of 'code_inline' and 'text'
61
- if (item.type === 'code_inline' || item.type === 'text') {
62
- return `${result}${shared_1.htmlEscape(item.content)}`;
63
- }
64
- // keep the content of 'emoji' and 'html_inline'
65
- return `${result}${item.content}`;
66
- }, '')
67
- .trim();
68
- // the id of the heading anchor is the slugify result of markdown-it-anchor
69
- // if the id does not exist, slugify the title ourselves
70
- const slug = (_b = token.attrGet('id')) !== null && _b !== void 0 ? _b : slugify(title);
71
- // push the header to tree
72
- push({
73
- level: headerLevel,
74
- title: shared_1.isFunction(format) ? format(title) : title,
75
- slug,
76
- children: [],
77
- });
78
- });
79
- return headers;
80
- };
81
- exports.resolveHeadersFromTokens = resolveHeadersFromTokens;
@@ -1 +0,0 @@
1
- export declare const slugify: (str: string) => string;
@@ -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;