@vuepress/plugin-shiki 2.0.0-rc.33 → 2.0.0-rc.34

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
1
  export * from './applyHighlighter/index.js';
2
2
  export * from './highlightLinesPlugin.js';
3
- export * from './lineNumberPlugin.js';
4
3
  export * from './preWrapperPlugin.js';
@@ -1,4 +1,3 @@
1
1
  export * from './applyHighlighter/index.js';
2
2
  export * from './highlightLinesPlugin.js';
3
- export * from './lineNumberPlugin.js';
4
3
  export * from './preWrapperPlugin.js';
@@ -1,5 +1,6 @@
1
- import type { LineNumberOptions, PreWrapperOptions, ShikiHighlightOptions } from './types.js';
1
+ import type { MarkdownItLineNumbersOptions } from '@vuepress/highlighter-helper';
2
+ import type { PreWrapperOptions, ShikiHighlightOptions } from './types.js';
2
3
  /**
3
4
  * Options of @vuepress/plugin-shiki
4
5
  */
5
- export type ShikiPluginOptions = ShikiHighlightOptions & PreWrapperOptions & LineNumberOptions;
6
+ export type ShikiPluginOptions = ShikiHighlightOptions & PreWrapperOptions & Pick<MarkdownItLineNumbersOptions, 'lineNumbers'>;
@@ -1,5 +1,6 @@
1
+ import { lineNumbers as lineNumbersPlugin } from '@vuepress/highlighter-helper';
1
2
  import { isPlainObject } from 'vuepress/shared';
2
- import { applyHighlighter, highlightLinesPlugin, lineNumberPlugin, preWrapperPlugin, } from './markdown/index.js';
3
+ import { applyHighlighter, highlightLinesPlugin, preWrapperPlugin, } from './markdown/index.js';
3
4
  export const shikiPlugin = ({ preWrapper = true, lineNumbers = true, ...options } = {}) => ({
4
5
  name: '@vuepress/plugin-shiki',
5
6
  extendsMarkdown: async (md, app) => {
@@ -11,7 +12,7 @@ export const shikiPlugin = ({ preWrapper = true, lineNumbers = true, ...options
11
12
  md.use(highlightLinesPlugin);
12
13
  md.use(preWrapperPlugin, { preWrapper });
13
14
  if (preWrapper) {
14
- md.use(lineNumberPlugin, { lineNumbers });
15
+ md.use(lineNumbersPlugin, { lineNumbers });
15
16
  }
16
17
  },
17
18
  });
@@ -100,13 +100,6 @@ export type ShikiHighlightOptions = ShikiThemeOptions & {
100
100
  */
101
101
  logLevel?: 'silent' | 'warn' | 'debug';
102
102
  };
103
- export interface LineNumberOptions {
104
- /**
105
- * Show line numbers in code blocks
106
- * @default true
107
- */
108
- lineNumbers?: boolean | number;
109
- }
110
103
  export interface PreWrapperOptions {
111
104
  /**
112
105
  * Wrap the `<pre>` tag with an extra `<div>` or not. Do not disable it unless you
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vuepress/plugin-shiki",
3
- "version": "2.0.0-rc.33",
3
+ "version": "2.0.0-rc.34",
4
4
  "description": "VuePress plugin - shiki",
5
5
  "keywords": [
6
6
  "vuepress-plugin",
@@ -35,13 +35,14 @@
35
35
  "clean": "rimraf --glob ./lib ./*.tsbuildinfo"
36
36
  },
37
37
  "dependencies": {
38
- "@shikijs/transformers": "^1.6.1",
39
- "@vuepress/helper": "2.0.0-rc.33",
38
+ "@shikijs/transformers": "^1.6.2",
39
+ "@vuepress/helper": "2.0.0-rc.34",
40
+ "@vuepress/highlighter-helper": "2.0.0-rc.34",
40
41
  "nanoid": "^5.0.7",
41
- "shiki": "^1.6.1"
42
+ "shiki": "^1.6.2"
42
43
  },
43
44
  "peerDependencies": {
44
- "vuepress": "2.0.0-rc.12"
45
+ "vuepress": "2.0.0-rc.13"
45
46
  },
46
47
  "publishConfig": {
47
48
  "access": "public"
@@ -50,5 +51,5 @@
50
51
  "@types/markdown-it": "^14.1.1",
51
52
  "markdown-it": "^14.1.0"
52
53
  },
53
- "gitHead": "6e9565ef71b7eb41f8bf8736dc9f6544f1925c58"
54
+ "gitHead": "93df303baa6291f52e3523f136073e79d53274ea"
54
55
  }
@@ -1,3 +0,0 @@
1
- import type { Markdown } from 'vuepress/markdown';
2
- import type { LineNumberOptions } from '../types.js';
3
- export declare const lineNumberPlugin: (md: Markdown, { lineNumbers }?: LineNumberOptions) => void;
@@ -1,36 +0,0 @@
1
- // markdown-it plugin for generating line numbers.
2
- // It depends on preWrapper plugin.
3
- const LINE_NUMBERS_REGEXP = /:line-numbers\b/;
4
- const NO_LINE_NUMBERS_REGEXP = /:no-line-numbers\b/;
5
- const LINE_NUMBERS_START_REGEXP = /:line-numbers=(\d+)\b/;
6
- export const lineNumberPlugin = (md, { lineNumbers = true } = {}) => {
7
- const rawFence = md.renderer.rules.fence;
8
- md.renderer.rules.fence = (...args) => {
9
- const rawCode = rawFence(...args);
10
- const [tokens, idx] = args;
11
- const info = tokens[idx].info;
12
- const enableLineNumbers = LINE_NUMBERS_REGEXP.test(info);
13
- const disableLineNumbers = NO_LINE_NUMBERS_REGEXP.test(info);
14
- if ((!lineNumbers && !enableLineNumbers) ||
15
- (lineNumbers && disableLineNumbers)) {
16
- return rawCode;
17
- }
18
- const code = rawCode.slice(rawCode.indexOf('<code>'), rawCode.indexOf('</code>'));
19
- const lines = code.split('\n');
20
- if (typeof lineNumbers === 'number' &&
21
- lines.length < lineNumbers &&
22
- !enableLineNumbers) {
23
- return rawCode;
24
- }
25
- const startNumbers = Number(info.match(LINE_NUMBERS_START_REGEXP)?.[1] ?? 1) - 1;
26
- const lineNumbersStyle = `style="counter-reset:line-number ${startNumbers}"`;
27
- const lineNumbersCode = [...Array(lines.length)]
28
- .map(() => `<div class="line-number"></div>`)
29
- .join('');
30
- const lineNumbersWrapperCode = `<div class="line-numbers" aria-hidden="true" ${lineNumbersStyle}>${lineNumbersCode}</div>`;
31
- const finalCode = rawCode
32
- .replace(/<\/div>$/, `${lineNumbersWrapperCode}</div>`)
33
- .replace(/"(language-[^"]*?)"/, '"$1 line-numbers-mode"');
34
- return finalCode;
35
- };
36
- };