V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
爱意满满的作品展示区。
octref

Shiki — A beautiful Syntax Highlighter

  •  1
     
  •   octref ·
    octref · Jan 4, 2019 · 3281 views
    This topic created in 2670 days ago, the information mentioned may be changed or developed.

    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 replies    2019-01-04 14:09:37 +08:00
    MartinWu
        1
    MartinWu  
       Jan 4, 2019
    vscode 用户表示,我可以怎么用这个东西?
    octref
        2
    octref  
    OP
       Jan 4, 2019
    @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  
       Jan 4, 2019
    @octref #2 完全不懂。。。路过好了。
    aaronly
        4
    aaronly  
       Jan 4, 2019
    nice, 关注了
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5628 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 40ms · UTC 08:52 · PVG 16:52 · LAX 01:52 · JFK 04:52
    ♥ Do have faith in what you're doing.