@vuepress/plugin-shiki 2.0.0-rc.43 → 2.0.0-rc.44

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,6 +1,17 @@
1
- import type { MarkdownItLineNumbersOptions } from '@vuepress/highlighter-helper';
1
+ import type { MarkdownItCollapsedLinesOptions } from '@vuepress/highlighter-helper';
2
2
  import type { PreWrapperOptions, ShikiHighlightOptions } from './types.js';
3
3
  /**
4
4
  * Options of @vuepress/plugin-shiki
5
5
  */
6
- export type ShikiPluginOptions = Pick<MarkdownItLineNumbersOptions, 'lineNumbers'> & PreWrapperOptions & ShikiHighlightOptions;
6
+ export type ShikiPluginOptions = Pick<MarkdownItCollapsedLinesOptions, 'collapsedLines'> & PreWrapperOptions & ShikiHighlightOptions & {
7
+ /**
8
+ * Line number options
9
+ *
10
+ * - A `boolean` value is to enable line numbers or not globally.
11
+ * - A `number` value is the minimum number of lines to enable line numbers
12
+ * - `disable` means completely disable the feature
13
+ *
14
+ * @default true
15
+ */
16
+ lineNumbers?: boolean | number | 'disable';
17
+ };
@@ -1,3 +1,3 @@
1
1
  import type { App } from 'vuepress';
2
2
  import type { ShikiPluginOptions } from './options.js';
3
- export declare const prepareConfigFile: (app: App, { lineNumbers, notationDiff, notationErrorLevel, notationFocus, notationHighlight, notationWordHighlight, whitespace, }: ShikiPluginOptions) => Promise<string>;
3
+ export declare const prepareConfigFile: (app: App, { lineNumbers, collapsedLines, notationDiff, notationErrorLevel, notationFocus, notationHighlight, notationWordHighlight, whitespace, }: ShikiPluginOptions) => Promise<string>;
@@ -1,12 +1,13 @@
1
1
  import { getRealPath } from '@vuepress/helper';
2
2
  import { PLUGIN_NAME } from './utils.js';
3
3
  const { url } = import.meta;
4
- export const prepareConfigFile = (app, { lineNumbers = true, notationDiff, notationErrorLevel, notationFocus, notationHighlight, notationWordHighlight, whitespace, }) => {
4
+ export const prepareConfigFile = (app, { lineNumbers = true, collapsedLines, notationDiff, notationErrorLevel, notationFocus, notationHighlight, notationWordHighlight, whitespace, }) => {
5
5
  const imports = [
6
6
  `import "${getRealPath('@vuepress/highlighter-helper/styles/base.css', url)}"`,
7
7
  `import "${getRealPath(`${PLUGIN_NAME}/styles/shiki.css`, import.meta.url)}"`,
8
8
  ];
9
- if (lineNumbers) {
9
+ const setups = [];
10
+ if (lineNumbers !== 'disable') {
10
11
  imports.push(`import "${getRealPath('@vuepress/highlighter-helper/styles/line-numbers.css', url)}"`);
11
12
  }
12
13
  if (notationDiff) {
@@ -27,5 +28,18 @@ export const prepareConfigFile = (app, { lineNumbers = true, notationDiff, notat
27
28
  if (whitespace) {
28
29
  imports.push(`import "${getRealPath('@vuepress/highlighter-helper/styles/whitespace.css', url)}"`);
29
30
  }
30
- return app.writeTemp('shiki/config.js', imports.join('\n'));
31
+ if (collapsedLines !== 'disable') {
32
+ imports.push(`import "${getRealPath('@vuepress/highlighter-helper/styles/collapsed-lines.css', url)}"`, `import { setupCollapsedLines } from "${getRealPath('@vuepress/highlighter-helper/composables/collapsedLines.js', url)}"`);
33
+ setups.push('setupCollapsedLines()');
34
+ }
35
+ let code = imports.join('\n');
36
+ if (setups.length) {
37
+ code += `\n
38
+ export default {
39
+ setup() {
40
+ ${setups.join('\n ')}
41
+ }
42
+ }\n`;
43
+ }
44
+ return app.writeTemp('shiki/config.js', code);
31
45
  };
@@ -1,3 +1,3 @@
1
1
  import type { Plugin } from 'vuepress/core';
2
2
  import type { ShikiPluginOptions } from './options.js';
3
- export declare const shikiPlugin: ({ preWrapper, lineNumbers, ...options }?: ShikiPluginOptions) => Plugin;
3
+ export declare const shikiPlugin: (options?: ShikiPluginOptions) => Plugin;
@@ -1,22 +1,34 @@
1
- import { lineNumbers as lineNumbersPlugin } from '@vuepress/highlighter-helper';
1
+ import { collapsedLines as collapsedLinesPlugin, lineNumbers as lineNumbersPlugin, } from '@vuepress/highlighter-helper';
2
2
  import { isPlainObject } from 'vuepress/shared';
3
3
  import { applyHighlighter, highlightLinesPlugin, preWrapperPlugin, } from './markdown/index.js';
4
4
  import { prepareConfigFile } from './prepareConfigFile.js';
5
- export const shikiPlugin = ({ preWrapper = true, lineNumbers = true, ...options } = {}) => ({
6
- name: '@vuepress/plugin-shiki',
7
- extendsMarkdown: async (md, app) => {
8
- // FIXME: Remove in stable version
9
- // eslint-disable-next-line @typescript-eslint/no-deprecated
10
- const { code } = app.options.markdown;
11
- await applyHighlighter(md, app, {
12
- ...(isPlainObject(code) ? code : {}),
13
- ...options,
14
- });
15
- md.use(highlightLinesPlugin);
16
- md.use(preWrapperPlugin, { preWrapper });
17
- if (preWrapper) {
18
- md.use(lineNumbersPlugin, { lineNumbers });
19
- }
20
- },
21
- clientConfigFile: (app) => prepareConfigFile(app, options),
22
- });
5
+ export const shikiPlugin = (options = {}) => {
6
+ const opt = {
7
+ preWrapper: true,
8
+ lineNumbers: true,
9
+ collapsedLines: 'disable',
10
+ ...options,
11
+ };
12
+ return {
13
+ name: '@vuepress/plugin-shiki',
14
+ extendsMarkdown: async (md, app) => {
15
+ // FIXME: Remove in stable version
16
+ // eslint-disable-next-line @typescript-eslint/no-deprecated
17
+ const { code } = app.options.markdown;
18
+ await applyHighlighter(md, app, {
19
+ ...(isPlainObject(code) ? code : {}),
20
+ ...options,
21
+ });
22
+ const { preWrapper, lineNumbers, collapsedLines } = opt;
23
+ md.use(highlightLinesPlugin);
24
+ md.use(preWrapperPlugin, { preWrapper });
25
+ if (preWrapper) {
26
+ if (lineNumbers !== 'disable')
27
+ md.use(lineNumbersPlugin, { lineNumbers });
28
+ if (collapsedLines !== 'disable')
29
+ md.use(collapsedLinesPlugin, { collapsedLines });
30
+ }
31
+ },
32
+ clientConfigFile: (app) => prepareConfigFile(app, opt),
33
+ };
34
+ };
@@ -27,7 +27,7 @@ export const getTransformers = (options) => {
27
27
  };
28
28
  export const whitespaceTransformer = (meta, defaultPosition = false) => {
29
29
  const position = resolveWhitespacePosition(meta, defaultPosition);
30
- // disabled current code block
30
+ // disable current code block
31
31
  if (position === false)
32
32
  return [];
33
33
  return [transformerRenderWhitespace({ position })];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vuepress/plugin-shiki",
3
- "version": "2.0.0-rc.43",
3
+ "version": "2.0.0-rc.44",
4
4
  "description": "VuePress plugin - shiki",
5
5
  "keywords": [
6
6
  "vuepress-plugin",
@@ -32,11 +32,11 @@
32
32
  "lib"
33
33
  ],
34
34
  "dependencies": {
35
- "@shikijs/transformers": "^1.16.3",
36
- "@vuepress/helper": "2.0.0-rc.43",
37
- "@vuepress/highlighter-helper": "2.0.0-rc.43",
35
+ "@shikijs/transformers": "^1.17.7",
36
+ "@vuepress/helper": "2.0.0-rc.44",
37
+ "@vuepress/highlighter-helper": "2.0.0-rc.44",
38
38
  "nanoid": "^5.0.7",
39
- "shiki": "^1.16.3"
39
+ "shiki": "^1.17.7"
40
40
  },
41
41
  "peerDependencies": {
42
42
  "vuepress": "2.0.0-rc.15"
@@ -44,5 +44,5 @@
44
44
  "publishConfig": {
45
45
  "access": "public"
46
46
  },
47
- "gitHead": "7c75a58f6aed788e2ee40e2b2f0451a76ec20a23"
47
+ "gitHead": "e450489799bbfbdd015ec52255576144185eb64f"
48
48
  }