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

feat(theme-common): stable classname for code blocks #6125

Merged
merged 4 commits into from
Dec 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
parseCodeBlockTitle,
parseLanguage,
parseLines,
ThemeClassNames,
} from '@docusaurus/theme-common';
import usePrismTheme from '@theme/hooks/usePrismTheme';
import type {Props} from '@theme/CodeBlock';
Expand Down Expand Up @@ -72,7 +73,12 @@ export default function CodeBlock({
code={code}
language={language}>
{({className, style, tokens, getLineProps, getTokenProps}) => (
<div className={clsx(styles.codeBlockContainer, blockClassName)}>
<div
className={clsx(
styles.codeBlockContainer,
blockClassName,
ThemeClassNames.common.codeBlock,
)}>
{codeBlockTitle && (
<div style={style} className={styles.codeBlockTitle}>
{codeBlockTitle}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,19 @@
font-size: var(--ifm-code-font-size);
font-weight: 500;
padding: 0.75rem var(--ifm-pre-padding);
border-top-left-radius: var(--ifm-global-radius);
border-top-right-radius: var(--ifm-global-radius);
}

.codeBlockTitle + .codeBlockContent .codeBlock {
border-top-left-radius: 0;
border-top-right-radius: 0;
}

.codeBlock {
margin: 0;
padding: 0;
border-radius: 0;
border-radius: var(--ifm-global-radius);
}

.copyButton {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export const ThemeClassNames = {
editThisPage: 'theme-edit-this-page',
lastUpdated: 'theme-last-updated',
backToTopButton: 'theme-back-to-top-button',
codeBlock: 'theme-code-block',
},
layout: {
// TODO add other stable classNames here
Expand Down
1 change: 1 addition & 0 deletions website/docs/styling-layout.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ import CodeBlock from '@theme/CodeBlock';
{ThemeClassNamesCode
// remove source comments
.replace(/\/\*[\s\S]*?\*\/|\/\/.*/g,'')
.replace(/^ *\n/gm,'')
.trim()}
</CodeBlock>
```
Expand Down