How to use shiki - 2 common examples

To help you get started, we’ve selected a few shiki examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github EldoranDev / gridsome-plugin-remark-shiki / index.js View on Github external
function highlight ({ value, lang }, cls, highlighter) {
  const index = languages.findIndex((x) => x === lang)
  const theme = shiki.getTheme('nord')

  if (index >= 0) {
    return highlighter.codeToHtml(value, lang)
  }

  // Fallback for unknown languages.
  return `<code style="background: ${theme.bg}; color: ${theme.colors['terminal.foreground']}" class="${cls}">${escape(value)}</code>`
}
github EldoranDev / gridsome-plugin-remark-shiki / index.js View on Github external
return async tree => {
    const highlighter = await shiki.getHighlighter({
      theme,
      langs: languages
    })

    visit(tree, 'code', node => {
      node.type = 'html'
      try {
        node.value = highlight(node, CLASS_BLOCK, highlighter)
      } catch (e) {
        node.value = ERROR_MESSAGE
      }
    })

    if (!options.skipInline) {
      visit(tree, 'inlineCode', node => {
        node.type = 'html'

shiki

A beautiful Syntax Highlighter.

MIT
Latest version published 4 days ago

Package Health Score

100 / 100
Full package analysis

Popular shiki functions