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

@shikijs/rehype: theme background and color not applied to plain text blocks #805

Open
3 of 5 tasks
karlhorky opened this issue Oct 9, 2024 · 1 comment
Open
3 of 5 tasks

Comments

@karlhorky
Copy link
Contributor

Validations

Describe the bug

Using @shikijs/rehype, a text / txt / plain code block will appear without background or color from the theme specified:

next.config.ts

import rehypeShiki from '@shikijs/rehype';

// ...

[
  rehypeShiki,
  {
    theme: 'dark-plus',
    addLanguageClass: true,
  },
],

MDX:

```sql
CREATE TABLE animals (
  id integer PRIMARY KEY GENERATED ALWAYS AS IDENTITY,
  slug varchar(80) UNIQUE NOT NULL,
  name varchar(80) NOT NULL
);

SELECT
  *
FROM
  animals;

-- id | slug   | name
-- ---|--------|------
-- 13 | lucia  | Lucia
-- 34 | macca  | Macca
```

```txt
https://example.com/animals/lucia
https://example.com/animals/macca
```

Screenshot 2024-10-09 at 18 53 48

Reproduction

https://github.com/karlhorky/repro-shikijs-rehype-text-theme-styles-not-visible

Contributes

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

karlhorky commented Oct 9, 2024

Workaround

Use pre:has(> code.language-txt) selector to manually apply background and color matching your theme:

/**
 * Apply dark-plus background and color for plain text code blocks
 *
 * TODO: Remove if @shikijs/rehype is updated to do this out of the box:
 * - https://github.com/shikijs/shiki/issues/805
 *
 */
pre:has(> code.language-txt) {
  @apply bg-[#1E1E1E] text-[#D4D4D4];
}

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

1 participant