@vuepress/markdown 2.0.0-beta.40 → 2.0.0-beta.43

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.
@@ -21,9 +21,18 @@ export interface CodePluginOptions {
21
21
  */
22
22
  preWrapper?: boolean;
23
23
  /**
24
- * Add `v-pre` directive to `<pre>` tag or not
24
+ * Add `v-pre` directive or not
25
25
  */
26
- vPre?: boolean;
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
+ };
27
36
  }
28
37
  /**
29
38
  * Code plugin
@@ -8,10 +8,9 @@ const resolveVPre_1 = require("./resolveVPre");
8
8
  /**
9
9
  * Code plugin
10
10
  */
11
- const codePlugin = (md, { highlightLines = true, lineNumbers = true, preWrapper = true, vPre = true, } = {}) => {
11
+ const codePlugin = (md, { highlightLines = true, lineNumbers = true, preWrapper = true, vPre: { block: vPreBlock = true, inline: vPreInline = true } = {}, } = {}) => {
12
12
  // override default fence renderer
13
13
  md.renderer.rules.fence = (tokens, idx, options, env, slf) => {
14
- var _a, _b, _c;
15
14
  const token = tokens[idx];
16
15
  // get token info
17
16
  const info = token.info ? md.utils.unescapeAll(token.info).trim() : '';
@@ -19,14 +18,14 @@ const codePlugin = (md, { highlightLines = true, lineNumbers = true, preWrapper
19
18
  const language = (0, resolveLanguage_1.resolveLanguage)(info);
20
19
  const languageClass = `${options.langPrefix}${language.name}`;
21
20
  // try to get highlighted code
22
- const code = ((_a = options.highlight) === null || _a === void 0 ? void 0 : _a.call(options, token.content, language.name, '')) ||
21
+ const code = options.highlight?.(token.content, language.name, '') ||
23
22
  md.utils.escapeHtml(token.content);
24
23
  // wrap highlighted code with `<pre>` and `<code>`
25
24
  let result = code.startsWith('<pre')
26
25
  ? code
27
26
  : `<pre class="${languageClass}"><code>${code}</code></pre>`;
28
27
  // resolve v-pre mark from token info
29
- const useVPre = (_b = (0, resolveVPre_1.resolveVPre)(info)) !== null && _b !== void 0 ? _b : vPre;
28
+ const useVPre = (0, resolveVPre_1.resolveVPre)(info) ?? vPreBlock;
30
29
  if (useVPre) {
31
30
  result = `<pre v-pre${result.slice('<pre'.length)}`;
32
31
  }
@@ -53,9 +52,10 @@ const codePlugin = (md, { highlightLines = true, lineNumbers = true, preWrapper
53
52
  result = `${result}<div class="highlight-lines">${highlightLinesCode}</div>`;
54
53
  }
55
54
  // resolve line-numbers mark from token info
56
- const useLineNumbers = (_c = (0, resolveLineNumbers_1.resolveLineNumbers)(info)) !== null && _c !== void 0 ? _c : (typeof lineNumbers === 'number'
57
- ? lines.length >= lineNumbers
58
- : lineNumbers);
55
+ const useLineNumbers = (0, resolveLineNumbers_1.resolveLineNumbers)(info) ??
56
+ (typeof lineNumbers === 'number'
57
+ ? lines.length >= lineNumbers
58
+ : lineNumbers);
59
59
  // generate line numbers
60
60
  if (useLineNumbers) {
61
61
  // generate line numbers code
@@ -67,5 +67,12 @@ const codePlugin = (md, { highlightLines = true, lineNumbers = true, preWrapper
67
67
  result = `<div class="${languageClass} ext-${language.ext}${useLineNumbers ? ' line-numbers-mode' : ''}">${result}</div>`;
68
68
  return result;
69
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
+ }
70
77
  };
71
78
  exports.codePlugin = codePlugin;
@@ -27,12 +27,11 @@ const getLanguagesMap = () => {
27
27
  * Resolve language for highlight from token info
28
28
  */
29
29
  const resolveLanguage = (info) => {
30
- var _a, _b;
31
30
  // get user-defined language alias
32
- const alias = ((_a = info.match(/^([^ :[{]+)/)) === null || _a === void 0 ? void 0 : _a[1]) || 'text';
31
+ const alias = info.match(/^([^ :[{]+)/)?.[1] || 'text';
33
32
  // if the alias does not have a match in the map
34
33
  // fallback to the alias itself
35
- return ((_b = getLanguagesMap()[alias]) !== null && _b !== void 0 ? _b : {
34
+ return (getLanguagesMap()[alias] ?? {
36
35
  name: alias,
37
36
  ext: alias,
38
37
  aliases: [alias],
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Vue reserved tags
3
3
  *
4
- * @see https://v3.vuejs.org/api/built-in-components.html
4
+ * @see https://vuejs.org/api/built-in-components.html
5
5
  */
6
6
  export declare const vueReservedTags: string[];
@@ -4,7 +4,7 @@ exports.vueReservedTags = void 0;
4
4
  /**
5
5
  * Vue reserved tags
6
6
  *
7
- * @see https://v3.vuejs.org/api/built-in-components.html
7
+ * @see https://vuejs.org/api/built-in-components.html
8
8
  */
9
9
  exports.vueReservedTags = [
10
10
  'template',
@@ -25,9 +25,8 @@ const extractTitlePlugin = (md) => {
25
25
  // extract title to env
26
26
  const render = md.render.bind(md);
27
27
  md.render = (src, env = {}) => {
28
- var _a, _b;
29
28
  const result = render(src, env);
30
- env.title = (_b = (_a = env.frontmatter) === null || _a === void 0 ? void 0 : _a.title) !== null && _b !== void 0 ? _b : title;
29
+ env.title = env.frontmatter?.title ?? title;
31
30
  return result;
32
31
  };
33
32
  };
@@ -41,7 +41,7 @@ const createImportCodeBlockRule = ({ handleImportPath = (str) => str }) => (stat
41
41
  // create a import_code token
42
42
  const token = state.push('import_code', 'code', 0);
43
43
  // use user specified info, or fallback to file ext
44
- token.info = info !== null && info !== void 0 ? info : utils_1.path.extname(meta.importPath).slice(1);
44
+ token.info = info ?? utils_1.path.extname(meta.importPath).slice(1);
45
45
  token.markup = '```';
46
46
  token.map = [startLine, startLine + 1];
47
47
  // store token meta to be used in renderer rule
@@ -26,10 +26,9 @@ const resolveHeadersFromTokens = (tokens, { level, allowHtml, escapeText, slugif
26
26
  }
27
27
  };
28
28
  tokens.forEach((_, idx) => {
29
- var _a;
30
29
  const token = tokens[idx];
31
30
  // if the token type does not match, skip
32
- if ((token === null || token === void 0 ? void 0 : token.type) !== 'heading_open') {
31
+ if (token?.type !== 'heading_open') {
33
32
  return;
34
33
  }
35
34
  // get the level from the tag, h1 -> 1
@@ -50,7 +49,7 @@ const resolveHeadersFromTokens = (tokens, { level, allowHtml, escapeText, slugif
50
49
  });
51
50
  // the id of the heading anchor is the slugify result of markdown-it-anchor
52
51
  // if the id does not exist, slugify the title ourselves
53
- const slug = (_a = token.attrGet('id')) !== null && _a !== void 0 ? _a : slugify(title);
52
+ const slug = token.attrGet('id') ?? slugify(title);
54
53
  // push the header to tree
55
54
  push({
56
55
  level: headerLevel,
@@ -8,9 +8,8 @@ const shared_1 = require("@vuepress/shared");
8
8
  * Typically using the next token of `heading_open` token
9
9
  */
10
10
  const resolveTitleFromToken = (token, { allowHtml, escapeText, }) => {
11
- var _a;
12
11
  // children of the token contains the parsed result of the heading title
13
- const children = (_a = token.children) !== null && _a !== void 0 ? _a : [];
12
+ const children = token.children ?? [];
14
13
  // type of tokens to be included in the heading title
15
14
  const titleTokenTypes = ['text', 'emoji', 'code_inline'];
16
15
  // include 'html_inline' or not
@@ -18,12 +17,9 @@ const resolveTitleFromToken = (token, { allowHtml, escapeText, }) => {
18
17
  titleTokenTypes.push('html_inline');
19
18
  }
20
19
  // filter the token type to be included in the title
21
- const titleTokens = children.filter((item) => {
22
- var _a;
23
- return titleTokenTypes.includes(item.type) &&
24
- // filter permalink symbol that generated by markdown-it-anchor
25
- !((_a = item.meta) === null || _a === void 0 ? void 0 : _a.isPermalinkSymbol);
26
- });
20
+ const titleTokens = children.filter((item) => titleTokenTypes.includes(item.type) &&
21
+ // filter permalink symbol that generated by markdown-it-anchor
22
+ !item.meta?.isPermalinkSymbol);
27
23
  // get title from tokens
28
24
  return titleTokens
29
25
  .reduce((result, item) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vuepress/markdown",
3
- "version": "2.0.0-beta.40",
3
+ "version": "2.0.0-beta.43",
4
4
  "description": "Markdown package of VuePress",
5
5
  "keywords": [
6
6
  "vuepress",
@@ -23,8 +23,8 @@
23
23
  ],
24
24
  "dependencies": {
25
25
  "@types/markdown-it": "^12.2.3",
26
- "@vuepress/shared": "2.0.0-beta.40",
27
- "@vuepress/utils": "2.0.0-beta.40",
26
+ "@vuepress/shared": "2.0.0-beta.43",
27
+ "@vuepress/utils": "2.0.0-beta.43",
28
28
  "markdown-it": "^13.0.0",
29
29
  "markdown-it-anchor": "^8.4.1",
30
30
  "markdown-it-emoji": "^2.0.0",