What is @shikijs/engine-oniguruma?
@shikijs/engine-oniguruma is an npm package that provides Oniguruma regular expression engine support for the Shiki syntax highlighter. It allows for advanced syntax highlighting by leveraging the Oniguruma regex engine, which is known for its powerful and efficient pattern matching capabilities.
Syntax Highlighting
This feature allows you to perform syntax highlighting on code snippets using the Oniguruma regex engine. The code sample demonstrates how to load the Oniguruma WASM module and use the Shiki highlighter to highlight a JavaScript code snippet.
const { getHighlighter } = require('shiki');
const { loadWASM } = require('@shikijs/engine-oniguruma');
async function highlightCode() {
await loadWASM();
const highlighter = await getHighlighter({
theme: 'nord',
langs: ['javascript']
});
const code = `const x = 10;`;
const highlightedCode = highlighter.codeToHtml(code, { lang: 'javascript' });
console.log(highlightedCode);
}
highlightCode();