@vuepress/markdown 2.0.0-beta.25 → 2.0.0-beta.32

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.
@@ -1,4 +1,3 @@
1
- import * as anchorPlugin from 'markdown-it-anchor';
2
- import type { AnchorOptions } from 'markdown-it-anchor';
3
- export declare type AnchorPluginOptions = AnchorOptions;
1
+ import anchorPlugin from 'markdown-it-anchor';
2
+ export declare type AnchorPluginOptions = anchorPlugin.AnchorOptions;
4
3
  export { anchorPlugin };
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.anchorPlugin = void 0;
4
- const anchorPlugin = require("markdown-it-anchor");
5
- exports.anchorPlugin = anchorPlugin;
4
+ const markdown_it_anchor_1 = require("markdown-it-anchor");
5
+ exports.anchorPlugin = markdown_it_anchor_1.default;
@@ -14,14 +14,14 @@ const assetsPlugin = (md, { relativePathPrefix = '@source' } = {}) => {
14
14
  const link = token.attrGet('src');
15
15
  if (link) {
16
16
  // replace the original link with resolved link
17
- token.attrSet('src', resolveLink_1.resolveLink(link, relativePathPrefix, env));
17
+ token.attrSet('src', (0, resolveLink_1.resolveLink)(link, relativePathPrefix, env));
18
18
  }
19
19
  return rawImageRule(tokens, idx, options, env, self);
20
20
  };
21
21
  // wrap raw html renderer rule
22
22
  const createHtmlRule = (rawHtmlRule) => (tokens, idx, options, env, self) => {
23
23
  // replace the original link with resolved link
24
- tokens[idx].content = tokens[idx].content.replace(/^( *<img\b.*src=")([^"]*)(")/s, (_, prefix, link, suffix) => `${prefix}${resolveLink_1.resolveLink(link, relativePathPrefix, env)}${suffix}`);
24
+ tokens[idx].content = tokens[idx].content.replace(/^( *<img\b.*src=")([^"]*)(")/s, (_, prefix, link, suffix) => `${prefix}${(0, resolveLink_1.resolveLink)(link, relativePathPrefix, env)}${suffix}`);
25
25
  return rawHtmlRule(tokens, idx, options, env, self);
26
26
  };
27
27
  const rawHtmlBlockRule = md.renderer.rules.html_block;
@@ -5,7 +5,7 @@ const utils_1 = require("@vuepress/utils");
5
5
  const mdurl_1 = require("mdurl");
6
6
  const resolveLink = (link, relativePathPrefix, env) => {
7
7
  // decode link to ensure bundler can find the file correctly
8
- let resolvedLink = mdurl_1.decode(link);
8
+ let resolvedLink = (0, mdurl_1.decode)(link);
9
9
  // if the link is relative path, and the `env.filePathRelative` exists
10
10
  // add `@source` alias to the link
11
11
  if (/^\.{1,2}\//.test(link) && env.filePathRelative) {
@@ -16,7 +16,7 @@ const codePlugin = (md, { highlightLines = true, lineNumbers = true, preWrapper
16
16
  // get token info
17
17
  const info = token.info ? md.utils.unescapeAll(token.info).trim() : '';
18
18
  // resolve language from token info
19
- const language = resolveLanguage_1.resolveLanguage(info);
19
+ const language = (0, resolveLanguage_1.resolveLanguage)(info);
20
20
  const languageClass = `${options.langPrefix}${language.name}`;
21
21
  // try to get highlighted code
22
22
  const code = ((_a = options.highlight) === null || _a === void 0 ? void 0 : _a.call(options, token.content, language.name, '')) ||
@@ -26,7 +26,7 @@ const codePlugin = (md, { highlightLines = true, lineNumbers = true, preWrapper
26
26
  ? code
27
27
  : `<pre class="${languageClass}"><code>${code}</code></pre>`;
28
28
  // resolve v-pre mark from token info
29
- const useVPre = (_b = resolveVPre_1.resolveVPre(info)) !== null && _b !== void 0 ? _b : vPre;
29
+ const useVPre = (_b = (0, resolveVPre_1.resolveVPre)(info)) !== null && _b !== void 0 ? _b : vPre;
30
30
  if (useVPre) {
31
31
  result = `<pre v-pre${result.slice('<pre'.length)}`;
32
32
  }
@@ -38,13 +38,13 @@ const codePlugin = (md, { highlightLines = true, lineNumbers = true, preWrapper
38
38
  const lines = code.split('\n').slice(0, -1);
39
39
  // resolve highlight line ranges from token info
40
40
  const highlightLinesRanges = highlightLines
41
- ? resolveHighlightLines_1.resolveHighlightLines(info)
41
+ ? (0, resolveHighlightLines_1.resolveHighlightLines)(info)
42
42
  : null;
43
43
  // generate highlight lines
44
44
  if (highlightLinesRanges) {
45
45
  const highlightLinesCode = lines
46
46
  .map((_, index) => {
47
- if (resolveHighlightLines_1.isHighlightLine(index + 1, highlightLinesRanges)) {
47
+ if ((0, resolveHighlightLines_1.isHighlightLine)(index + 1, highlightLinesRanges)) {
48
48
  return '<div class="highlight-line">&nbsp;</div>';
49
49
  }
50
50
  return '<br>';
@@ -53,7 +53,7 @@ const codePlugin = (md, { highlightLines = true, lineNumbers = true, preWrapper
53
53
  result = `${result}<div class="highlight-lines">${highlightLinesCode}</div>`;
54
54
  }
55
55
  // resolve line-numbers mark from token info
56
- const useLineNumbers = (_c = resolveLineNumbers_1.resolveLineNumbers(info)) !== null && _c !== void 0 ? _c : (typeof lineNumbers === 'number'
56
+ const useLineNumbers = (_c = (0, resolveLineNumbers_1.resolveLineNumbers)(info)) !== null && _c !== void 0 ? _c : (typeof lineNumbers === 'number'
57
57
  ? lines.length >= lineNumbers
58
58
  : lineNumbers);
59
59
  // generate line numbers
@@ -12,7 +12,7 @@ const extractHeadersPlugin = (md, { level = [2, 3], slugify = utils_1.slugify, f
12
12
  // push the rule to the end of the chain
13
13
  // resolve headers from the parsed tokens
14
14
  md.core.ruler.push('resolveExtractHeaders', (state) => {
15
- headers = utils_1.resolveHeadersFromTokens(state.tokens, {
15
+ headers = (0, utils_1.resolveHeadersFromTokens)(state.tokens, {
16
16
  level,
17
17
  allowHtml: false,
18
18
  escapeText: false,
@@ -12,7 +12,7 @@ const extractTitlePlugin = (md) => {
12
12
  md.core.ruler.push('resolveExtractTitle', (state) => {
13
13
  const tokenIdx = state.tokens.findIndex((token) => token.tag === 'h1');
14
14
  if (tokenIdx > -1) {
15
- title = utils_1.resolveTitleFromToken(state.tokens[tokenIdx + 1], {
15
+ title = (0, utils_1.resolveTitleFromToken)(state.tokens[tokenIdx + 1], {
16
16
  escapeText: false,
17
17
  allowHtml: false,
18
18
  });
@@ -1,3 +1,3 @@
1
1
  import type { RuleBlock } from 'markdown-it/lib/parser_block';
2
2
  import type { ImportCodePluginOptions } from './importCodePlugin';
3
- export declare const createImportCodeBlockRule: ({ handleImportPath, }: ImportCodePluginOptions) => RuleBlock;
3
+ export declare const createImportCodeBlockRule: ({ handleImportPath }: ImportCodePluginOptions) => RuleBlock;
@@ -8,7 +8,7 @@ const MIN_LENGTH = 9;
8
8
  const START_CODES = [64, 91, 99, 111, 100, 101];
9
9
  // regexp to match the import syntax
10
10
  const SYNTAX_RE = /^@\[code(?:{(?:(\d+)?-(\d+)?)})?(?: ([^\]]+))?\]\(([^)]*)\)/;
11
- const createImportCodeBlockRule = ({ handleImportPath = (str) => str, }) => (state, startLine, endLine, silent) => {
11
+ const createImportCodeBlockRule = ({ handleImportPath = (str) => str }) => (state, startLine, endLine, silent) => {
12
12
  // if it's indented more than 3 spaces, it should be a code block
13
13
  /* istanbul ignore if */
14
14
  if (state.sCount[startLine] - state.blkIndent >= 4) {
@@ -5,14 +5,14 @@ const createImportCodeBlockRule_1 = require("./createImportCodeBlockRule");
5
5
  const resolveImportCode_1 = require("./resolveImportCode");
6
6
  const importCodePlugin = (md, options = {}) => {
7
7
  // add import_code block rule
8
- md.block.ruler.before('fence', 'import_code', createImportCodeBlockRule_1.createImportCodeBlockRule(options), {
8
+ md.block.ruler.before('fence', 'import_code', (0, createImportCodeBlockRule_1.createImportCodeBlockRule)(options), {
9
9
  alt: ['paragraph', 'reference', 'blockquote', 'list'],
10
10
  });
11
11
  // add import_code renderer rule
12
12
  md.renderer.rules.import_code = (tokens, idx, options, env, slf) => {
13
13
  const token = tokens[idx];
14
14
  // use imported code as token content
15
- const { importFilePath, importCode } = resolveImportCode_1.resolveImportCode(token.meta, env);
15
+ const { importFilePath, importCode } = (0, resolveImportCode_1.resolveImportCode)(token.meta, env);
16
16
  token.content = importCode;
17
17
  // extract imported files to env
18
18
  if (importFilePath) {
@@ -18,12 +18,6 @@ export interface LinksPluginOptions {
18
18
  * ```
19
19
  */
20
20
  externalAttrs?: Record<string, string>;
21
- /**
22
- * Whether to render an outbound icon to external links
23
- *
24
- * @default true
25
- */
26
- externalIcon?: boolean;
27
21
  }
28
22
  /**
29
23
  * Process links in markdown file
@@ -10,7 +10,6 @@ const resolvePaths_1 = require("./resolvePaths");
10
10
  * - external links: add extra attrs and external icon
11
11
  */
12
12
  const linksPlugin = (md, options = {}) => {
13
- var _a;
14
13
  // tag of internal links
15
14
  const internalTag = options.internalTag || 'RouterLink';
16
15
  // attrs that going to be added to external links
@@ -19,12 +18,8 @@ const linksPlugin = (md, options = {}) => {
19
18
  rel: 'noopener noreferrer',
20
19
  ...options.externalAttrs,
21
20
  };
22
- // external icon
23
- const externalIcon = (_a = options.externalIcon) !== null && _a !== void 0 ? _a : true;
24
21
  let hasOpenInternalLink = false;
25
- let hasOpenExternalLink = false;
26
22
  const handleLinkOpen = (tokens, idx, env) => {
27
- var _a;
28
23
  // get current token
29
24
  const token = tokens[idx];
30
25
  // get `href` attr index
@@ -38,78 +33,64 @@ const linksPlugin = (md, options = {}) => {
38
33
  const hrefAttr = token.attrs[hrefIndex];
39
34
  const hrefLink = hrefAttr[1];
40
35
  // get `base` and `filePathRelative` from `env`
41
- const { base = '/', filePathRelative = null, frontmatter = {} } = env;
36
+ const { base = '/', filePathRelative = null } = env;
42
37
  // check if a link is an external link
43
- if (shared_1.isLinkExternal(hrefLink, base)) {
38
+ if ((0, shared_1.isLinkExternal)(hrefLink, base)) {
44
39
  // set `externalAttrs` to current token
45
40
  Object.entries(externalAttrs).forEach(([key, val]) => token.attrSet(key, val));
46
- // check if we should render external icon
47
- if (
48
- // frontmatter should override plugin option
49
- ((_a = frontmatter.externalIcon) !== null && _a !== void 0 ? _a : externalIcon) &&
50
- // only when an external link has `target="_blank"`
51
- // should we render external icon
52
- externalAttrs.target === '_blank') {
53
- hasOpenExternalLink = true;
54
- }
55
41
  return;
56
42
  }
57
43
  // check if a link is an internal link
58
44
  const internalLinkMatch = hrefLink.match(/^((?:.*)(?:\/|\.md|\.html))(#.*)?$/);
59
- if (internalLinkMatch) {
60
- // convert
61
- // <a href="hrefLink">
62
- // to
63
- // <RouterLink to="toProp">
64
- // notice that the path and hash are encoded by markdown-it
65
- const rawPath = internalLinkMatch[1];
66
- const rawHash = internalLinkMatch[2] || '';
67
- // resolve relative and absolute path
68
- const { relativePath, absolutePath } = resolvePaths_1.resolvePaths(rawPath, base, filePathRelative);
69
- // normalize markdown file path to route path
70
- //
71
- // we are removing the `base` from absolute path because it should not be
72
- // passed to `<RouterLink>`
73
- //
74
- // '/foo/index.md' => '/foo/'
75
- // '/foo/bar.md' => '/foo/bar.html'
76
- const normalizedPath = absolutePath
77
- .replace(new RegExp(`^${base}`), '/')
78
- .replace(/(^|\/)(README|index).md$/i, '$1')
79
- .replace(/\.md$/, '.html');
80
- if (internalTag === 'RouterLink') {
81
- // convert starting tag of internal link to `<RouterLink>`
82
- token.tag = internalTag;
83
- // replace the original `href` attr with `to` attr
84
- hrefAttr[0] = 'to';
85
- // set `hasOpenInternalLink` to modify the ending tag
86
- hasOpenInternalLink = true;
87
- }
88
- hrefAttr[1] = `${normalizedPath}${rawHash}`;
89
- // extract internal links for file / page existence check
90
- const links = env.links || (env.links = []);
91
- links.push({
92
- raw: hrefLink,
93
- relative: relativePath,
94
- absolute: absolutePath,
95
- });
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;
96
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
+ });
97
84
  };
98
85
  md.renderer.rules.link_open = (tokens, idx, options, env, self) => {
99
86
  handleLinkOpen(tokens, idx, env);
100
87
  return self.renderToken(tokens, idx, options);
101
88
  };
102
89
  md.renderer.rules.link_close = (tokens, idx, options, env, self) => {
103
- const token = tokens[idx];
104
- // add external icon before ending tag of external link
105
- if (hasOpenExternalLink) {
106
- hasOpenExternalLink = false;
107
- return '<OutboundLink/>' + self.renderToken(tokens, idx, options);
108
- }
109
90
  // convert ending tag of internal link
110
91
  if (hasOpenInternalLink) {
111
92
  hasOpenInternalLink = false;
112
- token.tag = internalTag;
93
+ tokens[idx].tag = internalTag;
113
94
  }
114
95
  return self.renderToken(tokens, idx, options);
115
96
  };
@@ -3,12 +3,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createRenderHeaders = void 0;
4
4
  const shared_1 = require("@vuepress/shared");
5
5
  const createRenderHeaders = ({ listTag, listClass, itemClass, linkTag, linkClass, }) => {
6
- const listTagString = shared_1.htmlEscape(listTag);
7
- const listClassString = listClass ? ` class="${shared_1.htmlEscape(listClass)}"` : '';
6
+ const listTagString = (0, shared_1.htmlEscape)(listTag);
7
+ const listClassString = listClass ? ` class="${(0, shared_1.htmlEscape)(listClass)}"` : '';
8
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)}` : '';
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
12
  const linkTo = (slug) => linkTag === 'RouterLink' ? ` to="#${slug}"` : ` href="#${slug}"`;
13
13
  const renderHeaders = (headers) => `\
14
14
  <${listTagString}${listClassString}>\
@@ -20,7 +20,7 @@ const tocPlugin = (md, { pattern = /^\[\[toc\]\]$/i, slugify = utils_1.slugify,
20
20
  // push the rule to the end of the chain
21
21
  // resolve headers from the parsed tokens
22
22
  md.core.ruler.push('resolveTocHeaders', (state) => {
23
- headers = utils_1.resolveHeadersFromTokens(state.tokens, {
23
+ headers = (0, utils_1.resolveHeadersFromTokens)(state.tokens, {
24
24
  level,
25
25
  allowHtml: true,
26
26
  escapeText: true,
@@ -30,14 +30,14 @@ const tocPlugin = (md, { pattern = /^\[\[toc\]\]$/i, slugify = utils_1.slugify,
30
30
  return true;
31
31
  });
32
32
  // add toc syntax as a block rule
33
- md.block.ruler.before('heading', 'toc', createTocBlockRule_1.createTocBlockRule({
33
+ md.block.ruler.before('heading', 'toc', (0, createTocBlockRule_1.createTocBlockRule)({
34
34
  pattern,
35
35
  containerTag,
36
36
  containerClass,
37
37
  }), {
38
38
  alt: ['paragraph', 'reference', 'blockquote'],
39
39
  });
40
- const renderHeaders = createRenderHeaders_1.createRenderHeaders({
40
+ const renderHeaders = (0, createRenderHeaders_1.createRenderHeaders)({
41
41
  listTag,
42
42
  listClass,
43
43
  itemClass,
package/lib/types.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { PageFrontmatter, PageHeader } from '@vuepress/shared';
2
- import * as MarkdownIt from 'markdown-it';
2
+ import type * as MarkdownIt from 'markdown-it';
3
3
  import type { AnchorPluginOptions, AssetsPluginOptions, CodePluginOptions, EmojiPluginOptions, ExtractHeadersPluginOptions, HoistTagsPluginOptions, ImportCodePluginOptions, LinksPluginOptions, TocPluginOptions } from './plugins';
4
4
  export declare type Markdown = MarkdownIt;
5
5
  export interface MarkdownOptions extends MarkdownIt.Options {
@@ -1,4 +1,4 @@
1
- import * as Token from 'markdown-it/lib/token';
1
+ import type * as Token from 'markdown-it/lib/token';
2
2
  import type { MarkdownHeader } from '../types';
3
3
  /**
4
4
  * Resolve headers from markdown-it tokens
@@ -44,7 +44,7 @@ const resolveHeadersFromTokens = (tokens, { level, allowHtml, escapeText, slugif
44
44
  if (!nextToken) {
45
45
  return;
46
46
  }
47
- const title = resolveTitleFromToken_1.resolveTitleFromToken(nextToken, {
47
+ const title = (0, resolveTitleFromToken_1.resolveTitleFromToken)(nextToken, {
48
48
  allowHtml,
49
49
  escapeText,
50
50
  });
@@ -54,7 +54,7 @@ const resolveHeadersFromTokens = (tokens, { level, allowHtml, escapeText, slugif
54
54
  // push the header to tree
55
55
  push({
56
56
  level: headerLevel,
57
- title: shared_1.isFunction(format) ? format(title) : title,
57
+ title: (0, shared_1.isFunction)(format) ? format(title) : title,
58
58
  slug,
59
59
  children: [],
60
60
  });
@@ -1,4 +1,4 @@
1
- import * as Token from 'markdown-it/lib/token';
1
+ import type * as Token from 'markdown-it/lib/token';
2
2
  /**
3
3
  * Resolve header title from markdown-it token
4
4
  *
@@ -30,7 +30,7 @@ const resolveTitleFromToken = (token, { allowHtml, escapeText, }) => {
30
30
  if (escapeText) {
31
31
  // escape the content of 'code_inline' and 'text'
32
32
  if (item.type === 'code_inline' || item.type === 'text') {
33
- return `${result}${shared_1.htmlEscape(item.content)}`;
33
+ return `${result}${(0, shared_1.htmlEscape)(item.content)}`;
34
34
  }
35
35
  }
36
36
  // keep the content of 'emoji' and 'html_inline'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vuepress/markdown",
3
- "version": "2.0.0-beta.25",
3
+ "version": "2.0.0-beta.32",
4
4
  "description": "Markdown package of VuePress",
5
5
  "keywords": [
6
6
  "vuepress",
@@ -26,16 +26,16 @@
26
26
  "clean": "rimraf lib *.tsbuildinfo"
27
27
  },
28
28
  "dependencies": {
29
- "@types/markdown-it": "^12.2.0",
30
- "@vuepress/shared": "2.0.0-beta.25",
31
- "@vuepress/utils": "2.0.0-beta.25",
29
+ "@types/markdown-it": "^12.2.3",
30
+ "@vuepress/shared": "2.0.0-beta.32",
31
+ "@vuepress/utils": "2.0.0-beta.32",
32
32
  "markdown-it": "^12.2.0",
33
- "markdown-it-anchor": "^8.1.2",
33
+ "markdown-it-anchor": "^8.4.1",
34
34
  "markdown-it-emoji": "^2.0.0",
35
35
  "mdurl": "^1.0.1"
36
36
  },
37
37
  "publishConfig": {
38
38
  "access": "public"
39
39
  },
40
- "gitHead": "76ce5e52b07de75cf1f40a57ef3b6a682e44fce7"
40
+ "gitHead": "8ffa71313607fe78f3956e3ccb886fcae0ddf5e9"
41
41
  }