shikijs / shiki

A beautiful yet powerful syntax highlighter
http://shiki.style/
MIT License
9.19k stars 330 forks source link

Color replacement in multiple theme modes #679

Closed QuentinRoy closed 1 month ago

QuentinRoy commented 1 month ago

Clear and concise description of the problem

The colorReplacements applies to every themes, there is no way to specify replacements for one particular theme only. This can be quite problematic when multi-themes are provided (e.g. light and dark).

Suggested solution

colorReplacements options could be namespaced with the name of the theme, for example:

{
  lang: "js",
  themes: { dark: "min-dark", light: "min-light" },
  colorReplacements: {
    "min-light": {
      "#ff79c6": "#189eff",
    },
  },
}

Alternative

colorReplacements could also be a property of themes

{
  lang: "js",
  themes: {
    dark: {
      name: "min-dark",
      builtIn: true,
      colorReplacements: {
        "#ff79c6": "#189eff",
      },
    },
    light: "min-light",
  },
}

I added the builtIn property as well, since without it, the theme wouldn't be recognized as a built-in theme.

Additional context

No response

Validations

Contributes

antfu commented 1 month ago

Good points. I think the first approach make sense to me, PR welcome!

QuentinRoy commented 1 month ago

Should it be namespaced by the name of the theme (in the exampel above "min-light") or its label (in the example above "light"? I tend to feel it makes more sense to use the name of the theme since change to the applied theme is likely to render most color replacements deprecated, and leaving it as is would probably be an error.

antfu commented 1 month ago

I would vote for the name of the theme - so you users could have a single replacement registry for every theme without being bound to the ones being assigned temporarily.