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

[Feature]: enable code-wrapping for shiki-highlighting #1619

Open
ap0nia opened this issue Nov 21, 2024 · 2 comments
Open

[Feature]: enable code-wrapping for shiki-highlighting #1619

ap0nia opened this issue Nov 21, 2024 · 2 comments

Comments

@ap0nia
Copy link
Contributor

ap0nia commented Nov 21, 2024

What problem does this feature solve?

It was possible to enable wrapping with shiki-highlighting by conditionally adding "white-space: pre" to the code element.

However, this could cause breaking changes for people that don't want this style applied to their shiki codeblock. Alternatively, a data attribute could be attached to the element, and the user can apply css targeting it.

What does the proposed API look like?

  1. If the code block should be wrapped, apply a data-rp-code-wrapped=true attribute to the element.
<code {...props} data-rp-code-wrapped={codeWrapped}></code>
  1. The user can write custom CSS for that data-attribute.
code[data-rs-code-wrapped="true"] {
  white-space: pre-wrap;
}

Alternatively, always apply the white-space style for them, but allow it to be overridden. Or do both strategies; always apply the white-space style, but add a data-attribute that's easy to override the default styles from CSS.

<code style={{ whiteSpace: codeWrap ? 'pre-wrap' : undefined }} {...props} data-rp-code-wrapped={codeWrapped}></code>
@Timeless0911
Copy link
Collaborator

How about adding a specific classname for it? like rspress-shiki-code.

@ap0nia
Copy link
Contributor Author

ap0nia commented Nov 21, 2024

That makes sense too, and I think there should be a specific class that's applied when the code is wrapped. e.g. rspress-shiki-code-wrapped.

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

No branches or pull requests

2 participants