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

docs: pass CodeBlock/highlight code + lang in as props, parameter #862

Merged
merged 3 commits into from
Dec 10, 2024

Conversation

karlhorky
Copy link
Contributor

Description

Pass in:

  1. code and language via props for <CodeBlock> component
  2. language via 2nd highlight() function parameter

Linked Issues

--

Additional context

--

Copy link

netlify bot commented Dec 9, 2024

Deploy Preview for shiki-matsu ready!

Name Link
🔨 Latest commit 0cd190a
🔍 Latest deploy log https://app.netlify.com/sites/shiki-matsu/deploys/6757b38266ee6c0008d14eca
😎 Deploy Preview https://deploy-preview-862--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.

Copy link

netlify bot commented Dec 9, 2024

Deploy Preview for shiki-next ready!

Name Link
🔨 Latest commit 0cd190a
🔍 Latest deploy log https://app.netlify.com/sites/shiki-next/deploys/6757b382c799590008cce1e5
😎 Deploy Preview https://deploy-preview-862--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.

@karlhorky karlhorky changed the title docs: pass code and lang in as props, parameter docs: pass CodeBlock/highlight code + lang in as props, parameter Dec 9, 2024
@antfu
Copy link
Member

antfu commented Dec 9, 2024

Could you help to fix the lint? Thanks

@karlhorky
Copy link
Contributor Author

karlhorky commented Dec 9, 2024

@antfu Sure thing - what do you think of the style in this commit:

I guess the only problem here is the extra indentation at the start of each code line in the template string. Maybe we would want to introduce dedent or similar on the code block...?

dedent is what I used here:

export default async function CodeBlock(props: Props) {
  const out = await codeToHast(dedent(props.children), {
    lang: props.language,
    theme: 'dark-plus',
  });

But totally understand if you don't want to introduce new dependencies.

If we shouldn't add any more dependencies, I would probably suggest disabling the react/jsx-curly-brace-presence lint rule for that case I guess... 🤔 Having the code outside of a JSX expression feels unwieldy.

@antfu
Copy link
Member

antfu commented Dec 10, 2024

It's just some demo examples; I think it's fine either way, but I would think it's better not to involve too many concepts all at once. It shouldn't be hard for developers to catch up and fix it, it's a problem unrelated to Shiki so I think it's better to not mention that. I changed it to array join to workaround that.

@antfu antfu merged commit e78c42a into shikijs:main Dec 10, 2024
12 checks passed
@karlhorky
Copy link
Contributor Author

Sounds good, thanks for the review, edit and merge!

@karlhorky karlhorky deleted the patch-1 branch December 10, 2024 08:01
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.

2 participants