-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
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: customize code block line highlight color via CSS var #7176
Conversation
✅ [V2]
To edit notification comments on pull requests, go to your Netlify site settings. |
⚡️ Lighthouse report for the changes in this PR:
Lighthouse ran on https://deploy-preview-7176--docusaurus-2.netlify.app/ |
Size Change: +172 B (0%) Total Size: 799 kB
ℹ️ View Unchanged
|
@@ -139,7 +139,10 @@ export default function CodeBlock({ | |||
}); | |||
|
|||
if (highlightLines.includes(i)) { | |||
lineProps.className += ' docusaurus-highlight-code-line'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if we should keep this stable class, eg to make it easier adding custom styling.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should. In #7178 I'll allow any type of magic comments to be mapped to custom class names, so I think solely for consistency we should keep this class name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then maybe move its definition to theme-common? https://github.com/facebook/docusaurus/blob/main/packages/docusaurus-theme-common/src/utils/ThemeClassNames.ts
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I think that makes sense 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Renamed docusaurus-highlight-code-line
to theme-code-block-highlighted-line
to be more consistent with the current approach.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, while the rename is fine, adding it to ThemeClassNames is unnecessary because in #7178 it will be injected from theme config...
We might change that API later though, so just keep it like this now.
…hlight-code-line-built
LGTM 👍 |
Breaking change
Please migrate your custom CSS file from:
to:
The former class remains available but has been renamed to
theme-code-block-highlighted-line
Motivation
Currently we are asking end-user to add a special class to style highlighted code line themselves, which is quite inconvenient, so I suggest finally walk away from this.
Although we have a problem that the CSS variables defined in built-in Docusaurus component cannot be overridden in the custom CSS file (#3678), however we can lower the specificity of desired selector. And that way it will be possible to set custom background for the highlighted code line via CSS var in the custom file. This is probably better than the current approach.
Have you read the Contributing Guidelines on pull requests?
Yes
Test Plan
Preview
Related PRs