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: customize code block line highlight color via CSS var #7176

Merged
merged 6 commits into from
Apr 21, 2022

Conversation

lex111
Copy link
Contributor

@lex111 lex111 commented Apr 15, 2022

Breaking change

Please migrate your custom CSS file from:

.docusaurus-highlight-code-line {
  background-color: rgb(72, 77, 91);
}

[data-theme='dark'] .docusaurus-highlight-code-line {
  background-color: rgb(100, 100, 100);
}

to:

:root {
  --docusaurus-highlighted-code-line-bg: rgb(72, 77, 91);
}

[data-theme='dark'] {
  --docusaurus-highlighted-code-line-bg: rgb(100, 100, 100);
}

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

@lex111 lex111 added the pr: polish This PR adds a very minor behavior improvement that users will enjoy. label Apr 15, 2022
@facebook-github-bot facebook-github-bot added the CLA Signed Signed Facebook CLA label Apr 15, 2022
@netlify
Copy link

netlify bot commented Apr 15, 2022

[V2]

Name Link
🔨 Latest commit ca53c66
🔍 Latest deploy log https://app.netlify.com/sites/docusaurus-2/deploys/6259712bbee5ff00081e63a1
😎 Deploy Preview https://deploy-preview-7176--docusaurus-2.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 settings.

@github-actions
Copy link

github-actions bot commented Apr 15, 2022

⚡️ Lighthouse report for the changes in this PR:

Category Score
🟠 Performance 59
🟢 Accessibility 100
🟢 Best practices 92
🟢 SEO 100
🟢 PWA 90

Lighthouse ran on https://deploy-preview-7176--docusaurus-2.netlify.app/

@github-actions
Copy link

github-actions bot commented Apr 15, 2022

Size Change: +172 B (0%)

Total Size: 799 kB

Filename Size Change
website/build/assets/css/styles.********.css 106 kB +172 B (0%)
ℹ️ View Unchanged
Filename Size
website/.docusaurus/globalData.json 50 kB
website/build/assets/js/main.********.js 604 kB
website/build/index.html 38.8 kB

compressed-size-action

@@ -139,7 +139,10 @@ export default function CodeBlock({
});

if (highlightLines.includes(i)) {
lineProps.className += ' docusaurus-highlight-code-line';
Copy link
Contributor Author

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.

Copy link
Collaborator

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Collaborator

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 👍

Copy link
Contributor Author

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.

Copy link
Collaborator

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.

@Josh-Cena Josh-Cena changed the title refactor: make changeable bg color highlighted code line via CSS var refactor: customize code block line highlight color via CSS var Apr 15, 2022
@lex111 lex111 added the pr: breaking change Existing sites may not build successfully in the new version. Description contains more details. label Apr 15, 2022
@slorber
Copy link
Collaborator

slorber commented Apr 21, 2022

LGTM 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed Signed Facebook CLA pr: breaking change Existing sites may not build successfully in the new version. Description contains more details. pr: polish This PR adds a very minor behavior improvement that users will enjoy.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants