Socket
Socket
Sign inDemoInstall

shiki

Package Overview
Dependencies
Maintainers
1
Versions
115
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

shiki - npm Package Compare versions

Comparing version 0.1.4 to 0.1.5

dist/highlighter.js.map

4

dist/highlighter.d.ts

@@ -10,4 +10,4 @@ import { TLang } from 'shiki-languages';

export interface Highlighter {
codeToThemedTokens(code: string, lang: string): IThemedToken[][];
codeToHtml?(code: string, lang: string): string;
codeToThemedTokens(code: string, lang: TLang): IThemedToken[][];
codeToHtml?(code: string, lang: TLang): string;
}

@@ -109,5 +109,19 @@ "use strict";

codeToThemedTokens: function (code, lang) {
if (isPlaintext(lang)) {
throw Error('Cannot tokenize plaintext');
}
if (!ltog[lang]) {
throw Error("No language registration for " + lang);
}
return themedTokenizer_1.tokenizeWithTheme(_this._theme, _this._colorMap, code, ltog[lang]);
},
codeToHtml: function (code, lang) {
if (isPlaintext(lang)) {
return renderer_1.renderToHtml([[{ content: code }]], {
bg: _this._theme.bg
});
}
if (!ltog[lang]) {
throw Error("No language registration for " + lang);
}
var tokens = themedTokenizer_1.tokenizeWithTheme(_this._theme, _this._colorMap, code, ltog[lang]);

@@ -125,1 +139,5 @@ return renderer_1.renderToHtml(tokens, {

}());
function isPlaintext(lang) {
return ['plaintext', 'txt', 'text'].indexOf(lang) !== -1;
}
//# sourceMappingURL=highlighter.js.map
export { getTheme, loadTheme } from 'shiki-themes';
export { commonLangIds, commonLangAliases, otherLangIds } from 'shiki-languages';
export { getHighlighter } from './highlighter';
export { renderToHtml } from './renderer';
export { IThemedToken } from './themedTokenizer';

@@ -6,2 +6,6 @@ "use strict";

exports.loadTheme = shiki_themes_1.loadTheme;
var shiki_languages_1 = require("shiki-languages");
exports.commonLangIds = shiki_languages_1.commonLangIds;
exports.commonLangAliases = shiki_languages_1.commonLangAliases;
exports.otherLangIds = shiki_languages_1.otherLangIds;
var highlighter_1 = require("./highlighter");

@@ -11,1 +15,2 @@ exports.getHighlighter = highlighter_1.getHighlighter;

exports.renderToHtml = renderer_1.renderToHtml;
//# sourceMappingURL=index.js.map

@@ -28,1 +28,2 @@ /*---------------------------------------------------------

exports.getOnigasm = getOnigasm;
//# sourceMappingURL=onigLibs.js.map

@@ -31,1 +31,2 @@ "use strict";

}
//# sourceMappingURL=renderer.js.map

@@ -105,1 +105,2 @@ /*---------------------------------------------------------

}
//# sourceMappingURL=resolver.js.map

@@ -74,1 +74,2 @@ "use strict";

exports.StackElementMetadata = StackElementMetadata;
//# sourceMappingURL=stackElementMetadata.js.map

@@ -124,1 +124,2 @@ /*---------------------------------------------------------

}
//# sourceMappingURL=themedTokenizer.js.map
{
"name": "shiki",
"version": "0.1.4",
"version": "0.1.5",
"description": "shiki",

@@ -21,7 +21,7 @@ "keywords": [

"onigasm": "^2.2.1",
"shiki-languages": "^0.1.4",
"shiki-themes": "^0.1.4",
"shiki-languages": "^0.1.5",
"shiki-themes": "^0.1.5",
"vscode-textmate": "https://github.com/octref/vscode-textmate"
},
"gitHead": "aee04f62480bd891d036c2606f84d1d8cf27a4a6"
"gitHead": "c91d0ed6af369a9c28ebf699b34edb7c60280a58"
}
import { Registry } from 'vscode-textmate'
import { TLang, commonLangIds, commonLangAliases, ILanguageRegistration, getLangRegistrations } from 'shiki-languages'
import {
TLang,
commonLangIds,
commonLangAliases,
ILanguageRegistration,
getLangRegistrations
} from 'shiki-languages'

@@ -18,5 +24,5 @@ import { Resolver } from './resolver'

export async function getHighlighter(options: HighlighterOptions) {
let t: IShikiTheme;
let t: IShikiTheme
if (typeof options.theme === 'string') {
t = getTheme(options.theme)
t = getTheme(options.theme)
} else if (options.theme.name) {

@@ -28,6 +34,3 @@ t = options.theme

let langs: TLang[] = [
...commonLangIds,
...commonLangAliases
]
let langs: TLang[] = [...commonLangIds, ...commonLangAliases]

@@ -79,5 +82,19 @@ if (options.langs) {

codeToThemedTokens: (code, lang) => {
if (isPlaintext(lang)) {
throw Error('Cannot tokenize plaintext')
}
if (!ltog[lang]) {
throw Error(`No language registration for ${lang}`)
}
return tokenizeWithTheme(this._theme, this._colorMap, code, ltog[lang])
},
codeToHtml: (code, lang) => {
if (isPlaintext(lang)) {
return renderToHtml([[{ content: code }]], {
bg: this._theme.bg
})
}
if (!ltog[lang]) {
throw Error(`No language registration for ${lang}`)
}
const tokens = tokenizeWithTheme(this._theme, this._colorMap, code, ltog[lang])

@@ -92,5 +109,9 @@ return renderToHtml(tokens, {

function isPlaintext(lang) {
return ['plaintext', 'txt', 'text'].indexOf(lang) !== -1
}
export interface Highlighter {
codeToThemedTokens(code: string, lang: string): IThemedToken[][]
codeToHtml?(code: string, lang: string): string
codeToThemedTokens(code: string, lang: TLang): IThemedToken[][]
codeToHtml?(code: string, lang: TLang): string

@@ -102,2 +123,2 @@ // codeToRawHtml?(code: string): string

// codeToImage?(): string
}
}
export { getTheme, loadTheme } from 'shiki-themes'
export { commonLangIds, commonLangAliases, otherLangIds } from 'shiki-languages'

@@ -3,0 +4,0 @@ export { getHighlighter } from './highlighter';

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc