Security News
NIST Misses 2024 Deadline to Clear NVD Backlog
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.
@shikijs/core
Advanced tools
@shikijs/core is a syntax highlighter for the web that is designed to be fast, lightweight, and easy to use. It supports a wide range of programming languages and can be easily integrated into various web applications.
Syntax Highlighting
This feature allows you to highlight code syntax for various programming languages. The code sample demonstrates how to use the @shikijs/core package to highlight JavaScript code using the 'nord' theme.
const shiki = require('@shikijs/core');
async function highlightCode() {
const highlighter = await shiki.getHighlighter({ theme: 'nord' });
const code = `const x = 10;`;
const highlightedCode = highlighter.codeToHtml(code, { lang: 'javascript' });
console.log(highlightedCode);
}
highlightCode();
Custom Themes
This feature allows you to create and use custom themes for syntax highlighting. The code sample demonstrates how to define a custom theme and use it to highlight JavaScript code.
const shiki = require('@shikijs/core');
async function customThemeHighlight() {
const highlighter = await shiki.getHighlighter({
theme: {
name: 'my-custom-theme',
type: 'dark',
colors: {
'editor.background': '#1e1e1e'
},
tokenColors: [
{
scope: 'comment',
settings: {
foreground: '#6A9955'
}
}
]
}
});
const code = `// This is a comment`;
const highlightedCode = highlighter.codeToHtml(code, { lang: 'javascript' });
console.log(highlightedCode);
}
customThemeHighlight();
Language Registration
This feature allows you to register custom languages for syntax highlighting. The code sample demonstrates how to register a custom language and use it to highlight code.
const shiki = require('@shikijs/core');
async function registerLanguage() {
const highlighter = await shiki.getHighlighter({ theme: 'nord' });
await highlighter.loadLanguage({ id: 'myLang', scopeName: 'source.myLang', grammar: {/* grammar definition */} });
const code = `myLang code here`;
const highlightedCode = highlighter.codeToHtml(code, { lang: 'myLang' });
console.log(highlightedCode);
}
registerLanguage();
highlight.js is a popular syntax highlighter written in JavaScript. It supports a wide range of languages and is known for its ease of use and extensive language support. Compared to @shikijs/core, highlight.js is more established but may not be as lightweight or fast.
Prism is a lightweight, extensible syntax highlighter. It is designed to be easy to customize and extend, with a focus on performance. Compared to @shikijs/core, Prism offers a more modular approach but may require more configuration for advanced use cases.
The core functionality of Shiki, without any grammar of themes bundled.
It's the same as importing shiki/core
.
FAQs
Core of Shiki
The npm package @shikijs/core receives a total of 817,290 weekly downloads. As such, @shikijs/core popularity was classified as popular.
We found that @shikijs/core demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.
Security News
Cloudflare has launched a setup wizard allowing users to easily create and manage a security.txt file for vulnerability disclosure on their websites.
Security News
The Socket Research team breaks down a malicious npm package targeting the legitimate DOMPurify library. It uses obfuscated code to hide that it is exfiltrating browser and crypto wallet data.