Skip to content

Fix Code.astro shiki css class replace logic#5829

Merged
bluwy merged 2 commits into
withastro:mainfrom
giuseppelt:patch-1
Jan 11, 2023
Merged

Fix Code.astro shiki css class replace logic#5829
bluwy merged 2 commits into
withastro:mainfrom
giuseppelt:patch-1

Conversation

@giuseppelt
Copy link
Copy Markdown
Contributor

@giuseppelt giuseppelt commented Jan 11, 2023

Changes

The replace uses a regex witch matches anything extra and adds it back to the css class.

Closes #5828

Testing

As mentioned in the linked issue #5828, the actual pinned shiki version v0.11 does work. The v0.12 causes the bug, as a new feature shikijs/shiki#376 adds an extra css class, making the actual logic to fail.

There's a test already in place

it('<Code theme="...">', async () => {
let html = await fixture.readFile('/custom-theme/index.html');
const $ = cheerio.load(html);
expect($('pre')).to.have.lengthOf(1);
expect($('pre').attr('class')).to.equal('astro-code');
and it will fail when shiki gets updated to v0.12. This PR resolves the issue.

Docs

The replace uses a regex witch matches anything extra, and adds it back to the css class.

Closes #5828
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Jan 11, 2023

🦋 Changeset detected

Latest commit: 69b872c

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions Bot added the pkg: astro Related to the core `astro` package (scope) label Jan 11, 2023
Comment thread packages/astro/components/Code.astro Outdated
Co-authored-by: Bjorn Lu <bjornlu.dev@gmail.com>
Copy link
Copy Markdown
Member

@bluwy bluwy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pkg: astro Related to the core `astro` package (scope)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Code.astro component no longer set .astro-code css class

2 participants