Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@shikijs/core

Package Overview
Dependencies
Maintainers
0
Versions
74
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@shikijs/core

Core of Shiki

  • 1.24.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.2M
increased by0.66%
Maintainers
0
Weekly downloads
 
Created

What is @shikijs/core?

@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.

What are @shikijs/core's main functionalities?

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();

Other packages similar to @shikijs/core

Keywords

FAQs

Package last updated on 09 Dec 2024

Did you know?

Socket

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.

Install

Related posts

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