Skip to content

Commit 83c88a0

Browse files
committed
Properly place code tools even when there is no title
1 parent af81d39 commit 83c88a0

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

src/command/render/codetools.ts

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -140,14 +140,24 @@ export function codeToolsPostprocessor(format: Format) {
140140
const codeTools = resolveCodeTools(format, doc);
141141
if (codeTools.source || codeTools.toggle) {
142142
const title = doc.querySelector("#title-block-header h1");
143-
if (title) {
144-
const header = (title as Element).parentElement;
143+
const header = title !== null
144+
? (title as Element).parentElement
145+
: doc.querySelector("main.content");
146+
147+
if (header) {
145148
const titleDiv = doc.createElement("div");
146149
titleDiv.classList.add("quarto-title-block");
147150
const layoutDiv = doc.createElement("div");
148151
titleDiv.appendChild(layoutDiv);
149-
header?.replaceChild(titleDiv, title);
150-
layoutDiv.appendChild(title);
152+
if (title) {
153+
header?.replaceChild(titleDiv, title);
154+
layoutDiv.appendChild(title);
155+
} else {
156+
// create an empty title
157+
const h1El = doc.createElement("h1");
158+
layoutDiv.appendChild(h1El);
159+
layoutDiv.classList.add("quarto-title-tools-only");
160+
}
151161
const button = doc.createElement("button");
152162
button.setAttribute("type", "button");
153163
button.classList.add("btn");
@@ -159,7 +169,13 @@ export function codeToolsPostprocessor(format: Format) {
159169
button.appendChild(doc.createTextNode(" " + codeTools.caption));
160170
}
161171
layoutDiv.appendChild(button);
162-
header!.appendChild(titleDiv);
172+
173+
if (title) {
174+
header!.appendChild(titleDiv);
175+
} else {
176+
header!.prepend(titleDiv);
177+
}
178+
163179
if (codeTools.toggle) {
164180
button.setAttribute("id", kCodeToolsMenuButtonId);
165181
button.classList.add("dropdown-toggle");

src/resources/formats/html/templates/title-block.scss

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,3 +188,8 @@ main.quarto-banner-title-block > section:first-child > h4 {
188188
grid-template-columns: 1fr 1fr;
189189
}
190190
}
191+
192+
.quarto-title-tools-only {
193+
display: flex;
194+
justify-content: right;
195+
}

0 commit comments

Comments
 (0)