Skip to content

加载自定义主题

请先查看所有内建主题

你可以通过向 themes 数组传递一个 Theme 对象来载入自定义主题。

ts
import {  } from 'shiki'

const  = {
  : 'my-theme',
  : [
    {
      : ['comment'],
      : {
        : '#888'
      }
    },
    // ...
  ]
}

const  = await ({
  : [],
  : [],
})

const  = `console.log('hello')`
const  = .(, {
  : 'javascript',
  : 'my-theme'
})

同样的,你也可以在高亮器创建后载入自定义主题。

ts
import {  } from 'shiki'

// 从文件、网络请求或其他任何地方载入主题对象
const  = .(fs.readFileSync('my-theme.json', 'utf8'))

const  = await ({
  : ['javascript'],
  : [],
})

await .() // <--

const  = `console.log('hello')`
const  = .(, {
  : 'javascript',
  : 'my-theme'
})

主题是一个 JavaScript 对象形式的 TextMate 主题,它看起来像这样