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

Refactor createShikiHighlighter #11825

Merged
merged 4 commits into from
Sep 2, 2024
Merged

Refactor createShikiHighlighter #11825

merged 4 commits into from
Sep 2, 2024

Conversation

bluwy
Copy link
Member

@bluwy bluwy commented Aug 23, 2024

Changes

(Disable whitespace diff recommended)

  • Refactors the createShikiHighlighter API to:
    • return codeToHast and codeToHtml. The hast version allows the rehype plugin to syntax highlight more efficiently. Before it's hast -> text -> (highlight) hast -> html -> hast , now it's hast -> text -> (highlight) hast.
    • reduce initial options surface as they aren't needed for the creation of the shiki highlighter. This allows the <Code/> component to key by lesser values and improve sharing the cached highlighter.

Testing

Existing tests should pass. Also edited stuff due to new API names.

Docs

There's a few changesets, but .changeset/large-zebras-sniff.md is the main one for the astro major, which will go in the migration guide.

Copy link

changeset-bot bot commented Aug 23, 2024

🦋 Changeset detected

Latest commit: 65bb472

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 feat: markdown Related to Markdown (scope) pkg: integration Related to any renderer integration (scope) pkg: astro Related to the core `astro` package (scope) semver: major Change triggers a `major` release labels Aug 23, 2024
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

This PR is blocked because it contains a major changeset. A reviewer will merge this at the next release if approved.

@bluwy bluwy dismissed github-actions[bot]’s stale review August 27, 2024 14:58

base branch is next (still awaiting docs review before merging)

// We just generated this node, so any positional information is invalid.
removePosition(replacement);
} else {
replacement = result.children[0] as Element;
Copy link
Contributor

Choose a reason for hiding this comment

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

is this cast safe? we know there's at least 1 child and its an Element?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah it should be. We currently control this function (it's mostly internal details for Shiki only), so if it changes we can also tweak this here.

Copy link
Contributor

@matthewp matthewp left a comment

Choose a reason for hiding this comment

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

just the one thing to confirm, otherwise lgtm

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

This PR is blocked because it contains a major changeset. A reviewer will merge this at the next release if approved.

Copy link
Member

@sarah11918 sarah11918 left a comment

Choose a reason for hiding this comment

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

Thanks @bluwy ! Just made some suggestions for your consideration that try to highlight more when someone might encounter the problem, because Shiki is pretty commonly used, but maybe transformers not quite as much! So something like this makes it maybe more obvious when someone needs to care and pay attention.

.changeset/large-zebras-sniff.md Outdated Show resolved Hide resolved
.changeset/large-zebras-sniff.md Outdated Show resolved Hide resolved
.changeset/large-zebras-sniff.md Outdated Show resolved Hide resolved
Co-authored-by: Sarah Rainsberger <[email protected]>
@bluwy bluwy merged commit 560ef15 into next Sep 2, 2024
13 checks passed
@bluwy bluwy deleted the plt-1946-refactor-shiki branch September 2, 2024 13:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat: markdown Related to Markdown (scope) pkg: astro Related to the core `astro` package (scope) pkg: integration Related to any renderer integration (scope) semver: major Change triggers a `major` release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants