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

[🐞BUG]: colorReplacements not working on the <pre> container #641

Closed
3 of 5 tasks
xsjcTony opened this issue Mar 26, 2024 · 3 comments
Closed
3 of 5 tasks

[🐞BUG]: colorReplacements not working on the <pre> container #641

xsjcTony opened this issue Mar 26, 2024 · 3 comments

Comments

@xsjcTony
Copy link

Validations

Describe the bug

Please refer to the reproduction, it's pretty clear.

Reproduction

https://stackblitz.com/edit/vitejs-vite-4byr7f?file=src%2Fmain.ts

Contributes

  • I am willing to submit a PR to fix this issue
  • I am willing to submit a PR with failing tests
@xsjcTony xsjcTony changed the title colorReplacements not working on the <pre> container [🐞BUG]: colorReplacements not working on the <pre> container Mar 26, 2024
@hddhyq
Copy link
Contributor

hddhyq commented Mar 26, 2024

It seems that colorReplacements is only used to replace code colors, you should use the bg property to replace the background color.

document.querySelector<HTMLDivElement>('#app')!.innerHTML = await codeToHtml(
  JSON.stringify(obj, null, 2),
  {
    lang: 'json',
    theme: {
      name: 'one-dark-pro',
      bg: '#ff0000', // change the bg
    },
    colorReplacements: {
      // This doesn't work (color on container)
      '#282c34': '#ff0000',
      // This works
      '#e06c75': '#00ffff',
    },
  }
);

@xsjcTony
Copy link
Author

xsjcTony commented Mar 26, 2024

How can I change the bg color for dual theme then? I only want to change the dark one.
This is my usage.

highlighter.codeToHtml(JSON.stringify(parsedJson, null, 2), {
  lang: 'json',
  themes: {
    light: 'vitesse-light',
    dark: 'material-theme-palenight',
  },
  colorReplacements: { '#282c34': '#141414' },
});

This doesn't seem to work:

highlighter.codeToHtml(JSON.stringify(parsedJson, null, 2), {
  lang: 'json',
  themes: {
    light: 'vitesse-light',
    dark: {
      name: 'material-theme-palenight',
      bg: '#141414',
    },
  },
});

@xsjcTony
Copy link
Author

It seems that colorReplacements is only used to replace code colors, you should use the bg property to replace the background color.

document.querySelector<HTMLDivElement>('#app')!.innerHTML = await codeToHtml(
  JSON.stringify(obj, null, 2),
  {
    lang: 'json',
    theme: {
      name: 'one-dark-pro',
      bg: '#ff0000', // change the bg
    },
    colorReplacements: {
      // This doesn't work (color on container)
      '#282c34': '#ff0000',
      // This works
      '#e06c75': '#00ffff',
    },
  }
);

This won't work either, since if you use object as theme, it means a custom theme, the registered theme string as name won't work

@antfu antfu closed this as completed in bb47a84 Apr 1, 2024
diegohaz pushed a commit to ariakit/ariakit that referenced this issue Apr 13, 2024
[![Mend
Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
| [shiki](https://togithub.com/shikijs/shiki)
([source](https://togithub.com/shikijs/shiki/tree/HEAD/packages/shiki))
| [`1.2.0` ->
`1.3.0`](https://renovatebot.com/diffs/npm/shiki/1.2.0/1.3.0) |
[![age](https://developer.mend.io/api/mc/badges/age/npm/shiki/1.3.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![adoption](https://developer.mend.io/api/mc/badges/adoption/npm/shiki/1.3.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![passing](https://developer.mend.io/api/mc/badges/compatibility/npm/shiki/1.2.0/1.3.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/shiki/1.2.0/1.3.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|

---

### Release Notes

<details>
<summary>shikijs/shiki (shiki)</summary>

### [`v1.3.0`](https://togithub.com/shikijs/shiki/releases/tag/v1.3.0)

[Compare
Source](https://togithub.com/shikijs/shiki/compare/v1.2.4...v1.3.0)

#####    🚀 Features

- **core**: New `structure: inline` option for `codeToHast`  -  by
[@&#8203;antfu](https://togithub.com/antfu) in
[shikijs/shiki#653
[<samp>(ae516)</samp>](https://togithub.com/shikijs/shiki/commit/ae516aec)

#####     [View changes on
GitHub](https://togithub.com/shikijs/shiki/compare/v1.2.4...v1.3.0)

### [`v1.2.4`](https://togithub.com/shikijs/shiki/releases/tag/v1.2.4)

[Compare
Source](https://togithub.com/shikijs/shiki/compare/v1.2.3...v1.2.4)

*No significant changes*

#####     [View changes on
GitHub](https://togithub.com/shikijs/shiki/compare/v1.2.3...v1.2.4)

### [`v1.2.3`](https://togithub.com/shikijs/shiki/releases/tag/v1.2.3)

[Compare
Source](https://togithub.com/shikijs/shiki/compare/v1.2.2...v1.2.3)

#####    🐞 Bug Fixes

- `colorReplacements` also for `bg` and `fg`, close
[#&#8203;641](https://togithub.com/shikijs/shiki/issues/641)  -  by
[@&#8203;antfu](https://togithub.com/antfu) in
[shikijs/shiki#641
[<samp>(bb47a)</samp>](https://togithub.com/shikijs/shiki/commit/bb47a846)

#####     [View changes on
GitHub](https://togithub.com/shikijs/shiki/compare/v1.2.2...v1.2.3)

### [`v1.2.2`](https://togithub.com/shikijs/shiki/releases/tag/v1.2.2)

[Compare
Source](https://togithub.com/shikijs/shiki/compare/v1.2.1...v1.2.2)

#####    🚀 Features

- Update deps, new `tsv` grammar  -  by
[@&#8203;antfu](https://togithub.com/antfu)
[<samp>(a7ca7)</samp>](https://togithub.com/shikijs/shiki/commit/a7ca7c32)

#####    🐞 Bug Fixes

- **monaco**: Typo on interface  -  by
[@&#8203;ije](https://togithub.com/ije) in
[shikijs/shiki#644
[<samp>(1fc70)</samp>](https://togithub.com/shikijs/shiki/commit/1fc70bd3)

#####    🏎 Performance

- **shiki-monaco**: Improve tokenizer performance  -  by
[@&#8203;ije](https://togithub.com/ije) in
[shikijs/shiki#645
[<samp>(069e0)</samp>](https://togithub.com/shikijs/shiki/commit/069e0be7)

#####     [View changes on
GitHub](https://togithub.com/shikijs/shiki/compare/v1.2.1...v1.2.2)

### [`v1.2.1`](https://togithub.com/shikijs/shiki/releases/tag/v1.2.1)

[Compare
Source](https://togithub.com/shikijs/shiki/compare/v1.2.0...v1.2.1)

#####    🐞 Bug Fixes

- **vitepress-twoslash**: Pass `options.twoslashOptions` to
`createTwoslasher`  -  by
[@&#8203;sapphi-red](https://togithub.com/sapphi-red) in
[shikijs/shiki#637
[<samp>(75832)</samp>](https://togithub.com/shikijs/shiki/commit/75832e13)

#####     [View changes on
GitHub](https://togithub.com/shikijs/shiki/compare/v1.2.0...v1.2.1)

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined),
Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you
are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Mend
Renovate](https://www.mend.io/free-developer-tools/renovate/). View
repository job log
[here](https://developer.mend.io/github/ariakit/ariakit).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy4yNjkuMiIsInVwZGF0ZWRJblZlciI6IjM3LjI2OS4yIiwidGFyZ2V0QnJhbmNoIjoibWFpbiJ9-->

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants