Skip to content

Commit 42fdd0d

Browse files
authored
Merge pull request #4786 from quarto-dev/bugfix/templates
Bugfix/templates
2 parents be1f37e + 83c88a0 commit 42fdd0d

File tree

7 files changed

+35
-10
lines changed

7 files changed

+35
-10
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/project/types/website/website-meta.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,7 @@ function resolveImageMetadata(
301301
const siteMeta = format.metadata[kWebsite] as Metadata;
302302
if (metadata[kImage] && siteMeta && siteMeta[kSiteUrl] !== undefined) {
303303
// Resolve any relative urls and figure out image size
304+
const inputRelImg = metadata[kImage];
304305
const imgMeta = imageMetadata(
305306
metadata[kImage] as string,
306307
siteMeta[kSiteUrl] as string,
@@ -318,7 +319,7 @@ function resolveImageMetadata(
318319
metadata[kImageAlt] = altText;
319320
}
320321

321-
return imgMeta.path;
322+
return inputRelImg as string;
322323
}
323324
}
324325

src/resources/formats/html/pandoc/template.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434

3535
$if(title)$
3636
$title-block.html()$
37+
$elseif(subtitle)$
38+
$title-block.html()$
3739
$endif$
3840

3941
$if(toc)$

src/resources/formats/html/pandoc/title-block.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
<header id="title-block-header">
2-
<h1 class="title">$title$</h1>
2+
$if(title)$<h1 class="title">$title$</h1>$endif$
33
$if(subtitle)$
44
<p class="subtitle">$subtitle$</p>
5-
65
$endif$
76
$for(author)$
87
<p class="author">$author$</p>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<header id="title-block-header" class="quarto-title-block default$if(quarto-template-params.banner-header-class)$ $quarto-template-params.banner-header-class$$endif$">
33
<div class="quarto-title-banner">
44
<div class="quarto-title column-body">
5-
<h1 class="title">$title$</h1>
5+
$if(title)$<h1 class="title">$title$</h1>$endif$
66
$if(subtitle)$
77
<p class="subtitle lead">$subtitle$</p>
88
$endif$

src/resources/formats/html/templates/quarto-html.ejs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -596,8 +596,10 @@ window.document.addEventListener("DOMContentLoaded", function (event) {
596596
597597
<% if (linkExternalIcon || linkExternalNewwindow) { %>
598598
var localhostRegex = new RegExp(/^(?:http|https):\/\/localhost\:?[0-9]*\//);
599-
<% if (linkExternalFilter) { %>
599+
<% if (linkExternalFilter && linkExternalFilter.match(/\\\\/)) { %>
600600
<%- `var filterRegex = new RegExp(/${linkExternalFilter}/);` %>
601+
<% } else if (linkExternalFilter) { %>
602+
<%= `var filterRegex = new RegExp("${linkExternalFilter}");` %>
601603
<% } else { %>
602604
var filterRegex = new RegExp('/' + window.location.host + '/');
603605
<% } %>

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)