@vuepress/markdown 2.0.0-beta.42 → 2.0.0-beta.45

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,7 +8,7 @@ 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
14
  const token = tokens[idx];
@@ -25,7 +25,7 @@ const codePlugin = (md, { highlightLines = true, lineNumbers = true, preWrapper
25
25
  ? code
26
26
  : `<pre class="${languageClass}"><code>${code}</code></pre>`;
27
27
  // resolve v-pre mark from token info
28
- const useVPre = (0, resolveVPre_1.resolveVPre)(info) ?? vPre;
28
+ const useVPre = (0, resolveVPre_1.resolveVPre)(info) ?? vPreBlock;
29
29
  if (useVPre) {
30
30
  result = `<pre v-pre${result.slice('<pre'.length)}`;
31
31
  }
@@ -60,12 +60,19 @@ const codePlugin = (md, { highlightLines = true, lineNumbers = true, preWrapper
60
60
  if (useLineNumbers) {
61
61
  // generate line numbers code
62
62
  const lineNumbersCode = lines
63
- .map((_, index) => `<span class="line-number">${index + 1}</span><br>`)
63
+ .map(() => `<div class="line-number"></div>`)
64
64
  .join('');
65
65
  result = `${result}<div class="line-numbers" aria-hidden="true">${lineNumbersCode}</div>`;
66
66
  }
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;
@@ -1,17 +1,28 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.resolvePaths = void 0;
4
+ const shared_1 = require("@vuepress/shared");
4
5
  const utils_1 = require("@vuepress/utils");
5
6
  /**
6
7
  * Resolve relative and absolute paths according to the `base` and `filePathRelative`
7
8
  */
8
9
  const resolvePaths = (rawPath, base, filePathRelative) => {
9
- let relativePath;
10
10
  let absolutePath;
11
+ let relativePath;
11
12
  if (rawPath.startsWith('/')) {
12
13
  // if raw path is absolute
13
- absolutePath = rawPath;
14
- relativePath = utils_1.path.relative(base, absolutePath);
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
+ }
15
26
  }
16
27
  else {
17
28
  // if raw path is relative
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vuepress/markdown",
3
- "version": "2.0.0-beta.42",
3
+ "version": "2.0.0-beta.45",
4
4
  "description": "Markdown package of VuePress",
5
5
  "keywords": [
6
6
  "vuepress",
@@ -23,11 +23,11 @@
23
23
  ],
24
24
  "dependencies": {
25
25
  "@types/markdown-it": "^12.2.3",
26
- "@vuepress/shared": "2.0.0-beta.42",
27
- "@vuepress/utils": "2.0.0-beta.42",
28
- "markdown-it": "^13.0.0",
29
- "markdown-it-anchor": "^8.4.1",
30
- "markdown-it-emoji": "^2.0.0",
26
+ "@vuepress/shared": "2.0.0-beta.45",
27
+ "@vuepress/utils": "2.0.0-beta.45",
28
+ "markdown-it": "^13.0.1",
29
+ "markdown-it-anchor": "^8.6.3",
30
+ "markdown-it-emoji": "^2.0.2",
31
31
  "mdurl": "^1.0.1"
32
32
  },
33
33
  "publishConfig": {