Skip to content
Open
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
6 changes: 6 additions & 0 deletions .changeset/code-block-scroll.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@doc-kit/core': patch
'@node-core/doc-kit-legacy': patch
---

Confine horizontal scrolling in code blocks to the code itself, so the toolbar no longer scrolls out of view along with a long line.
5 changes: 5 additions & 0 deletions packages/core/src/utils/highlighter.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,11 @@ export default function rehypeShikiji() {
// Adds the original language back to the <pre> element
children[0].properties.class = `${children[0].properties.class} ${codeLanguage}`;

// The <code> element is the one that scrolls horizontally, so it is the
// one that has to be reachable by keyboard
delete children[0].properties.tabindex;
children[0].children[0].properties.tabindex = 0;

// Adds the toolbar (language label + copy button) to the <pre> element
children[0].children.push(createToolbarElement(languageId));

Expand Down
4 changes: 3 additions & 1 deletion packages/node-legacy/src/legacy-html/assets/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -544,11 +544,13 @@ pre {
vertical-align: top;
border-radius: 4px;
margin: 1rem;
overflow-x: auto;
}

/* Only the code scrolls, so the toolbar stays put */
pre > code {
display: block;
padding: 0;
overflow-x: auto;
}

pre + h3 {
Expand Down