diff --git a/packages/docusaurus-theme-classic/src/theme/CodeBlock/index.tsx b/packages/docusaurus-theme-classic/src/theme/CodeBlock/index.tsx
index 3c2655cc33f5..93903ab13864 100644
--- a/packages/docusaurus-theme-classic/src/theme/CodeBlock/index.tsx
+++ b/packages/docusaurus-theme-classic/src/theme/CodeBlock/index.tsx
@@ -140,14 +140,22 @@ export default function CodeBlock({
lineProps.className += ' docusaurus-highlight-code-line';
}
+ const lineTokens = line.map((token, key) => (
+
+ ));
+
return (
- {shouldShowLineNumbers && (
-
+ {shouldShowLineNumbers ? (
+ <>
+
+
+ {lineTokens}
+
+ >
+ ) : (
+ lineTokens
)}
- {line.map((token, key) => (
-
- ))}
);
diff --git a/packages/docusaurus-theme-classic/src/theme/CodeBlock/styles.module.css b/packages/docusaurus-theme-classic/src/theme/CodeBlock/styles.module.css
index 75bedb96959c..92a92bdd53c2 100644
--- a/packages/docusaurus-theme-classic/src/theme/CodeBlock/styles.module.css
+++ b/packages/docusaurus-theme-classic/src/theme/CodeBlock/styles.module.css
@@ -52,7 +52,8 @@
}
.codeBlockLinesWithNumbering {
- padding-left: 0;
+ display: table;
+ padding: var(--ifm-pre-padding) 0;
}
@media print {
@@ -62,11 +63,14 @@
}
.codeLine {
+ display: table-row;
counter-increment: line-count;
}
.codeLineNumber {
- display: inline-block;
+ display: table-cell;
+ text-align: right;
+ width: 1%;
position: sticky;
left: 0;
padding: 0 var(--ifm-pre-padding);
@@ -81,3 +85,7 @@
:global(.docusaurus-highlight-code-line) .codeLineNumber::before {
opacity: 0.8;
}
+
+.codeLineContent {
+ padding-right: var(--ifm-pre-padding);
+}