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

feat(rehype): support inline codes #751

Merged
merged 6 commits into from
Aug 22, 2024
Merged

feat(rehype): support inline codes #751

merged 6 commits into from
Aug 22, 2024

Conversation

fuma-nama
Copy link
Contributor

@fuma-nama fuma-nama commented Aug 20, 2024

Description

Support to highlight inline codes with code{:language} syntax.

It isn't enabled by default to avoid problems when people upgrading from older versions of Shiki.
The output is basically same as normal code blocks but with pre replaced by a span element.

<span class="shiki ...">
<code>...</code>
</span>

Linked Issues

#660

Additional context

Should we give additional information to transformers, or allow to pass different options for inline code highlighting?

Copy link

netlify bot commented Aug 20, 2024

Deploy Preview for shiki-next ready!

Name Link
🔨 Latest commit 4d81712
🔍 Latest deploy log https://app.netlify.com/sites/shiki-next/deploys/66c745f3308bd9000832406f
😎 Deploy Preview https://deploy-preview-751--shiki-next.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

netlify bot commented Aug 20, 2024

Deploy Preview for shiki-matsu ready!

Name Link
🔨 Latest commit 4d81712
🔍 Latest deploy log https://app.netlify.com/sites/shiki-matsu/deploys/66c745f32394780008f7c60e
😎 Deploy Preview https://deploy-preview-751--shiki-matsu.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@fuma-nama fuma-nama marked this pull request as ready for review August 20, 2024 14:34
@jcayzac
Copy link

jcayzac commented Aug 21, 2024

Using the proposed syntax code{:language} makes the plugin incompatible with MDX.

@fuma-nama
Copy link
Contributor Author

image

Hmm it should work on both markdown, MDX, and probably the markdown syntax of Vitepress too.

`console.log("Hello World"){:js}`

packages/rehype/src/core.ts Outdated Show resolved Hide resolved
packages/rehype/src/core.ts Outdated Show resolved Hide resolved
@fuma-nama fuma-nama requested a review from antfu August 21, 2024 15:09
@jcayzac
Copy link

jcayzac commented Aug 21, 2024

Is this just for lang? How do you pass the rest of the meta string? e.g. js /Hello/ when using transformerMetaWordHighlight ?

@fuma-nama
Copy link
Contributor Author

It doesn't work with transformers, I would just suggest to use code blocks if you want to use them.

@jcayzac
Copy link

jcayzac commented Aug 22, 2024

It doesn't work with transformers, I would just suggest to use code blocks if you want to use them.

Why not making it work?

Using code blocks for inline code isn't really an option.

@fuma-nama
Copy link
Contributor Author

fuma-nama commented Aug 22, 2024

It should be discussed in a separate issue with enough details on how transformers can be re-implemented for inline codes, and it makes no sense to use transformers like line highlight, focus on an inline code. Twoslash, notation transformers cannot even work without multiline code blocks, I'd say it's probably useless and further discussion is needed.

For now, it's better to avoid changes on transformer API

Copy link

codecov bot commented Aug 22, 2024

Codecov Report

Attention: Patch coverage is 94.06780% with 7 lines in your changes missing coverage. Please review.

Project coverage is 94.58%. Comparing base (bbf37b1) to head (4d81712).
Report is 1 commits behind head on main.

Files Patch % Lines
packages/rehype/src/core.ts 92.70% 7 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #751      +/-   ##
==========================================
+ Coverage   94.52%   94.58%   +0.05%     
==========================================
  Files          64       65       +1     
  Lines        3874     3931      +57     
  Branches      859      870      +11     
==========================================
+ Hits         3662     3718      +56     
- Misses        207      208       +1     
  Partials        5        5              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@antfu antfu merged commit 6ca98aa into shikijs:main Aug 22, 2024
12 of 13 checks passed
@jcayzac
Copy link

jcayzac commented Aug 23, 2024

@fuma-nama

it makes no sense to use transformers like line highlight, focus on an inline code.

I use transformerMetaWordHighlight in inline code (I pass the meta programmatically, using a component, not through rehype).

I don't understand the point about avoiding changes on transformer API being better. That's my point exactly. There's nothing special about inline code.

@fuma-nama
Copy link
Contributor Author

fuma-nama commented Aug 23, 2024

Because this PR is about the Rehype integration of Shiki, you can also contribute by opening a PR.

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

Successfully merging this pull request may close these issues.

3 participants