Skip to content

Commit 01ac557

Browse files
committed
Merge branch 'main' of github.com:quarto-dev/quarto-cli into main
2 parents 160d5f6 + d7efc45 commit 01ac557

File tree

5 files changed

+103
-8
lines changed

5 files changed

+103
-8
lines changed

src/project/types/website/listing/website-listing-shared.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -365,10 +365,23 @@ export function readRenderedContents(
365365
});
366366
}
367367

368+
// Cleans math tags and replaces with qquad
369+
const replaceTagRegex = /\/tag\{(.*)\}/g;
370+
const cleanMath = (contents?: string) => {
371+
if (!contents) {
372+
return undefined;
373+
} else {
374+
// /tag{1} > \qquad(1)
375+
return contents.replaceAll(replaceTagRegex, (_match, content) => {
376+
return `\\qquad{${content}}`;
377+
});
378+
}
379+
};
380+
368381
return {
369382
title: titleText,
370-
fullContents: mainEl?.innerHTML,
371-
firstPara: mainEl?.querySelector("p")?.innerHTML,
383+
fullContents: cleanMath(mainEl?.innerHTML),
384+
firstPara: cleanMath(mainEl?.querySelector("p")?.innerHTML),
372385
};
373386
}
374387

src/project/types/website/website-navigation.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -855,7 +855,10 @@ function expandedSidebar(href: string, sidebar?: Sidebar): Sidebar | undefined {
855855
const item = items[i];
856856
item.active = itemHasNavTarget(item, href);
857857
if (Object.keys(item).includes("contents")) {
858-
if (resolveExpandedItems(href, item.contents || [])) {
858+
if (
859+
resolveExpandedItems(href, item.contents || []) ||
860+
item.href === href
861+
) {
859862
item.expanded = true;
860863
return true;
861864
}
@@ -938,8 +941,9 @@ async function navbarEjsData(
938941
background: navbar.background || "primary",
939942
logo: resolveLogo(navbar.logo),
940943
collapse,
941-
[kCollapseBelow]: !collapse ? ""
942-
: ("-" + (navbar[kCollapseBelow] || "lg")) as LayoutBreak,
944+
[kCollapseBelow]: !collapse
945+
? ""
946+
: ("-" + (navbar[kCollapseBelow] || "lg")) as LayoutBreak,
943947
pinned: navbar.pinned !== undefined ? !!navbar.pinned : false,
944948
};
945949

src/resources/filters/quarto-pre/table-captions.lua

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,29 @@ kTblSubCap = "tbl-subcap"
66

77
local latexTableWithOptionsPattern = "(\\begin{table}%[%w+%])(.*)(\\end{table})"
88
local latexTablePattern = "(\\begin{table})(.*)(\\end{table})"
9+
local latexLongtablePatternwWithPosAndAlign = "(\\begin{longtable}%[[^%]]+%]{.*})(.*)(\\end{longtable})"
10+
local latexLongtablePatternWithPos = "(\\begin{longtable}%[[^%]]+%])(.*)(\\end{longtable})"
11+
local latexLongtablePatternWithAlign = "(\\begin{longtable}{.*})(.*)(\\end{longtable})"
912
local latexLongtablePattern = "(\\begin{longtable})(.*)(\\end{longtable})"
13+
local latexTabularPatternWithPosAndAlign = "(\\begin{tabular}%[[^%]]+%]{.*})(.*)(\\end{tabular})"
14+
local latexTabularPatternWithPos = "(\\begin{tabular}%[[^%]]+%])(.*)(\\end{tabular})"
15+
local latexTabularPatternWithAlign = "(\\begin{tabular}{.*})(.*)(\\end{tabular})"
1016
local latexTabularPattern = "(\\begin{tabular})(.*)(\\end{tabular})"
1117

1218
local latexTablePatterns = pandoc.List({
1319
latexTableWithOptionsPattern,
1420
latexTablePattern,
21+
latexLongtablePatternwWithPosAndAlign,
22+
latexLongtablePatternWithPos,
23+
latexLongtablePatternWithAlign,
1524
latexLongtablePattern,
25+
latexTabularPatternWithPosAndAlign,
26+
latexTabularPatternWithPos,
27+
latexTabularPatternWithAlign,
1628
latexTabularPattern,
1729
})
1830

19-
local latexCaptionPattern = "(\\caption{)(.-)(}\n)"
31+
local latexCaptionPattern = "(\\caption{)(.-)(}[^\n]*\n)"
2032

2133
function tableCaptions()
2234

@@ -206,7 +218,7 @@ function applyLatexTableCaption(latex, tblCaption, tblLabel, tablePattern)
206218
-- insert caption if there is none
207219
local beginCaption, caption = latex:match(latexCaptionPattern)
208220
if not beginCaption then
209-
latex = latex:gsub(tablePattern, "%1" .. "\n\\caption{ }\n" .. "%2%3", 1)
221+
latex = latex:gsub(tablePattern, "%1" .. "\n\\caption{ }\\tabularnewline\n" .. "%2%3", 1)
210222
end
211223
-- apply table caption and label
212224
local beginCaption, captionText, endCaption = latex:match(latexCaptionPattern)
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
---
2+
title: "knitr-tables-latex"
3+
format:
4+
pdf:
5+
keep-tex: true
6+
keep-md: true
7+
knitr:
8+
opts_chunk:
9+
echo: false
10+
---
11+
12+
```{r}
13+
#| label: tbl-1
14+
#| tbl-cap: "Markdown table"
15+
knitr::kable(head(iris))
16+
```
17+
18+
```{r}
19+
#| label: tbl-2
20+
#| tbl-cap: "Tabular"
21+
knitr::kable(head(iris), format = "latex")
22+
```
23+
24+
```{r}
25+
#| label: tbl-3
26+
#| tbl-cap: "Longtable"
27+
knitr::kable(
28+
head(mtcars),
29+
format = "latex",
30+
longtable = TRUE
31+
)
32+
```
33+
34+
```{r}
35+
#| label: tbl-4
36+
#| tbl-cap: "Two tables placed side by side."
37+
d1 <- head(cars, 3)
38+
d2 <- head(mtcars[, 1:3], 5)
39+
knitr::kable(
40+
list(d1, d2),
41+
valign = 'c'
42+
)
43+
```
44+
45+
46+
Markdown source for @tbl-1
47+
48+
LaTeX source with tabulat for @tbl-2
49+
50+
LaTeX source with longtable for @tbl-3
51+
52+
LaTeX source with table and tabular for @tbl-4

tests/smoke/crossref/tables.test.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,11 @@
66
*/
77

88
import { ensureFileRegexMatches, ensureHtmlElements } from "../../verify.ts";
9-
import { testRender } from "../render/render.ts";
9+
import { testRender, renderVerifyLatexOutput } from "../render/render.ts";
1010
import { crossref } from "./utils.ts";
11+
import { docs } from "../../utils.ts";
12+
13+
/* HTML */
1114

1215
const tablesQmd = crossref("tables.qmd", "html");
1316
testRender(tablesQmd.input, "html", false, [
@@ -44,3 +47,14 @@ testRender(knitrTablesQmd.input, "html", false, [
4447
/\?@tbl-/,
4548
]),
4649
]);
50+
51+
/* LaTeX */
52+
53+
/* caption is inserted in the right place in table environment*/
54+
renderVerifyLatexOutput(docs("crossrefs/knitr-tables-latex.qmd"), [
55+
/\\begin{longtable}\[.*\]{.*}.*\n\\caption{\\label{tbl-1}.*}\\tabularnewline/,
56+
/\\begin{table}\n\\caption{\\label{tbl-2}.*}.*\n+\\centering\n\\begin{tabular}{.*}/,
57+
/\\begin{longtable}{.*}.*\n\\caption{\\label{tbl-3}.*}\\tabularnewline/,
58+
/\\begin{table}\n\\caption{\\label{tbl-4}.*}.*\n+\\centering\n\\begin{tabular}\[c\]{.*}/,
59+
/\\begin{table}\n\\caption{\\label{tbl-4}.*}.*\n+\\centering\n\\begin{tabular}\[c\]{.*}/,
60+
]);

0 commit comments

Comments
 (0)