Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v4?] New code highlighter #296

Open
yhatt opened this issue May 10, 2022 · 0 comments
Open

[v4?] New code highlighter #296

yhatt opened this issue May 10, 2022 · 0 comments
Labels
enhancement New feature or request

Comments

@yhatt
Copy link
Member

yhatt commented May 10, 2022

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

  • 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.

@yhatt yhatt added the enhancement New feature or request label May 10, 2022
@yhatt yhatt changed the title [v4] New code highlighter [v4?] New code highlighter Aug 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: Todo
Development

No branches or pull requests

1 participant