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

ansi highlighting not working with theme dark-plus #597

Closed
5 tasks done
chwzr opened this issue Feb 20, 2024 · 2 comments · May be fixed by NOUIY/nodejs.org#1313, NOUIY/nodejs.org#1322, NOUIY/nodejs.org#1331, NOUIY/nodejs.org#1340 or NOUIY/nodejs.org#1349

Comments

@chwzr
Copy link
Contributor

chwzr commented Feb 20, 2024

Validations

Describe the bug

When using theme dark-plus and language ansi together shiki fails to render anything with following error:

index.js:27 TypeError: Cannot read properties of undefined (reading 'toLowerCase')
    at applyColorReplacements (index.mjs:125:33)
    at eval (index.mjs:460:17)
    at Array.map (<anonymous>)
    at eval (index.mjs:449:52)
    at Array.map (<anonymous>)
    at tokenizeAnsiWithTheme (index.mjs:449:18)
    at _codeToTokensBase (index.mjs:518:16)
    at _codeToTokens (index.mjs:771:18)
    at _codeToHast (index.mjs:1003:53)
    at _codeToHtml (index.mjs:4564:25)
    at Object.codeToHtml (index.mjs:5357:40)
    at _callee9$ (index.mjs:5441:26)
    at tryCatch (regeneratorRuntime.js:45:16)
    at Generator.eval (regeneratorRuntime.js:133:17)
    at Generator.eval [as next] (regeneratorRuntime.js:74:21)
    at asyncGeneratorStep (asyncToGenerator.js:3:24)
    at _next (asyncToGenerator.js:22:9)

Other themes are working fine (e.g. monokai). Included a simple Reproduction Code Sandbox.

Reproduction

https://codesandbox.io/p/sandbox/dark-plus-ansi-8qkpwj?file=%2Fsrc%2Findex.ts%3A1%2C1-20%2C1

Contributes

  • I am willing to submit a PR to fix this issue
  • I am willing to submit a PR with failing tests
@chwzr
Copy link
Contributor Author

chwzr commented Feb 20, 2024

Figured out that adding optional chaining operator to color.toLowerCase() will make highlighting work.

export function applyColorReplacements(color: string, replacements?: Record<string, string>): string {
return replacements?.[color.toLowerCase()] || color
}

@chwzr
Copy link
Contributor Author

chwzr commented Feb 20, 2024

I've implemented a PR for this. Please let me know if this fix is acceptable or if you think there is another way to fix it.

@antfu antfu closed this as completed in ccb5833 Feb 21, 2024
diegohaz referenced this issue in ariakit/ariakit Mar 1, 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://github.com/shikijs/shiki)
([source](https://github.com/shikijs/shiki/tree/HEAD/packages/shiki))
| [`1.1.6` ->
`1.1.7`](https://renovatebot.com/diffs/npm/shiki/1.1.6/1.1.7) |
[![age](https://developer.mend.io/api/mc/badges/age/npm/shiki/1.1.7?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![adoption](https://developer.mend.io/api/mc/badges/adoption/npm/shiki/1.1.7?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![passing](https://developer.mend.io/api/mc/badges/compatibility/npm/shiki/1.1.6/1.1.7?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/shiki/1.1.6/1.1.7?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|

---

### Release Notes

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

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

[Compare
Source](https://github.com/shikijs/shiki/compare/v1.1.6...v1.1.7)

#####    🐞 Bug Fixes

- Allow nullish color for colorReplacement, fix ansi highlighting with
dark-plus, fix
[#&#8203;597](https://github.com/shikijs/shiki/issues/597)  -  by
[@&#8203;chwzr](https://github.com/chwzr) in
[https://github.com/shikijs/shiki/issues/598](https://github.com/shikijs/shiki/issues/598)
and
[https://github.com/shikijs/shiki/issues/597](https://github.com/shikijs/shiki/issues/597)
[<samp>(ccb58)</samp>](https://github.com/shikijs/shiki/commit/ccb58331)

#####     [View changes on
GitHub](https://github.com/shikijs/shiki/compare/v1.1.6...v1.1.7)

</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:eyJjcmVhdGVkSW5WZXIiOiIzNy4yMDAuMCIsInVwZGF0ZWRJblZlciI6IjM3LjIwMC4wIiwidGFyZ2V0QnJhbmNoIjoibWFpbiJ9-->

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