@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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vuepress/markdown",
3
- "version": "2.0.0-beta.48",
3
+ "version": "2.0.0-beta.50-pre",
4
4
  "description": "Markdown package of VuePress",
5
5
  "keywords": [
6
6
  "vuepress",
@@ -16,25 +16,56 @@
16
16
  },
17
17
  "license": "MIT",
18
18
  "author": "meteorlxy",
19
- "main": "lib/index.js",
20
- "types": "lib/index.d.ts",
19
+ "type": "module",
20
+ "exports": {
21
+ ".": "./dist/index.js",
22
+ "./package.json": "./package.json"
23
+ },
24
+ "main": "./dist/index.js",
25
+ "types": "./dist/index.d.ts",
21
26
  "files": [
22
- "lib"
27
+ "./dist"
23
28
  ],
24
29
  "dependencies": {
30
+ "@mdit-vue/plugin-component": "^0.9.0",
31
+ "@mdit-vue/plugin-frontmatter": "^0.9.1",
32
+ "@mdit-vue/plugin-headers": "^0.9.1",
33
+ "@mdit-vue/plugin-sfc": "^0.9.1",
34
+ "@mdit-vue/plugin-title": "^0.9.1",
35
+ "@mdit-vue/plugin-toc": "^0.9.1",
36
+ "@mdit-vue/shared": "^0.9.1",
37
+ "@mdit-vue/types": "^0.9.0",
25
38
  "@types/markdown-it": "^12.2.3",
26
- "@vuepress/shared": "2.0.0-beta.48",
27
- "@vuepress/utils": "2.0.0-beta.48",
39
+ "@types/markdown-it-emoji": "^2.0.2",
40
+ "@vuepress/shared": "2.0.0-beta.50-pre",
41
+ "@vuepress/utils": "2.0.0-beta.50-pre",
28
42
  "markdown-it": "^13.0.1",
29
43
  "markdown-it-anchor": "^8.6.4",
30
44
  "markdown-it-emoji": "^2.0.2",
31
45
  "mdurl": "^1.0.1"
32
46
  },
47
+ "devDependencies": {
48
+ "@types/mdurl": "^1.0.2"
49
+ },
33
50
  "publishConfig": {
34
51
  "access": "public"
35
52
  },
53
+ "tsup": {
54
+ "clean": true,
55
+ "dts": "./src/index.ts",
56
+ "entry": [
57
+ "./src/index.ts"
58
+ ],
59
+ "format": [
60
+ "esm"
61
+ ],
62
+ "outDir": "./dist",
63
+ "sourcemap": false,
64
+ "target": "es2020",
65
+ "tsconfig": "../tsconfig.dts.json"
66
+ },
36
67
  "scripts": {
37
- "build": "tsc -b tsconfig.build.json",
38
- "clean": "rimraf lib *.tsbuildinfo"
68
+ "build": "tsup",
69
+ "clean": "rimraf dist"
39
70
  }
40
71
  }
package/lib/index.d.ts DELETED
@@ -1,4 +0,0 @@
1
- export * from './markdown';
2
- export * from './plugins';
3
- export * from './types';
4
- export * from './utils';
package/lib/index.js DELETED
@@ -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("./markdown"), exports);
18
- __exportStar(require("./plugins"), exports);
19
- __exportStar(require("./types"), exports);
20
- __exportStar(require("./utils"), exports);
package/lib/markdown.d.ts DELETED
@@ -1,5 +0,0 @@
1
- import type { Markdown, MarkdownOptions } from './types';
2
- /**
3
- * Create vuepress customized markdown-it instance
4
- */
5
- export declare const createMarkdown: ({ anchor, assets, code, customComponent, emoji, extractHeaders, extractTitle, hoistTags, importCode, links, slugify, toc, ...markdownItOptions }?: MarkdownOptions) => Markdown;
package/lib/markdown.js DELETED
@@ -1,88 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createMarkdown = void 0;
4
- const MarkdownIt = require("markdown-it");
5
- const plugins_1 = require("./plugins");
6
- const utils_1 = require("./utils");
7
- /**
8
- * Create vuepress customized markdown-it instance
9
- */
10
- const createMarkdown = ({ anchor, assets, code, customComponent, emoji, extractHeaders, extractTitle, hoistTags, importCode, links, slugify = utils_1.vuepressSlugify, toc, ...markdownItOptions } = {}) => {
11
- // create raw markdown-it instance
12
- const md = MarkdownIt({
13
- ...markdownItOptions,
14
- // should always enable html option
15
- html: true,
16
- });
17
- // =====================================================
18
- // following plugins push rules to the end of chain, so
19
- // the order to use them is important
20
- // parse emoji
21
- if (emoji !== false) {
22
- md.use(plugins_1.emojiPlugin, emoji);
23
- }
24
- // add anchor to headers
25
- if (anchor !== false) {
26
- md.use(plugins_1.anchorPlugin, {
27
- level: [1, 2, 3, 4, 5, 6],
28
- slugify,
29
- permalink: plugins_1.anchorPlugin.permalink.ariaHidden({
30
- class: 'header-anchor',
31
- symbol: '#',
32
- space: true,
33
- placement: 'before',
34
- }),
35
- ...anchor,
36
- });
37
- }
38
- // allow toc syntax
39
- if (toc !== false) {
40
- md.use(plugins_1.tocPlugin, {
41
- level: [2, 3],
42
- slugify,
43
- linkTag: 'RouterLink',
44
- ...toc,
45
- });
46
- }
47
- // extract headers into env
48
- if (extractHeaders !== false) {
49
- md.use(plugins_1.extractHeadersPlugin, {
50
- level: [2, 3],
51
- slugify,
52
- ...extractHeaders,
53
- });
54
- }
55
- // extract title into env
56
- if (extractTitle !== false) {
57
- md.use(plugins_1.extractTitlePlugin);
58
- }
59
- // =====================================================
60
- // following plugins modify or replace the rule in place
61
- // and have no conflicts, so the order is not important
62
- // treat unknown html tags as custom components
63
- if (customComponent !== false) {
64
- md.use(plugins_1.customComponentPlugin);
65
- }
66
- // replace relative link of assets with absolute link
67
- if (assets !== false) {
68
- md.use(plugins_1.assetsPlugin, assets);
69
- }
70
- // hoist vue SFC blocks and extract them into env
71
- if (hoistTags !== false) {
72
- md.use(plugins_1.hoistTagsPlugin, hoistTags);
73
- }
74
- // process external and internal links
75
- if (links !== false) {
76
- md.use(plugins_1.linksPlugin, links);
77
- }
78
- // process code fence
79
- if (code !== false) {
80
- md.use(plugins_1.codePlugin, code);
81
- }
82
- // handle import_code syntax
83
- if (importCode !== false) {
84
- md.use(plugins_1.importCodePlugin, importCode);
85
- }
86
- return md;
87
- };
88
- exports.createMarkdown = createMarkdown;
@@ -1,3 +0,0 @@
1
- import anchorPlugin from 'markdown-it-anchor';
2
- export declare type AnchorPluginOptions = anchorPlugin.AnchorOptions;
3
- export { anchorPlugin };
@@ -1,5 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.anchorPlugin = void 0;
4
- const markdown_it_anchor_1 = require("markdown-it-anchor");
5
- exports.anchorPlugin = markdown_it_anchor_1.default;
@@ -1,11 +0,0 @@
1
- import type { PluginWithOptions } from 'markdown-it';
2
- export interface AssetsPluginOptions {
3
- /**
4
- * Prefix to add to relative assets links
5
- */
6
- relativePathPrefix?: string;
7
- }
8
- /**
9
- * Plugin to handle assets links
10
- */
11
- export declare const assetsPlugin: PluginWithOptions<AssetsPluginOptions>;
@@ -1,41 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.assetsPlugin = void 0;
4
- const resolveLink_1 = require("./resolveLink");
5
- /**
6
- * Plugin to handle assets links
7
- */
8
- const assetsPlugin = (md, { relativePathPrefix = '@source' } = {}) => {
9
- // wrap raw image renderer rule
10
- const rawImageRule = md.renderer.rules.image;
11
- md.renderer.rules.image = (tokens, idx, options, env, self) => {
12
- const token = tokens[idx];
13
- // get the image link
14
- const link = token.attrGet('src');
15
- if (link) {
16
- // replace the original link with resolved link
17
- token.attrSet('src', (0, resolveLink_1.resolveLink)(link, relativePathPrefix, env));
18
- }
19
- return rawImageRule(tokens, idx, options, env, self);
20
- };
21
- // wrap raw html renderer rule
22
- const createHtmlRule = (rawHtmlRule) => (tokens, idx, options, env, self) => {
23
- // replace the original link with resolved link
24
- tokens[idx].content = tokens[idx].content
25
- // handle src
26
- .replace(/(<img\b.*?src=")([^"]*)(")/gs, (_, prefix, src, suffix) => `${prefix}${(0, resolveLink_1.resolveLink)(src.trim(), relativePathPrefix, env)}${suffix}`)
27
- // handle srcset
28
- .replace(/(<img\b.*?srcset=")([^"]*)(")/gs, (_, prefix, srcset, suffix) => `${prefix}${srcset
29
- .split(',')
30
- .map((item) => item
31
- .trim()
32
- .replace(/^([^ ]*?)([ \n].*)?$/, (_, url, descriptor = '') => `${(0, resolveLink_1.resolveLink)(url.trim(), relativePathPrefix, env)}${descriptor.replace(/[ \n]+/g, ' ').trimEnd()}`))
33
- .join(', ')}${suffix}`);
34
- return rawHtmlRule(tokens, idx, options, env, self);
35
- };
36
- const rawHtmlBlockRule = md.renderer.rules.html_block;
37
- const rawHtmlInlineRule = md.renderer.rules.html_inline;
38
- md.renderer.rules.html_block = createHtmlRule(rawHtmlBlockRule);
39
- md.renderer.rules.html_inline = createHtmlRule(rawHtmlInlineRule);
40
- };
41
- exports.assetsPlugin = assetsPlugin;
@@ -1,2 +0,0 @@
1
- export * from './assetsPlugin';
2
- export * from './resolveLink';
@@ -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("./assetsPlugin"), exports);
18
- __exportStar(require("./resolveLink"), exports);
@@ -1,2 +0,0 @@
1
- import type { MarkdownEnv } from '../../types';
2
- export declare const resolveLink: (link: string, relativePathPrefix: string, env: MarkdownEnv) => string;
@@ -1,16 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.resolveLink = void 0;
4
- const utils_1 = require("@vuepress/utils");
5
- const mdurl_1 = require("mdurl");
6
- const resolveLink = (link, relativePathPrefix, env) => {
7
- // decode link to ensure bundler can find the file correctly
8
- let resolvedLink = (0, mdurl_1.decode)(link);
9
- // if the link is relative path, and the `env.filePathRelative` exists
10
- // add `@source` alias to the link
11
- if (/^\.{1,2}\//.test(link) && env.filePathRelative) {
12
- resolvedLink = `${relativePathPrefix}/${utils_1.path.join(utils_1.path.dirname(env.filePathRelative), resolvedLink)}`;
13
- }
14
- return resolvedLink;
15
- };
16
- exports.resolveLink = resolveLink;
@@ -1,40 +0,0 @@
1
- import type { PluginWithOptions } from 'markdown-it';
2
- export interface CodePluginOptions {
3
- /**
4
- * Enable highlight lines or not
5
- */
6
- highlightLines?: boolean;
7
- /**
8
- * Enable line numbers or not
9
- *
10
- * - A `boolean` value is to enable line numbers or not.
11
- * - A `number` value is the minimum number of lines to enable line numbers
12
- */
13
- lineNumbers?: boolean | number;
14
- /**
15
- * Wrap the `<pre>` tag with an extra `<div>` or not. Do not disable it unless you
16
- * understand what's it for
17
- *
18
- * - Required for `highlightLines`
19
- * - Required for `lineNumbers`
20
- * - Required for language display of default theme
21
- */
22
- preWrapper?: boolean;
23
- /**
24
- * Add `v-pre` directive or not
25
- */
26
- vPre?: {
27
- /**
28
- * Add `v-pre` directive to `<pre>` tag of code block or not
29
- */
30
- block?: boolean;
31
- /**
32
- * Add `v-pre` directive to `<code>` tag of inline code or not
33
- */
34
- inline?: boolean;
35
- };
36
- }
37
- /**
38
- * Code plugin
39
- */
40
- export declare const codePlugin: PluginWithOptions<CodePluginOptions>;
@@ -1,78 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.codePlugin = void 0;
4
- const resolveHighlightLines_1 = require("./resolveHighlightLines");
5
- const resolveLanguage_1 = require("./resolveLanguage");
6
- const resolveLineNumbers_1 = require("./resolveLineNumbers");
7
- const resolveVPre_1 = require("./resolveVPre");
8
- /**
9
- * Code plugin
10
- */
11
- const codePlugin = (md, { highlightLines = true, lineNumbers = true, preWrapper = true, vPre: { block: vPreBlock = true, inline: vPreInline = true } = {}, } = {}) => {
12
- // override default fence renderer
13
- md.renderer.rules.fence = (tokens, idx, options, env, slf) => {
14
- const token = tokens[idx];
15
- // get token info
16
- const info = token.info ? md.utils.unescapeAll(token.info).trim() : '';
17
- // resolve language from token info
18
- const language = (0, resolveLanguage_1.resolveLanguage)(info);
19
- const languageClass = `${options.langPrefix}${language.name}`;
20
- // try to get highlighted code
21
- const code = options.highlight?.(token.content, language.name, '') ||
22
- md.utils.escapeHtml(token.content);
23
- // wrap highlighted code with `<pre>` and `<code>`
24
- let result = code.startsWith('<pre')
25
- ? code
26
- : `<pre class="${languageClass}"><code>${code}</code></pre>`;
27
- // resolve v-pre mark from token info
28
- const useVPre = (0, resolveVPre_1.resolveVPre)(info) ?? vPreBlock;
29
- if (useVPre) {
30
- result = `<pre v-pre${result.slice('<pre'.length)}`;
31
- }
32
- // if `preWrapper` is disabled, return directly
33
- if (!preWrapper) {
34
- return result;
35
- }
36
- // code fences always have an ending `\n`, so we should trim the last line
37
- const lines = code.split('\n').slice(0, -1);
38
- // resolve highlight line ranges from token info
39
- const highlightLinesRanges = highlightLines
40
- ? (0, resolveHighlightLines_1.resolveHighlightLines)(info)
41
- : null;
42
- // generate highlight lines
43
- if (highlightLinesRanges) {
44
- const highlightLinesCode = lines
45
- .map((_, index) => {
46
- if ((0, resolveHighlightLines_1.isHighlightLine)(index + 1, highlightLinesRanges)) {
47
- return '<div class="highlight-line">&nbsp;</div>';
48
- }
49
- return '<br>';
50
- })
51
- .join('');
52
- result = `${result}<div class="highlight-lines">${highlightLinesCode}</div>`;
53
- }
54
- // resolve line-numbers mark from token info
55
- const useLineNumbers = (0, resolveLineNumbers_1.resolveLineNumbers)(info) ??
56
- (typeof lineNumbers === 'number'
57
- ? lines.length >= lineNumbers
58
- : lineNumbers);
59
- // generate line numbers
60
- if (useLineNumbers) {
61
- // generate line numbers code
62
- const lineNumbersCode = lines
63
- .map(() => `<div class="line-number"></div>`)
64
- .join('');
65
- result = `${result}<div class="line-numbers" aria-hidden="true">${lineNumbersCode}</div>`;
66
- }
67
- result = `<div class="${languageClass} ext-${language.ext}${useLineNumbers ? ' line-numbers-mode' : ''}">${result}</div>`;
68
- return result;
69
- };
70
- if (vPreInline) {
71
- const rawInlineCodeRule = md.renderer.rules.code_inline;
72
- md.renderer.rules.code_inline = (tokens, idx, options, env, slf) => {
73
- const result = rawInlineCodeRule(tokens, idx, options, env, slf);
74
- return `<code v-pre${result.slice('<code'.length)}`;
75
- };
76
- }
77
- };
78
- exports.codePlugin = codePlugin;
@@ -1,6 +0,0 @@
1
- export * from './codePlugin';
2
- export * from './languages';
3
- export * from './resolveHighlightLines';
4
- export * from './resolveLanguage';
5
- export * from './resolveLineNumbers';
6
- export * from './resolveVPre';
@@ -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("./codePlugin"), exports);
18
- __exportStar(require("./languages"), exports);
19
- __exportStar(require("./resolveHighlightLines"), exports);
20
- __exportStar(require("./resolveLanguage"), exports);
21
- __exportStar(require("./resolveLineNumbers"), exports);
22
- __exportStar(require("./resolveVPre"), exports);
@@ -1,38 +0,0 @@
1
- /**
2
- * Language type for syntax highlight
3
- */
4
- export interface HighlightLanguage {
5
- /**
6
- * Name of the language
7
- *
8
- * The name to be used for the class name,
9
- * e.g. `class="language-typescript"`
10
- */
11
- name: string;
12
- /**
13
- * Extension of the language
14
- *
15
- * The file extension, which will be used for the
16
- * class name, e.g. `class="ext-ts"`
17
- */
18
- ext: string;
19
- /**
20
- * Aliases that point to this language
21
- *
22
- * Do not conflict with other languages
23
- */
24
- aliases: string[];
25
- }
26
- export declare const languageBash: HighlightLanguage;
27
- export declare const languageCsharp: HighlightLanguage;
28
- export declare const languageDocker: HighlightLanguage;
29
- export declare const languageFsharp: HighlightLanguage;
30
- export declare const languageJavascript: HighlightLanguage;
31
- export declare const languageKotlin: HighlightLanguage;
32
- export declare const languageMarkdown: HighlightLanguage;
33
- export declare const languagePython: HighlightLanguage;
34
- export declare const languageRuby: HighlightLanguage;
35
- export declare const languageRust: HighlightLanguage;
36
- export declare const languageStylus: HighlightLanguage;
37
- export declare const languageTypescript: HighlightLanguage;
38
- export declare const languageYaml: HighlightLanguage;
@@ -1,68 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.languageYaml = exports.languageTypescript = exports.languageStylus = exports.languageRust = exports.languageRuby = exports.languagePython = exports.languageMarkdown = exports.languageKotlin = exports.languageJavascript = exports.languageFsharp = exports.languageDocker = exports.languageCsharp = exports.languageBash = void 0;
4
- exports.languageBash = {
5
- name: 'bash',
6
- ext: 'sh',
7
- aliases: ['bash', 'sh', 'shell', 'zsh'],
8
- };
9
- exports.languageCsharp = {
10
- name: 'csharp',
11
- ext: 'cs',
12
- aliases: ['cs', 'csharp'],
13
- };
14
- exports.languageDocker = {
15
- name: 'docker',
16
- ext: 'docker',
17
- aliases: ['docker', 'dockerfile'],
18
- };
19
- exports.languageFsharp = {
20
- name: 'fsharp',
21
- ext: 'fs',
22
- aliases: ['fs', 'fsharp'],
23
- };
24
- exports.languageJavascript = {
25
- name: 'javascript',
26
- ext: 'js',
27
- aliases: ['javascript', 'js'],
28
- };
29
- exports.languageKotlin = {
30
- name: 'kotlin',
31
- ext: 'kt',
32
- aliases: ['kotlin', 'kt'],
33
- };
34
- exports.languageMarkdown = {
35
- name: 'markdown',
36
- ext: 'md',
37
- aliases: ['markdown', 'md'],
38
- };
39
- exports.languagePython = {
40
- name: 'python',
41
- ext: 'py',
42
- aliases: ['py', 'python'],
43
- };
44
- exports.languageRuby = {
45
- name: 'ruby',
46
- ext: 'rb',
47
- aliases: ['rb', 'ruby'],
48
- };
49
- exports.languageRust = {
50
- name: 'rust',
51
- ext: 'rs',
52
- aliases: ['rs', 'rust'],
53
- };
54
- exports.languageStylus = {
55
- name: 'stylus',
56
- ext: 'styl',
57
- aliases: ['styl', 'stylus'],
58
- };
59
- exports.languageTypescript = {
60
- name: 'typescript',
61
- ext: 'ts',
62
- aliases: ['ts', 'typescript'],
63
- };
64
- exports.languageYaml = {
65
- name: 'yaml',
66
- ext: 'yml',
67
- aliases: ['yaml', 'yml'],
68
- };
@@ -1,9 +0,0 @@
1
- export declare type HighlightLinesRange = [number, number];
2
- /**
3
- * Resolve highlight-lines ranges from token info
4
- */
5
- export declare const resolveHighlightLines: (info: string) => HighlightLinesRange[] | null;
6
- /**
7
- * Check if a line number is in ranges
8
- */
9
- export declare const isHighlightLine: (lineNumber: number, ranges: HighlightLinesRange[]) => boolean;
@@ -1,28 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isHighlightLine = exports.resolveHighlightLines = void 0;
4
- /**
5
- * Resolve highlight-lines ranges from token info
6
- */
7
- const resolveHighlightLines = (info) => {
8
- // try to match highlight-lines mark
9
- const match = info.match(/{([\d,-]+)}/);
10
- // no highlight-lines mark, return `null`
11
- if (match === null) {
12
- return null;
13
- }
14
- // resolve lines ranges from the highlight-lines mark
15
- return match[1].split(',').map((item) => {
16
- const range = item.split('-');
17
- if (range.length === 1) {
18
- range.push(range[0]);
19
- }
20
- return range.map((str) => Number.parseInt(str, 10));
21
- });
22
- };
23
- exports.resolveHighlightLines = resolveHighlightLines;
24
- /**
25
- * Check if a line number is in ranges
26
- */
27
- const isHighlightLine = (lineNumber, ranges) => ranges.some(([start, end]) => lineNumber >= start && lineNumber <= end);
28
- exports.isHighlightLine = isHighlightLine;
@@ -1,5 +0,0 @@
1
- import type { HighlightLanguage } from './languages';
2
- /**
3
- * Resolve language for highlight from token info
4
- */
5
- export declare const resolveLanguage: (info: string) => HighlightLanguage;
@@ -1,40 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.resolveLanguage = void 0;
4
- const languages = require("./languages");
5
- /**
6
- * A key-value map to get language info from alias
7
- *
8
- * - key: alias
9
- * - value: language
10
- */
11
- let languagesMap;
12
- /**
13
- * Lazy generate languages map
14
- */
15
- const getLanguagesMap = () => {
16
- if (!languagesMap) {
17
- languagesMap = Object.values(languages).reduce((result, item) => {
18
- item.aliases.forEach((alias) => {
19
- result[alias] = item;
20
- });
21
- return result;
22
- }, {});
23
- }
24
- return languagesMap;
25
- };
26
- /**
27
- * Resolve language for highlight from token info
28
- */
29
- const resolveLanguage = (info) => {
30
- // get user-defined language alias
31
- const alias = info.match(/^([^ :[{]+)/)?.[1] || 'text';
32
- // if the alias does not have a match in the map
33
- // fallback to the alias itself
34
- return (getLanguagesMap()[alias] ?? {
35
- name: alias,
36
- ext: alias,
37
- aliases: [alias],
38
- });
39
- };
40
- exports.resolveLanguage = resolveLanguage;
@@ -1,4 +0,0 @@
1
- /**
2
- * Resolve the `:line-numbers` / `:no-line-numbers` mark from token info
3
- */
4
- export declare const resolveLineNumbers: (info: string) => boolean | null;