Skip to content
Merged
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
1 change: 1 addition & 0 deletions news/changelog-1.7.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,4 @@ All changes included in 1.7:
- ([fb38eb5](https://github.com/quarto-dev/quarto-cli/commit/fb38eb56c11e09f44cef58fd3b697ff24bb5a3f3)) Use the `latest` parser for Acorn when analyzing JS code imported from OJS blocks.
- ([#10532](https://github.com/quarto-dev/quarto-cli/issues/10532)): Quarto changed default of `--headless=old` to `--headless` as [Chrome 132 has removed old headless mode](https://developer.chrome.com/blog/removing-headless-old-from-chrome) and only support new mode. For using old mode, `QUARTO_CHROMIUM` could be set to a [new `chrome-headless-shell` binary](https://developer.chrome.com/blog/chrome-headless-shell) or too an older chrome version (between 128 and 132) and `QUARTO_CHROMIUM_HEADLESS_MODE` set to `old` for using old headless mode with that compatabitle version.
- ([#10961](https://github.com/quarto-dev/quarto-cli/issues/10961)): Add more information on which Chrome Headless will be used in `quarto check install`. This is helpful to help debug mermaid issues.
- ([#11951](https://github.com/quarto-dev/quarto-cli/issues/11951)): Raw LaTeX table without `tbl-` prefix label for using Quarto crossref are now correctly passed through unmodified.
28 changes: 20 additions & 8 deletions src/command/render/pandoc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,16 @@ export async function runPandoc(
...options.flags?.metadata,
} as Metadata;

const cleanQuartoTestsMetadata = (metadata: Metadata) => {
// remove any metadata that is only used for testing
if (metadata["_quarto"] && typeof metadata["_quarto"] === "object") {
delete (metadata._quarto as { [key: string]: unknown })?.tests;
if (Object.keys(metadata._quarto).length === 0) {
delete metadata._quarto;
}
}
};

// remove some metadata that are used as parameters to our lua filters
const cleanMetadataForPrinting = (metadata: Metadata) => {
delete metadata.params;
Expand All @@ -409,6 +419,7 @@ export async function runPandoc(
delete metadata[kRevealJsScripts];
deleteProjectMetadata(metadata);
deleteCrossrefMetadata(metadata);
removeFilterParams(metadata);

// Don't print empty reveal-js plugins
if (
Expand All @@ -417,7 +428,12 @@ export async function runPandoc(
) {
delete metadata[kRevealJSPlugins];
}

// Don't print _quarto.tests
// This can cause issue on regex test for printed output
cleanQuartoTestsMetadata(metadata);
};

cleanMetadataForPrinting(printMetadata);

// Forward flags metadata into the format
Expand Down Expand Up @@ -1270,11 +1286,9 @@ export async function runPandoc(
delete pandocPassedMetadata.project;
delete pandocPassedMetadata.website;
delete pandocPassedMetadata.about;
if (pandocPassedMetadata._quarto) {
// these shouldn't be visible because they are emitted on markdown output
// and it breaks ensureFileRegexMatches
delete pandocPassedMetadata._quarto.tests;
}
// these shouldn't be visible because they are emitted on markdown output
// and it breaks ensureFileRegexMatches
cleanQuartoTestsMetadata(pandocPassedMetadata);

Deno.writeTextFileSync(
metadataTemp,
Expand Down Expand Up @@ -1377,7 +1391,7 @@ export async function runPandoc(

// this mutates metadata[kClassOption]
function cleanupPandocMetadata(metadata: Metadata) {
// pdf classoption can end up with duplicaed options
// pdf classoption can end up with duplicated options
const classoption = metadata[kClassOption];
if (Array.isArray(classoption)) {
metadata[kClassOption] = ld.uniqBy(
Expand Down Expand Up @@ -1668,8 +1682,6 @@ function runPandocMessage(
const printMetadata = ld.cloneDeep(metadata) as Metadata;
delete printMetadata.format;

// remove filter params
removeFilterParams(printMetadata);
// print message
if (Object.keys(printMetadata).length > 0) {
info("metadata", { bold: true });
Expand Down
31 changes: 17 additions & 14 deletions src/resources/filters/quarto-pre/parsefiguredivs.lua
Original file line number Diff line number Diff line change
Expand Up @@ -702,36 +702,39 @@ function parse_floatreftargets()
return nil
end

-- prevent raw mutation
local rawText = raw.text

-- first we check if all of the expected bits are present

-- check for {#...} or \label{...}
if raw.text:find(patterns.latex_label) == nil and
raw.text:find(patterns.attr_identifier) == nil then
if rawText:find(patterns.latex_label) == nil and
rawText:find(patterns.attr_identifier) == nil then
return nil
end

-- check for \caption{...}
if raw.text:find(patterns.latex_caption) == nil then
if rawText:find(patterns.latex_caption) == nil then
return nil
end

-- check for tabular or longtable
if raw.text:find(patterns.latex_long_table) == nil and
raw.text:find(patterns.latex_tabular) == nil then
if rawText:find(patterns.latex_long_table) == nil and
rawText:find(patterns.latex_tabular) == nil then
return nil
end

-- if we're here, then we're going to parse this as a FloatRefTarget
-- and we need to remove the label and caption from the raw block
local identifier = ""
local b, e, match1, label_identifier = raw.text:find(patterns.latex_label)
local b, e, _ , label_identifier = rawText:find(patterns.latex_label)
if b ~= nil then
raw.text = raw.text:sub(1, b - 1) .. raw.text:sub(e + 1)
rawText = rawText:sub(1, b - 1) .. rawText:sub(e + 1)
identifier = label_identifier
else
local b, e, match2, attr_identifier = raw.text:find(patterns.attr_identifier)
local b, e, _ , attr_identifier = rawText:find(patterns.attr_identifier)
if b ~= nil then
raw.text = raw.text:sub(1, b - 1) .. raw.text:sub(e + 1)
rawText = rawText:sub(1, b - 1) .. rawText:sub(e + 1)
identifier = attr_identifier
else
internal_error()
Expand All @@ -749,9 +752,9 @@ function parse_floatreftargets()
end

local caption
local b, e, match3, caption_content = raw.text:find(patterns.latex_caption)
local b, e, _, caption_content = rawText:find(patterns.latex_caption)
if b ~= nil then
raw.text = raw.text:sub(1, b - 1) .. raw.text:sub(e + 1)
rawText = rawText:sub(1, b - 1) .. rawText:sub(e + 1)
caption = pandoc.RawBlock("latex", caption_content)
else
internal_error()
Expand All @@ -760,16 +763,16 @@ function parse_floatreftargets()

-- finally, if the user passed a \\begin{table} float environment
-- we just remove it because we'll re-emit later ourselves
local matched, _ = _quarto.modules.patterns.match_in_list_of_patterns(raw.text, _quarto.patterns.latexTableEnvPatterns)
local matched, _ = _quarto.modules.patterns.match_in_list_of_patterns(rawText, _quarto.patterns.latexTableEnvPatterns)
if matched then
-- table_body is second matched element.
raw.text = matched[2]
rawText = matched[2]
end

return construct({
attr = pandoc.Attr(identifier, {}, {}),
type = "Table",
content = pandoc.Blocks({ raw }),
content = pandoc.Blocks({ pandoc.RawBlock(raw.format, rawText) }),
caption_long = quarto.utils.as_blocks(caption)
}), false
end
Expand Down
1 change: 0 additions & 1 deletion tests/docs/smoke-all/2024/01/22/8389.md.snapshot
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
---
_quarto: {}
foo: bar
toc-title: Table of contents
---
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
---
title: Raw LaTeX table with not `tbl` in label id
format: pdf
keep-tex: true
_quarto:
tests:
pdf:
ensureLatexFileRegexMatches:
- ['[\s\S]+\\begin\{table\}\[htbp\][\s\S]+', '[\s\S]+\\caption\{\\label\{mod\}']
- []
printsMessage:
- INFO
- 'WARNING(.*)Raw LaTeX table found with non-tbl label:'
---

This document has a raw LaTeX table with no intent to use quarto crossref. It uses a label with `tbl-` id.

Table will be identified by floatreftarget processing but raw TeX should be left untouched in the output, while a warning still is emitted.

```{=latex}
\begin{table}[htbp]
\caption{\label{mod} no title}
\centering
\begin{tabular}{lc}
\tabularnewline \midrule \midrule
Dependent Variable: & disp\\
Model: & (1)\\
\midrule
\emph{Variables}\\
Constant & 580.9$^{***}$\\
& (41.74)\\
mpg & -17.43$^{***}$\\
& (1.993)\\
\midrule
\emph{Fit statistics}\\
Observations & 32\\
R$^2$ & 0.71834\\
Adjusted R$^2$ & 0.70895\\
\midrule \midrule
\multicolumn{2}{l}{\emph{IID standard-errors in parentheses}}\\
\multicolumn{2}{l}{\emph{Signif. Codes: ***: 0.01, **: 0.05, *: 0.1}}\\
\end{tabular}
\end{table}
```