@vuepress/plugin-shiki 2.0.0-rc.40 → 2.0.0-rc.42

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,6 @@
1
1
  :root {
2
2
  --code-c-text: #9e9e9e;
3
- --code-c-highlight-bg: rgb(0 0 0 / 66%);
3
+ --code-c-highlight-bg: rgba(142 150 170 / 14%);
4
4
  }
5
5
 
6
6
  .shiki span {
@@ -11,8 +11,8 @@
11
11
  }
12
12
 
13
13
  div[data-highlighter=shiki] {
14
- background-color: var(--code-c-bg, --shiki-light-bg);
14
+ background-color: var(--code-c-bg, var(--shiki-light-bg));
15
15
  }
16
16
  [data-theme=dark] div[data-highlighter=shiki] {
17
- background-color: var(--code-c-bg, --shiki-dark-bg);
17
+ background-color: var(--code-c-bg, var(--shiki-dark-bg));
18
18
  }
@@ -1,6 +1,6 @@
1
1
  export const createMarkdownFilePathGetter = (md) => {
2
2
  const store = {};
3
- const rawRender = md.render;
3
+ const rawRender = md.render.bind(md);
4
4
  // we need to store file path before each render
5
5
  md.render = (src, env) => {
6
6
  store.path = env.filePathRelative;
@@ -15,10 +15,11 @@ const removeMustache = (str, store) => str.replace(MUSTACHE_REG, (match) => {
15
15
  return marker;
16
16
  });
17
17
  const restoreMustache = (str, store) => {
18
+ let result = str;
18
19
  store.forEach((marker, match) => {
19
- str = str.replaceAll(marker, match);
20
+ result = result.replaceAll(marker, match);
20
21
  });
21
- return str;
22
+ return result;
22
23
  };
23
24
  export const handleMustache = (str, highlight) => {
24
25
  const store = new Map();
@@ -19,7 +19,7 @@ export const applyHighlighter = async (md, app, { langs = bundledLanguageNames,
19
19
  await options.shikiSetup?.(highlighter);
20
20
  const transformers = getTransformers(options);
21
21
  const loadedLanguages = highlighter.getLoadedLanguages();
22
- md.options.highlight = (str, language, attrs) => handleMustache(str, (str) => highlighter.codeToHtml(str, {
22
+ md.options.highlight = (content, language, attrs) => handleMustache(content, (str) => highlighter.codeToHtml(str, {
23
23
  lang: getLanguage(language, loadedLanguages, defaultLang, logLevel, getMarkdownFilePath),
24
24
  meta: {
25
25
  /**
@@ -7,16 +7,15 @@ export const highlightLinesPlugin = (md) => {
7
7
  md.renderer.rules.fence = (...args) => {
8
8
  const [tokens, idx] = args;
9
9
  const token = tokens[idx];
10
- let lines = null;
11
- const rawInfo = token.info;
12
- const result = rawInfo?.match(HIGHLIGHT_LINES_REGEXP);
10
+ const rawInfo = token.info || '';
11
+ const result = rawInfo.match(HIGHLIGHT_LINES_REGEXP);
13
12
  if (!result) {
14
13
  return rawFence(...args);
15
14
  }
16
15
  // ensure the next plugin get the correct lang
17
16
  token.info = rawInfo.replace(HIGHLIGHT_LINES_REGEXP, '').trim();
18
- lines = result[1];
19
- token.info += ' ' + lines;
17
+ const lines = result[1];
18
+ token.info += ` ${lines}`;
20
19
  return rawFence(...args);
21
20
  };
22
21
  };
@@ -3,4 +3,4 @@ import type { PreWrapperOptions, ShikiHighlightOptions } from './types.js';
3
3
  /**
4
4
  * Options of @vuepress/plugin-shiki
5
5
  */
6
- export type ShikiPluginOptions = ShikiHighlightOptions & PreWrapperOptions & Pick<MarkdownItLineNumbersOptions, 'lineNumbers'>;
6
+ export type ShikiPluginOptions = Pick<MarkdownItLineNumbersOptions, 'lineNumbers'> & PreWrapperOptions & ShikiHighlightOptions;
@@ -2,4 +2,4 @@ import type { WhitespacePosition } from '@vuepress/highlighter-helper';
2
2
  import type { ShikiTransformer } from 'shiki';
3
3
  import type { ShikiHighlightOptions } from '../types.js';
4
4
  export declare const getTransformers: (options: ShikiHighlightOptions) => ShikiTransformer[];
5
- export declare const whitespaceTransformer: (meta: string, defaultPosition?: boolean | WhitespacePosition) => ShikiTransformer[];
5
+ export declare const whitespaceTransformer: (meta: string, defaultPosition?: WhitespacePosition | boolean) => ShikiTransformer[];
@@ -1,7 +1,7 @@
1
1
  import type { WhitespacePosition } from '@vuepress/highlighter-helper';
2
2
  import type { BundledLanguage, BundledTheme, Highlighter, LanguageInput, ShikiTransformer, SpecialLanguage, StringLiteralUnion, ThemeRegistrationAny } from 'shiki';
3
- export type ShikiLang = LanguageInput | StringLiteralUnion<BundledLanguage> | SpecialLanguage;
4
- export type ShikiTheme = ThemeRegistrationAny | StringLiteralUnion<BundledTheme>;
3
+ export type ShikiLang = LanguageInput | SpecialLanguage | StringLiteralUnion<BundledLanguage>;
4
+ export type ShikiTheme = StringLiteralUnion<BundledTheme> | ThemeRegistrationAny;
5
5
  export interface ShikiSingleThemeOptions {
6
6
  /**
7
7
  * The single theme to use
@@ -49,7 +49,7 @@ export type ShikiHighlightOptions = ShikiThemeOptions & {
49
49
  /**
50
50
  * Function to customize Shiki highlighter instance.
51
51
  */
52
- shikiSetup?: (shiki: Highlighter) => void | Promise<void>;
52
+ shikiSetup?: (shiki: Highlighter) => Promise<void> | void;
53
53
  /**
54
54
  * Shiki transformers
55
55
  */
@@ -116,7 +116,7 @@ export type ShikiHighlightOptions = ShikiThemeOptions & {
116
116
  *
117
117
  * @see https://shiki.style/packages/transformers#transformerrenderwhitespace
118
118
  */
119
- whitespace?: boolean | WhitespacePosition;
119
+ whitespace?: WhitespacePosition | boolean;
120
120
  /**
121
121
  * Log level Highlighter language detecter
122
122
  *
@@ -124,7 +124,7 @@ export type ShikiHighlightOptions = ShikiThemeOptions & {
124
124
  *
125
125
  * @default 'warn'
126
126
  */
127
- logLevel?: 'silent' | 'warn' | 'debug';
127
+ logLevel?: 'debug' | 'silent' | 'warn';
128
128
  };
129
129
  export interface PreWrapperOptions {
130
130
  /**
package/lib/node/utils.js CHANGED
@@ -25,14 +25,14 @@ export const resolveAttr = (info, attr) => {
25
25
  * [{ line: number, classes: string[] }]
26
26
  */
27
27
  export const attrsToLines = (attrs) => {
28
- attrs = attrs.replace(/^(?:\[.*?\])?.*?([\d,-]+).*/, '$1').trim();
28
+ const attrsContent = attrs.replace(/^(?:\[.*?\])?.*?([\d,-]+).*/, '$1').trim();
29
29
  const result = [];
30
- if (!attrs) {
30
+ if (!attrsContent) {
31
31
  return [];
32
32
  }
33
- attrs
33
+ attrsContent
34
34
  .split(',')
35
- .map((v) => v.split('-').map((v) => parseInt(v, 10)))
35
+ .map((lineNumberConfig) => lineNumberConfig.split('-').map((lineNumber) => parseInt(lineNumber, 10)))
36
36
  .forEach(([start, end]) => {
37
37
  if (start && end) {
38
38
  result.push(...Array.from({ length: end - start + 1 }, (_, i) => start + i));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vuepress/plugin-shiki",
3
- "version": "2.0.0-rc.40",
3
+ "version": "2.0.0-rc.42",
4
4
  "description": "VuePress plugin - shiki",
5
5
  "keywords": [
6
6
  "vuepress-plugin",
@@ -32,17 +32,17 @@
32
32
  "lib"
33
33
  ],
34
34
  "dependencies": {
35
- "@shikijs/transformers": "^1.11.1",
36
- "@vuepress/helper": "2.0.0-rc.40",
37
- "@vuepress/highlighter-helper": "2.0.0-rc.40",
35
+ "@shikijs/transformers": "^1.14.1",
36
+ "@vuepress/helper": "2.0.0-rc.42",
37
+ "@vuepress/highlighter-helper": "2.0.0-rc.42",
38
38
  "nanoid": "^5.0.7",
39
- "shiki": "^1.11.1"
39
+ "shiki": "^1.14.1"
40
40
  },
41
41
  "peerDependencies": {
42
- "vuepress": "2.0.0-rc.14"
42
+ "vuepress": "2.0.0-rc.15"
43
43
  },
44
44
  "publishConfig": {
45
45
  "access": "public"
46
46
  },
47
- "gitHead": "942849e4983555f1a7cf03a96579110a505492cb"
47
+ "gitHead": "66e494405a7fbb02f6d46d7be670ec69605b7606"
48
48
  }