mirror of
https://github.com/facebook/docusaurus.git
synced 2025-06-06 12:52:31 +02:00
feat(theme-common): stable classname for code blocks (#6125)
* feat(theme-common): stable classname for code blocks * Remove extra lines * Fix styles * Remove line
This commit is contained in:
parent
a5d2815154
commit
06bd44c693
4 changed files with 17 additions and 2 deletions
|
@ -15,6 +15,7 @@ import {
|
||||||
parseCodeBlockTitle,
|
parseCodeBlockTitle,
|
||||||
parseLanguage,
|
parseLanguage,
|
||||||
parseLines,
|
parseLines,
|
||||||
|
ThemeClassNames,
|
||||||
} from '@docusaurus/theme-common';
|
} from '@docusaurus/theme-common';
|
||||||
import usePrismTheme from '@theme/hooks/usePrismTheme';
|
import usePrismTheme from '@theme/hooks/usePrismTheme';
|
||||||
import type {Props} from '@theme/CodeBlock';
|
import type {Props} from '@theme/CodeBlock';
|
||||||
|
@ -72,7 +73,12 @@ export default function CodeBlock({
|
||||||
code={code}
|
code={code}
|
||||||
language={language}>
|
language={language}>
|
||||||
{({className, style, tokens, getLineProps, getTokenProps}) => (
|
{({className, style, tokens, getLineProps, getTokenProps}) => (
|
||||||
<div className={clsx(styles.codeBlockContainer, blockClassName)}>
|
<div
|
||||||
|
className={clsx(
|
||||||
|
styles.codeBlockContainer,
|
||||||
|
blockClassName,
|
||||||
|
ThemeClassNames.common.codeBlock,
|
||||||
|
)}>
|
||||||
{codeBlockTitle && (
|
{codeBlockTitle && (
|
||||||
<div style={style} className={styles.codeBlockTitle}>
|
<div style={style} className={styles.codeBlockTitle}>
|
||||||
{codeBlockTitle}
|
{codeBlockTitle}
|
||||||
|
|
|
@ -22,12 +22,19 @@
|
||||||
font-size: var(--ifm-code-font-size);
|
font-size: var(--ifm-code-font-size);
|
||||||
font-weight: 500;
|
font-weight: 500;
|
||||||
padding: 0.75rem var(--ifm-pre-padding);
|
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 {
|
.codeBlock {
|
||||||
margin: 0;
|
margin: 0;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
border-radius: 0;
|
border-radius: var(--ifm-global-radius);
|
||||||
}
|
}
|
||||||
|
|
||||||
.copyButton {
|
.copyButton {
|
||||||
|
|
|
@ -34,6 +34,7 @@ export const ThemeClassNames = {
|
||||||
editThisPage: 'theme-edit-this-page',
|
editThisPage: 'theme-edit-this-page',
|
||||||
lastUpdated: 'theme-last-updated',
|
lastUpdated: 'theme-last-updated',
|
||||||
backToTopButton: 'theme-back-to-top-button',
|
backToTopButton: 'theme-back-to-top-button',
|
||||||
|
codeBlock: 'theme-code-block',
|
||||||
},
|
},
|
||||||
layout: {
|
layout: {
|
||||||
// TODO add other stable classNames here
|
// TODO add other stable classNames here
|
||||||
|
|
|
@ -114,6 +114,7 @@ import CodeBlock from '@theme/CodeBlock';
|
||||||
{ThemeClassNamesCode
|
{ThemeClassNamesCode
|
||||||
// remove source comments
|
// remove source comments
|
||||||
.replace(/\/\*[\s\S]*?\*\/|\/\/.*/g,'')
|
.replace(/\/\*[\s\S]*?\*\/|\/\/.*/g,'')
|
||||||
|
.replace(/^ *\n/gm,'')
|
||||||
.trim()}
|
.trim()}
|
||||||
</CodeBlock>
|
</CodeBlock>
|
||||||
```
|
```
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue