Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
161 changes: 59 additions & 102 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,9 @@
"dependencies": {
"json5": "^2.1.3",
"marked": "^4.0.15",
"oniguruma": "^7.2.1",
"shiki": "^0.2.5",
"shiki-themes": "^0.2.5"
"shiki": "^0.14.1",
"shiki-themes": "^0.2.5",
"vscode-oniguruma": "^1.7.0"
},
"devDependencies": {
"@types/json5": "0.0.30",
Expand Down
23 changes: 15 additions & 8 deletions src/codeHighlighter.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import json5 from 'json5';
import * as shiki from 'shiki';
import type { IShikiTheme, Theme } from 'shiki-themes';
import { Highlighter } from 'shiki/dist/highlighter';
import { Highlighter } from 'shiki'
import type { Theme, IShikiTheme } from 'shiki'
import * as vscode from 'vscode';

declare const TextDecoder: any;
Expand Down Expand Up @@ -67,7 +67,7 @@ export class CodeHighlighter {
try {
const languageId = getLanguageId(language);
if (languageId) {
return highlighter.codeToHtml!(code, languageId);
return highlighter.codeToHtml(code, { lang: languageId });
}
} catch (err) {
// noop
Expand All @@ -92,7 +92,7 @@ export class CodeHighlighter {
} else if (currentThemeName) {
const colorThemePath = getCurrentThemePath(currentThemeName);
if (colorThemePath) {
theme = shiki.loadTheme(colorThemePath.fsPath);
theme = await shiki.loadTheme(colorThemePath.fsPath);

theme.name = 'random'; // Shiki doesn't work without name and defaults to `Nord`

Expand All @@ -107,11 +107,18 @@ export class CodeHighlighter {
}

if (typeof theme === 'string') {
theme = shiki.getTheme(theme as any);
// @ts-ignore
theme = shiki.getTheme(theme) as IShikiTheme
}

if (theme) {
theme.bg = ' '; // Don't set bg so that we use the view's background instead
if (theme && theme.settings) {
// Don't set bg so that we use the view's background instead
theme.bg = 'transparent'
theme.settings.unshift({
settings: {
background: 'transparent',
}
})
}
return theme;
}
Expand Down Expand Up @@ -215,7 +222,7 @@ const languages = [
{ name: 'handlebars', language: 'handlebars', identifiers: ['handlebars', 'hbs'], source: 'text.html.handlebars' },
{ name: 'markdown', language: 'markdown', identifiers: ['markdown', 'md'], source: 'text.html.markdown' },
{ name: 'haskell', language: 'haskell', identifiers: ['hs', 'lhs'], source: 'text.html.hs' },
{ name: 'ocaml', language: 'ocaml', identifiers: ['ml', 'mli', 'eliom', 'eliomi'], source: 'source.ocaml.interface' },
{ name: 'ocaml', language: 'ocaml', identifiers: ['ml', 'mli', 'eliom', 'eliomi'], source: 'source.ocaml.interface' },
{ name: 'zig', language: 'zig', identifiers: ['zig'], source: 'source.zig' },
{ name: 'd', language: 'd', identifiers: ['d'], source: 'source.d' },
];