diff --git a/src/resources/filters/quarto-post/foldcode.lua b/src/resources/filters/quarto-post/foldcode.lua index c6c0feb263c..0e009874b22 100644 --- a/src/resources/filters/quarto-post/foldcode.lua +++ b/src/resources/filters/quarto-post/foldcode.lua @@ -32,14 +32,10 @@ function render_folded_block(block) div.content:insert(pandoc.RawBlock("html", "")) return div end - local make_code_cell_scaffold = function(div) - return pandoc.Div({ block }, pandoc.Attr("", { "quarto-scaffold" })) - end - if not block.attr.classes:includes("cell-code") then - return nil - end - if not (_quarto.format.isHtmlOutput() or _quarto.format.isMarkdownWithHtmlOutput()) then - return make_code_cell_scaffold(block) + if (not block.attr.classes:includes("cell-code") or + (not (_quarto.format.isHtmlOutput() or + _quarto.format.isMarkdownWithHtmlOutput()))) then + return block, false end local fold = foldAttribute(block) local summary = summaryAttribute(block) @@ -47,12 +43,12 @@ function render_folded_block(block) block.attr.attributes["code-fold"] = nil block.attr.attributes["code-summary"] = nil if fold ~= "none" then - return make_code_fold_html(fold, summary) + return make_code_fold_html(fold, summary), true else - return block + return block, false end else - return block + return block, false end end @@ -77,15 +73,23 @@ function fold_code_and_lift_codeblocks() return nil, false end, CodeBlock = function(block) - local folded_block = make_scaffold(pandoc.Div, { render_folded_block(block) }) + local folded_block, did_fold = render_folded_block(block) + local need_to_lift = did_fold or block.classes:includes("code-annotation-code") + if need_to_lift then + folded_block = make_scaffold(pandoc.Div, { folded_block } ) + end if block.classes:includes("code-annotation-code") then prev_annotated_code_block_scaffold = folded_block prev_annotated_code_block = block else prev_annotated_code_block_scaffold = nil end - blocks:insert(folded_block) - return {} + if need_to_lift then + blocks:insert(folded_block) + return {} + else + return nil + end end, Div = function(div) if not div.classes:includes("cell-annotation") then @@ -102,6 +106,7 @@ function fold_code_and_lift_codeblocks() }) if need_to_move_dl then assert(prev_annotated_code_block_scaffold) + print(prev_annotated_code_block_scaffold) prev_annotated_code_block_scaffold.content:insert(div) return {} end diff --git a/tests/docs/smoke-all/2024/01/19/8354.qmd b/tests/docs/smoke-all/2024/01/19/8354.qmd new file mode 100644 index 00000000000..d2c4e1ca252 --- /dev/null +++ b/tests/docs/smoke-all/2024/01/19/8354.qmd @@ -0,0 +1,25 @@ +--- +title: "Untitled" +format: latex +execute: + warning: false +_quarto: + tests: + latex: + ensureSnapshotMatches: true +--- + +```{r} +#| label: tbl-tables +#| tbl-cap: "Tables" +#| tbl-subcap: +#| - cars +#| - pressure +#| layout-ncol: 2 + +library(knitr) +kable(head(cars)) +kable(head(pressure)) +``` + +See @tbl-tables for examples. In particular, @tbl-tables-2. diff --git a/tests/docs/smoke-all/2024/01/19/8354.tex.snapshot b/tests/docs/smoke-all/2024/01/19/8354.tex.snapshot new file mode 100644 index 00000000000..1ff018a3e72 --- /dev/null +++ b/tests/docs/smoke-all/2024/01/19/8354.tex.snapshot @@ -0,0 +1,251 @@ +% Options for packages loaded elsewhere +\PassOptionsToPackage{unicode}{hyperref} +\PassOptionsToPackage{hyphens}{url} +\PassOptionsToPackage{dvipsnames,svgnames,x11names}{xcolor} +% +\documentclass[ + letterpaper, + DIV=11, + numbers=noendperiod]{scrartcl} + +\usepackage{amsmath,amssymb} +\usepackage{iftex} +\ifPDFTeX + \usepackage[T1]{fontenc} + \usepackage[utf8]{inputenc} + \usepackage{textcomp} % provide euro and other symbols +\else % if luatex or xetex + \usepackage{unicode-math} + \defaultfontfeatures{Scale=MatchLowercase} + \defaultfontfeatures[\rmfamily]{Ligatures=TeX,Scale=1} +\fi +\usepackage{lmodern} +\ifPDFTeX\else + % xetex/luatex font selection +\fi +% Use upquote if available, for straight quotes in verbatim environments +\IfFileExists{upquote.sty}{\usepackage{upquote}}{} +\IfFileExists{microtype.sty}{% use microtype if available + \usepackage[]{microtype} + \UseMicrotypeSet[protrusion]{basicmath} % disable protrusion for tt fonts +}{} +\makeatletter +\@ifundefined{KOMAClassName}{% if non-KOMA class + \IfFileExists{parskip.sty}{% + \usepackage{parskip} + }{% else + \setlength{\parindent}{0pt} + \setlength{\parskip}{6pt plus 2pt minus 1pt}} +}{% if KOMA class + \KOMAoptions{parskip=half}} +\makeatother +\usepackage{xcolor} +\setlength{\emergencystretch}{3em} % prevent overfull lines +\setcounter{secnumdepth}{-\maxdimen} % remove section numbering +% Make \paragraph and \subparagraph free-standing +\ifx\paragraph\undefined\else + \let\oldparagraph\paragraph + \renewcommand{\paragraph}[1]{\oldparagraph{#1}\mbox{}} +\fi +\ifx\subparagraph\undefined\else + \let\oldsubparagraph\subparagraph + \renewcommand{\subparagraph}[1]{\oldsubparagraph{#1}\mbox{}} +\fi + +\usepackage{color} +\usepackage{fancyvrb} +\newcommand{\VerbBar}{|} +\newcommand{\VERB}{\Verb[commandchars=\\\{\}]} +\DefineVerbatimEnvironment{Highlighting}{Verbatim}{commandchars=\\\{\}} +% Add ',fontsize=\small' for more characters per line +\usepackage{framed} +\definecolor{shadecolor}{RGB}{241,243,245} +\newenvironment{Shaded}{\begin{snugshade}}{\end{snugshade}} +\newcommand{\AlertTok}[1]{\textcolor[rgb]{0.68,0.00,0.00}{#1}} +\newcommand{\AnnotationTok}[1]{\textcolor[rgb]{0.37,0.37,0.37}{#1}} +\newcommand{\AttributeTok}[1]{\textcolor[rgb]{0.40,0.45,0.13}{#1}} +\newcommand{\BaseNTok}[1]{\textcolor[rgb]{0.68,0.00,0.00}{#1}} +\newcommand{\BuiltInTok}[1]{\textcolor[rgb]{0.00,0.23,0.31}{#1}} +\newcommand{\CharTok}[1]{\textcolor[rgb]{0.13,0.47,0.30}{#1}} +\newcommand{\CommentTok}[1]{\textcolor[rgb]{0.37,0.37,0.37}{#1}} +\newcommand{\CommentVarTok}[1]{\textcolor[rgb]{0.37,0.37,0.37}{\textit{#1}}} +\newcommand{\ConstantTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{#1}} +\newcommand{\ControlFlowTok}[1]{\textcolor[rgb]{0.00,0.23,0.31}{#1}} +\newcommand{\DataTypeTok}[1]{\textcolor[rgb]{0.68,0.00,0.00}{#1}} +\newcommand{\DecValTok}[1]{\textcolor[rgb]{0.68,0.00,0.00}{#1}} +\newcommand{\DocumentationTok}[1]{\textcolor[rgb]{0.37,0.37,0.37}{\textit{#1}}} +\newcommand{\ErrorTok}[1]{\textcolor[rgb]{0.68,0.00,0.00}{#1}} +\newcommand{\ExtensionTok}[1]{\textcolor[rgb]{0.00,0.23,0.31}{#1}} +\newcommand{\FloatTok}[1]{\textcolor[rgb]{0.68,0.00,0.00}{#1}} +\newcommand{\FunctionTok}[1]{\textcolor[rgb]{0.28,0.35,0.67}{#1}} +\newcommand{\ImportTok}[1]{\textcolor[rgb]{0.00,0.46,0.62}{#1}} +\newcommand{\InformationTok}[1]{\textcolor[rgb]{0.37,0.37,0.37}{#1}} +\newcommand{\KeywordTok}[1]{\textcolor[rgb]{0.00,0.23,0.31}{#1}} +\newcommand{\NormalTok}[1]{\textcolor[rgb]{0.00,0.23,0.31}{#1}} +\newcommand{\OperatorTok}[1]{\textcolor[rgb]{0.37,0.37,0.37}{#1}} +\newcommand{\OtherTok}[1]{\textcolor[rgb]{0.00,0.23,0.31}{#1}} +\newcommand{\PreprocessorTok}[1]{\textcolor[rgb]{0.68,0.00,0.00}{#1}} +\newcommand{\RegionMarkerTok}[1]{\textcolor[rgb]{0.00,0.23,0.31}{#1}} +\newcommand{\SpecialCharTok}[1]{\textcolor[rgb]{0.37,0.37,0.37}{#1}} +\newcommand{\SpecialStringTok}[1]{\textcolor[rgb]{0.13,0.47,0.30}{#1}} +\newcommand{\StringTok}[1]{\textcolor[rgb]{0.13,0.47,0.30}{#1}} +\newcommand{\VariableTok}[1]{\textcolor[rgb]{0.07,0.07,0.07}{#1}} +\newcommand{\VerbatimStringTok}[1]{\textcolor[rgb]{0.13,0.47,0.30}{#1}} +\newcommand{\WarningTok}[1]{\textcolor[rgb]{0.37,0.37,0.37}{\textit{#1}}} + +\providecommand{\tightlist}{% + \setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}}\usepackage{longtable,booktabs,array} +\usepackage{calc} % for calculating minipage widths +% Correct order of tables after \paragraph or \subparagraph +\usepackage{etoolbox} +\makeatletter +\patchcmd\longtable{\par}{\if@noskipsec\mbox{}\fi\par}{}{} +\makeatother +% Allow footnotes in longtable head/foot +\IfFileExists{footnotehyper.sty}{\usepackage{footnotehyper}}{\usepackage{footnote}} +\makesavenoteenv{longtable} +\usepackage{graphicx} +\makeatletter +\def\maxwidth{\ifdim\Gin@nat@width>\linewidth\linewidth\else\Gin@nat@width\fi} +\def\maxheight{\ifdim\Gin@nat@height>\textheight\textheight\else\Gin@nat@height\fi} +\makeatother +% Scale images if necessary, so that they will not overflow the page +% margins by default, and it is still possible to overwrite the defaults +% using explicit options in \includegraphics[width, height, ...]{} +\setkeys{Gin}{width=\maxwidth,height=\maxheight,keepaspectratio} +% Set default figure placement to htbp +\makeatletter +\def\fps@figure{htbp} +\makeatother + +\KOMAoption{captions}{tableheading} +\makeatletter +\@ifpackageloaded{caption}{}{\usepackage{caption}} +\AtBeginDocument{% +\ifdefined\contentsname + \renewcommand*\contentsname{Table of contents} +\else + \newcommand\contentsname{Table of contents} +\fi +\ifdefined\listfigurename + \renewcommand*\listfigurename{List of Figures} +\else + \newcommand\listfigurename{List of Figures} +\fi +\ifdefined\listtablename + \renewcommand*\listtablename{List of Tables} +\else + \newcommand\listtablename{List of Tables} +\fi +\ifdefined\figurename + \renewcommand*\figurename{Figure} +\else + \newcommand\figurename{Figure} +\fi +\ifdefined\tablename + \renewcommand*\tablename{Table} +\else + \newcommand\tablename{Table} +\fi +} +\@ifpackageloaded{float}{}{\usepackage{float}} +\floatstyle{ruled} +\@ifundefined{c@chapter}{\newfloat{codelisting}{h}{lop}}{\newfloat{codelisting}{h}{lop}[chapter]} +\floatname{codelisting}{Listing} +\newcommand*\listoflistings{\listof{codelisting}{List of Listings}} +\makeatother +\makeatletter +\makeatother +\makeatletter +\@ifpackageloaded{caption}{}{\usepackage{caption}} +\@ifpackageloaded{subcaption}{}{\usepackage{subcaption}} +\makeatother +\ifLuaTeX + \usepackage{selnolig} % disable illegal ligatures +\fi +\usepackage{bookmark} + +\IfFileExists{xurl.sty}{\usepackage{xurl}}{} % add URL line breaks if available +\urlstyle{same} % disable monospaced font for URLs +\hypersetup{ + pdftitle={Untitled}, + colorlinks=true, + linkcolor={blue}, + filecolor={Maroon}, + citecolor={Blue}, + urlcolor={Blue}, + pdfcreator={LaTeX via pandoc}} + +\title{Untitled} +\author{} +\date{} + +\begin{document} +\maketitle + +\begin{Shaded} +\begin{Highlighting}[] +\FunctionTok{library}\NormalTok{(knitr)} +\FunctionTok{kable}\NormalTok{(}\FunctionTok{head}\NormalTok{(cars))} +\FunctionTok{kable}\NormalTok{(}\FunctionTok{head}\NormalTok{(pressure))} +\end{Highlighting} +\end{Shaded} + +\begin{table} + +\caption{\label{tbl-tables}Tables} + +\begin{minipage}{0.50\linewidth} + +\subcaption{\label{tbl-tables-1}cars} + +\centering{ + +\begin{tabular}{rr} +\toprule +speed & dist\\ +\midrule +4 & 2\\ +4 & 10\\ +7 & 4\\ +7 & 22\\ +8 & 16\\ +9 & 10\\ +\bottomrule +\end{tabular} + +} + +\end{minipage}% +% +\begin{minipage}{0.50\linewidth} + +\subcaption{\label{tbl-tables-2}pressure} + +\centering{ + +\begin{tabular}{rr} +\toprule +temperature & pressure\\ +\midrule +0 & 0.0002\\ +20 & 0.0012\\ +40 & 0.0060\\ +60 & 0.0300\\ +80 & 0.0900\\ +100 & 0.2700\\ +\bottomrule +\end{tabular} + +} + +\end{minipage}% + +\end{table}% + +See Table~\ref{tbl-tables} for examples. In particular, +Table~\ref{tbl-tables-2}. + + + +\end{document} diff --git a/tests/verify.ts b/tests/verify.ts index 48116ec0737..0288b7761a7 100644 --- a/tests/verify.ts +++ b/tests/verify.ts @@ -237,6 +237,12 @@ export const ensureSnapshotMatches = ( name: "Inspecting Snapshot", verify: async (_output: ExecuteOutput[]) => { const good = await checkSnapshot(file); + if (!good) { + console.log("output:"); + console.log(await Deno.readTextFile(file)); + console.log("snapshot:"); + console.log(await Deno.readTextFile(file + ".snapshot")); + } assert( good, `Snapshot ${file}.snapshot doesn't match output`,