marp-team / marp-core

The core of Marp converter
MIT License
766 stars 129 forks source link

[v4?] New code highlighter #296

Open yhatt opened 2 years ago

yhatt commented 2 years ago

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

https://github.com/marp-team/marp-core/issues/194#issuecomment-1122164223 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.

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.

yhatt commented 1 week ago

The latest Shiki v1.15.0 has been introduced experimental JavaScript RegExp Engine. This may become a huge step for this task.

An concern of using Shiki highilghter is depending on Oniguruma RegExp engine to recognize TextMate JSON. That is provided by WASM, and not supporting non-asynchronous function that is only supported by markdown-it API. The JavaScript RegExp engine could become to remove that dependency, support sync function, and make simplify the architecture.