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(theme-classic): cleanup of code blocks #6987

Merged
merged 1 commit into from
Mar 25, 2022

Conversation

lex111
Copy link
Contributor

@lex111 lex111 commented Mar 24, 2022

Motivation

Just small cleanups in the code.

Have you read the Contributing Guidelines on pull requests?

Yes

Test Plan

Preview (tests pages)

Related PRs

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

lex111 commented Mar 24, 2022

Wonder if we should remove this language CSS class from the code container, as Prism add it to pre element?

image

@@ -40,7 +40,6 @@ export default function CopyButton({code}: Props): JSX.Element {
description: 'The ARIA label for copy code blocks button',
})
}
// @todo: check it again later
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's settle on using // TODO in the future, because only this can be tracked by my vscode extension:

image

image

@netlify
Copy link

netlify bot commented Mar 24, 2022

[V2]

Name Link
🔨 Latest commit 3a25e2b
🔍 Latest deploy log https://app.netlify.com/sites/docusaurus-2/deploys/623c92fdfbab1600089fe29c
😎 Deploy Preview https://deploy-preview-6987--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.

@Josh-Cena
Copy link
Collaborator

Wonder if we should remove this language CSS class from the code container,

The div one is added by MDX, iirc. It's added again in the CodeBlock component so that the div would still get this class name when used in JSX. You can try removing it in our code, and check if it still appears.

@lex111
Copy link
Contributor Author

lex111 commented Mar 24, 2022

As I can see, MDX doesn't produce any div for code blocks -- all these elements inside code blocks are created inside <CodeBlock>, or am I misunderstanding something? Initially I had a question, why do we need to add another (duplicated) CSS class (see below), if it's already added to the <pre> element automatically.

[`language-${language}`]:
language && !blockClassName.includes(`language-${language}`),

@Josh-Cena
Copy link
Collaborator

Josh-Cena commented Mar 24, 2022

In MDXComponents, we map pre to CodeBlock:

return shouldBeInline ? (
<code {...props} />
) : (
<CodeBlock {...(props as ComponentProps<typeof CodeBlock>)} />
);
}

And language-xxx is part of the default blockClassName. You can experiment by removing that [`language-${language}`]: language && !blockClassName.includes(`language-${language}`), ; I just tried, the language-xxx is indeed still there because it's added by MDX.

@lex111
Copy link
Contributor Author

lex111 commented Mar 25, 2022

Uh-huh, I get it, but then why are we trying to manually add a CSS class with language? Does it mean that [`language-${language}`]: language && !blockClassName.includes(`language-${language}`) can be removed?

@Josh-Cena
Copy link
Collaborator

Because we allow users to use <CodeBlock language="java"> within React pages. If we don't manually apply this class name, that means div.language-java will not be able to consistently target Java code block containers. I doubt if it happens a lot, but it's always good to be consistent.

@slorber
Copy link
Collaborator

slorber commented Mar 25, 2022

🤪 sorry but not sure to understand if this is ready to merge and you both agree or not?

That looks good to me but not 100% sure about the className change

@Josh-Cena
Copy link
Collaborator

The current change looks fair to me. I think language-js needs to stay but the current js class name on the inner content can be removed.

@slorber slorber merged commit c2ac22e into main Mar 25, 2022
@slorber slorber deleted the lex111/code-block-cleanups branch March 25, 2022 11:56
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: 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