From 1f1bd25052794eb67c4cfae30b8929dbbc5ffdb9 Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Fri, 17 Nov 2023 11:45:28 +0100 Subject: [PATCH 1/5] don't flatten div with an id Otherwise #refs div for positionning does not work This complements #6952 to fix #6936 fix #6867 --- src/resources/filters/quarto-finalize/coalesceraw.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/resources/filters/quarto-finalize/coalesceraw.lua b/src/resources/filters/quarto-finalize/coalesceraw.lua index a638672c8cb..2f569a5cdf9 100644 --- a/src/resources/filters/quarto-finalize/coalesceraw.lua +++ b/src/resources/filters/quarto-finalize/coalesceraw.lua @@ -22,7 +22,8 @@ function coalesce_raw() Div = function(div) -- only flatten out divs that have no classes or attributes -- (see https://github.com/quarto-dev/quarto-cli/issues/6936) - if #div.classes == 0 and #div.attributes == 0 then + -- or empty identifier (see https://github.com/quarto-dev/quarto-cli/issues/6867) + if #div.classes == 0 and #div.attributes == 0 and div.identifier == "" then return div.content end end From b1894e52077c3a19e7fb133e33abfd95e555b17e Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Fri, 17 Nov 2023 12:12:41 +0100 Subject: [PATCH 2/5] Add a test to check we never remove div of id refs in our processing This adds a pre/post finalize entrypoint to the Lua chain so that we can check state at very end of processing --- src/resources/filters/main.lua | 2 ++ tests/docs/smoke-all/citations/check-refs.lua | 23 ++++++++++++ .../citations/citeproc-refs-position.qmd | 36 +++++++++++++++++++ 3 files changed, 61 insertions(+) create mode 100644 tests/docs/smoke-all/citations/check-refs.lua create mode 100644 tests/docs/smoke-all/citations/citeproc-refs-position.qmd diff --git a/src/resources/filters/main.lua b/src/resources/filters/main.lua index b75890d1097..d5d5223da12 100644 --- a/src/resources/filters/main.lua +++ b/src/resources/filters/main.lua @@ -426,7 +426,9 @@ table.insert(quarto_filter_list, { name = "pre-render", filter = {} }) -- entry tappend(quarto_filter_list, quarto_layout_filters) tappend(quarto_filter_list, quarto_post_filters) table.insert(quarto_filter_list, { name = "post-render", filter = {} }) -- entry point for user filters +table.insert(quarto_filter_list, { name = "pre-finalize", filter = {} }) -- entry point for user filters tappend(quarto_filter_list, quarto_finalize_filters) +table.insert(quarto_filter_list, { name = "post-finalize", filter = {} }) -- entry point for user filters -- now inject user-defined filters on appropriate positions inject_user_filters_at_entry_points(quarto_filter_list) diff --git a/tests/docs/smoke-all/citations/check-refs.lua b/tests/docs/smoke-all/citations/check-refs.lua new file mode 100644 index 00000000000..bcb69be7149 --- /dev/null +++ b/tests/docs/smoke-all/citations/check-refs.lua @@ -0,0 +1,23 @@ +--[[ + This test that none of our Lua processing is removing the div of id refs which is used to hold the bibliography placement + for Pandoc citeproc. +--]] +local ref_div_found = false + +Blocks = function(blocks) + blocks:walk({ + Div = function(div) + if div.identifier == "refs" then + quarto.log.output(div) + ref_div_found = true + end + end + }) +end + +Pandoc = function(doc) + if not ref_div_found then + error("No div with identifier 'refs' found") + crash() + end +end \ No newline at end of file diff --git a/tests/docs/smoke-all/citations/citeproc-refs-position.qmd b/tests/docs/smoke-all/citations/citeproc-refs-position.qmd new file mode 100644 index 00000000000..ab832625d40 --- /dev/null +++ b/tests/docs/smoke-all/citations/citeproc-refs-position.qmd @@ -0,0 +1,36 @@ +--- +title: Position citation +references: +- type: article-journal + id: Lovelace1842 + author: + - family: Lovelace + given: Augusta Ada + issued: + date-parts: + - - 1842 + title: >- + Sketch of the analytical engine invented by Charles Babbage, by LF Menabrea, + officer of the military engineers, with notes upon the memoir by the translator + container-title: Taylor’s Scientific Memoirs + volume: 3 + page: 666-731 + language: en-GB +format: + html: default + pdf: default +filters: + - at: post-finalize + path: check-refs.lua +--- + +@Lovelace1842 + +## References {#references} + +::: {#refs} +::: + +## Appendix {#appendix} + +Blah. \ No newline at end of file From ed1c9b5f5ffeb7ff24b68f4f2bbe653e059a75f2 Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Fri, 17 Nov 2023 12:19:04 +0100 Subject: [PATCH 3/5] more classical test on output content --- .../smoke-all/citations/citeproc-refs-position.qmd | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/tests/docs/smoke-all/citations/citeproc-refs-position.qmd b/tests/docs/smoke-all/citations/citeproc-refs-position.qmd index ab832625d40..734de7c01bd 100644 --- a/tests/docs/smoke-all/citations/citeproc-refs-position.qmd +++ b/tests/docs/smoke-all/citations/citeproc-refs-position.qmd @@ -18,10 +18,20 @@ references: language: en-GB format: html: default - pdf: default + latex: default filters: - at: post-finalize path: check-refs.lua +_quarto: + tests: + html: + ensureHtmlElements: + - ['#references div#refs.references div.csl-entry'] + - [] + latex: + ensureFileRegexMatches: + - ['\\subsection\{References\}[\s\S]+\\begin\{CSLReferences\}[\s\S]+\\subsection\{Appendix\}'] + - [] --- @Lovelace1842 From ed62f0482040252f70127c9c32a8c7bdf9b69012 Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Fri, 17 Nov 2023 12:29:58 +0100 Subject: [PATCH 4/5] Add tests for quarto feature about refs position for natbib and biblatex --- .../citations/biblatex-refs-position.qmd | 23 +++++++++++++++++++ .../citations/citeproc-refs-position.qmd | 17 +------------- .../citations/natbib-refs-position.qmd | 23 +++++++++++++++++++ 3 files changed, 47 insertions(+), 16 deletions(-) create mode 100644 tests/docs/smoke-all/citations/biblatex-refs-position.qmd create mode 100644 tests/docs/smoke-all/citations/natbib-refs-position.qmd diff --git a/tests/docs/smoke-all/citations/biblatex-refs-position.qmd b/tests/docs/smoke-all/citations/biblatex-refs-position.qmd new file mode 100644 index 00000000000..7a4e4a7a409 --- /dev/null +++ b/tests/docs/smoke-all/citations/biblatex-refs-position.qmd @@ -0,0 +1,23 @@ +--- +title: Position citation +bibliography: ref.bib +cite-method: biblatex +_quarto: + tests: + latex: + ensureFileRegexMatches: + - ['\\subsection\{References\}[\s\S]+\\printbibliography\[heading=none\][\s\S]+\\subsection\{Appendix\}'] + - [] + pdf: null +--- + +@Lovelace1842 + +## References {#references} + +::: {#refs} +::: + +## Appendix {#appendix} + +Blah. \ No newline at end of file diff --git a/tests/docs/smoke-all/citations/citeproc-refs-position.qmd b/tests/docs/smoke-all/citations/citeproc-refs-position.qmd index 734de7c01bd..318e86f58e1 100644 --- a/tests/docs/smoke-all/citations/citeproc-refs-position.qmd +++ b/tests/docs/smoke-all/citations/citeproc-refs-position.qmd @@ -1,21 +1,6 @@ --- title: Position citation -references: -- type: article-journal - id: Lovelace1842 - author: - - family: Lovelace - given: Augusta Ada - issued: - date-parts: - - - 1842 - title: >- - Sketch of the analytical engine invented by Charles Babbage, by LF Menabrea, - officer of the military engineers, with notes upon the memoir by the translator - container-title: Taylor’s Scientific Memoirs - volume: 3 - page: 666-731 - language: en-GB +bibliography: ref.bib format: html: default latex: default diff --git a/tests/docs/smoke-all/citations/natbib-refs-position.qmd b/tests/docs/smoke-all/citations/natbib-refs-position.qmd new file mode 100644 index 00000000000..15d7e062232 --- /dev/null +++ b/tests/docs/smoke-all/citations/natbib-refs-position.qmd @@ -0,0 +1,23 @@ +--- +title: Position citation +bibliography: ref.bib +cite-method: natbib +_quarto: + tests: + latex: + ensureFileRegexMatches: + - ['\\subsection\{References\}[\s\S]+\\bibliography\{ref\.bib\}[\s\S]+\\subsection\{Appendix\}'] + - [] + pdf: null +--- + +@Lovelace1842 + +## References {#references} + +::: {#refs} +::: + +## Appendix {#appendix} + +Blah. \ No newline at end of file From a46632afb799ab5e6746e852abdb8e6bd9550ddc Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Fri, 17 Nov 2023 16:02:15 +0100 Subject: [PATCH 5/5] Add missing ref.bib file for tests --- tests/docs/smoke-all/citations/ref.bib | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 tests/docs/smoke-all/citations/ref.bib diff --git a/tests/docs/smoke-all/citations/ref.bib b/tests/docs/smoke-all/citations/ref.bib new file mode 100644 index 00000000000..dd9f4c88623 --- /dev/null +++ b/tests/docs/smoke-all/citations/ref.bib @@ -0,0 +1,11 @@ +@article{Lovelace1842, + author = {Lovelace, Augusta Ada}, + title = {Sketch of the Analytical Engine Invented by {Charles} + {Babbage,} by {LF} {Menabrea,} Officer of the Military Engineers, + with Notes Upon the Memoir by the Translator}, + journal = {TaylorÔÇÖs Scientific Memoirs}, + volume = {3}, + pages = {666-731}, + date = {1842}, + langid = {en-GB} +} \ No newline at end of file