Skip to content

[v4.x] New code highlighter #296

@yhatt

Description

@yhatt

Related: marp-team/marp#103, #194

Let's start to think new architecture for code highlight toward Marp Core v4.

CSS variables based coloring

highlight.js based highlighting has high flexibility that came from stylabillity based on CSS class.

On the other hand, it is hard than expected to overload exist color scheme by the context. If the theme author wanted to use different highlight colors in section.invert, required reverting all styles about highlight.js and adding styles for changed colors.

When using theme inheritance by @import, need to know all of styles using for highlight in the parent theme and revert them surely.

I think it's painful for the custom theme author, so providing much better coloring system in code highlight would be best. https://github.com/orgs/marp-team/discussions/103#discussioncomment-702465

If Marp adopted CSS variables for code highlighting, changing color scheme by class context would be drastically simpler. It also means to deny detailed styling for highlighted keywords through CSS properties, but it's a corner case in the syntax highlight.

highlight.js -> Shiki

#194 (comment) has suggested a modern highlighter Shiki, made on TextMate json and Oniguruma RegExp engine.

Concerns

In future, this concern may become to resolve by adopting JavaScript RegExp instead of Oniguruma.

  • Deasync for loading highlight engine (markdown-it/Marpit does not support Promise in rendering for now)
    • Node.js: synckit (similar to deasync but requires no native bindings or node-gyp)
    • Browser: nothing
      • Inject an inline Web Worker when initializing Marp for deasync
      • Or consider to return thenable proxy object in Marp.render()
    • (We are already planning the next-gen engine of Marpit to support async/await while rendering)
  • Oniguruma WASM
    • Browser requires to fetch WASM from CDN that is supported CORS (jsDelivr, unpkg, etc)

Extended syntax for code fence

CommonMark defines the info string for fenced code block, like ```javascript. It leaves to Markdown processors about how to use this string, so may add more useful features to Marp.

We need work to them carefully because complexity of Marp Core theme CSS will increase at the same time.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    Status

    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions