V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
爱意满满的作品展示区。
octref
V2EX  ›  分享创造

Shiki — A beautiful Syntax Highlighter

  •  1
     
  •   octref ·
    octref · 2019-01-04 13:41:32 +08:00 · 2389 次点击
    这是一个创建于 1931 天前的主题,其中的信息可能已经有所发展或是发生改变。

    Shiki

    VS Code / 旧版 Atom / Sublime Text / TextMate 使用的都是 Oniguruma 和 TextMate grammar 來做 syntax highlighting。在各种 API 文档以及博客上,大家现在使用的一般是 Highlight.js 或者 Prism.js ,但它们的缺点是:

    • 无法达到 TextMate grammar + TextMate theme 高亮的准确性。
    • 无法使用 VS Code 的 theme。

    最近有人把 Oniguruma 编译成 WASM,于是就基于这个做了一个 Syntax Highlighter。

    各位可以试试用于自己的 static site generator。
    GitHub 欢迎 star / feature-request / issue。


    shiki

    TS Handbook in Material Theme:

    ts handbook material theme

    4 条回复    2019-01-04 14:09:37 +08:00
    MartinWu
        1
    MartinWu  
       2019-01-04 13:50:24 +08:00
    vscode 用户表示,我可以怎么用这个东西?
    octref
        2
    octref  
    OP
       2019-01-04 14:00:37 +08:00
    @MartinWu

    - `yarn add shiki`
    - 按 demo 或者 GitHub 里的例子运行,比如:

    ```js
    const shiki = require('shiki')

    shiki.getHighlighter({
    theme: 'nord'
    }).then(highlighter => {
    console.log(highlighter.codeToHtml(`console.log('shiki');`, 'js'))
    })
    ```
    MartinWu
        3
    MartinWu  
       2019-01-04 14:02:39 +08:00
    @octref #2 完全不懂。。。路过好了。
    aaronly
        4
    aaronly  
       2019-01-04 14:09:37 +08:00
    nice, 关注了
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5619 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 01:46 · PVG 09:46 · LAX 18:46 · JFK 21:46
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.