From a19a1f0f4ac57f680fd325c40416efe59aa20f7e Mon Sep 17 00:00:00 2001 From: James Goldie Date: Fri, 18 Oct 2024 15:43:22 +1100 Subject: [PATCH 1/5] Add spacer shortcode --- _extensions/closeread/_extension.yml | 2 ++ _extensions/closeread/closeread.css | 3 +++ _extensions/closeread/closeread.css.map | 2 +- _extensions/closeread/closeread.scss | 6 ++++++ _extensions/closeread/spacer.lua | 11 +++++++++++ docs/index.qmd | 2 ++ 6 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 _extensions/closeread/spacer.lua diff --git a/_extensions/closeread/_extension.yml b/_extensions/closeread/_extension.yml index 4564842..cda8078 100644 --- a/_extensions/closeread/_extension.yml +++ b/_extensions/closeread/_extension.yml @@ -3,6 +3,8 @@ author: Andrew Bray and James Goldie version: 0.7.0 quarto-required: ">=1.3.0" contributes: + shortcodes: + - spacer.lua formats: html: filters: diff --git a/_extensions/closeread/closeread.css b/_extensions/closeread/closeread.css index e0d36a9..a4ecef6 100644 --- a/_extensions/closeread/closeread.css +++ b/_extensions/closeread/closeread.css @@ -20,6 +20,9 @@ .cr-section .narrative-col .trigger p { margin-bottom: 0; } +.cr-section .narrative-col .trigger .narrative:has(.cr-spacer) { + visibility: hidden; +} .cr-section .sticky-col { grid-row: 1; } diff --git a/_extensions/closeread/closeread.css.map b/_extensions/closeread/closeread.css.map index 2179284..0148509 100644 --- a/_extensions/closeread/closeread.css.map +++ b/_extensions/closeread/closeread.css.map @@ -1 +1 @@ -{"version":3,"sourceRoot":"","sources":["closeread.scss"],"names":[],"mappings":"AACA;AAGA;AAEA;AAEA;AAAA;AAAA;AAAA;AAAA;AAMA;EACE;EACA;;AAEA;EACE;;AAEA;EACE;EACA;;AAEA;EACE;;AAKN;EACE;;AAIA;EACE;EACA;EACA;EACA;EACA;;AAEA;EACE;EACA;EAGA;EAEA,YACE;;AAMJ;EACE,YACE;;AAGJ;EACE,YACE;;AAKJ;EACE;;AAIA;EACE;EAEA,YACE;;AAGF;EACE;EAEA,YACA;;AAMJ;EACE;EAEA;;AAGA;EACE;EAEA;;AAIF;EACE;EAEA;;;AASZ;AAEA;EACE;AAAA;AAAA;AAAA;AAAA;IAKE;;EAEA;AAAA;AAAA;AAAA;AAAA;IACE;IACA;IACA;;EAEA;AAAA;AAAA;AAAA;AAAA;IACE;IACA;IACA;IACA;;EAIJ;AAAA;AAAA;AAAA;AAAA;IACE;;;AAQN;AAAA;AAAA;EAGE;;AAEA;AAAA;AAAA;EACE;EACA;EACA;;AAEA;AAAA;AAAA;EACE;EACA;EACA;EACA;;AAIJ;AAAA;AAAA;EACE;;;AAMF;EACE;EACA;;;AAIF;EACE;;;AAIF;EACE;EACA;;;AAMJ;EACE;;AAEA;EACE;EACA;;AAGF;EACE;;;AAGJ;EACE;;AAEA;EACE;EACA;;AAGF;EACE;;;AAKJ;AAAA;AAAA;AAAA;AAAA;EAKE;;AAEA;AAAA;AAAA;AAAA;AAAA;EACE;EACA;EACA;EACA;EACA;;AAGF;AAAA;AAAA;AAAA;AAAA;EACE;;;AAKJ;AAEA;EAEE;AAEA;AAAA;EAEA;EACA;EAEA;EACA;EAGA;;AAGA;EACE;;AAGF;EACE;;;AAIJ;EAEE;EAGA;EACA;EAGA;EAEA;EACA;EAGA;;AAGA;EACE;EAEA;;AAGF;EACE;;;AAKJ;AAKE;EACE;EACA;;AAIF;EACE;;AAKA;EACE;EACA;EACA;;AAEA;EACE;;;AAOR;AAII;EACE;EACA;;AAEA;EACE","file":"closeread.css"} \ No newline at end of file +{"version":3,"sourceRoot":"","sources":["closeread.scss"],"names":[],"mappings":"AACA;AAGA;AAEA;AAEA;AAAA;AAAA;AAAA;AAAA;AAMA;EACE;EACA;;AAEA;EACE;;AAEA;EACE;EACA;;AAEA;EACE;;AAIA;EACE;;AAMR;EACE;;AAIA;EACE;EACA;EACA;EACA;EACA;;AAEA;EACE;EACA;EAGA;EAEA,YACE;;AAMJ;EACE,YACE;;AAGJ;EACE,YACE;;AAKJ;EACE;;AAIA;EACE;EAEA,YACE;;AAGF;EACE;EAEA,YACA;;AAMJ;EACE;EAEA;;AAGA;EACE;EAEA;;AAIF;EACE;EAEA;;;AASZ;AAEA;EACE;AAAA;AAAA;AAAA;AAAA;IAKE;;EAEA;AAAA;AAAA;AAAA;AAAA;IACE;IACA;IACA;;EAEA;AAAA;AAAA;AAAA;AAAA;IACE;IACA;IACA;IACA;;EAIJ;AAAA;AAAA;AAAA;AAAA;IACE;;;AAQN;AAAA;AAAA;EAGE;;AAEA;AAAA;AAAA;EACE;EACA;EACA;;AAEA;AAAA;AAAA;EACE;EACA;EACA;EACA;;AAIJ;AAAA;AAAA;EACE;;;AAMF;EACE;EACA;;;AAIF;EACE;;;AAIF;EACE;EACA;;;AAMJ;EACE;;AAEA;EACE;EACA;;AAGF;EACE;;;AAGJ;EACE;;AAEA;EACE;EACA;;AAGF;EACE;;;AAKJ;AAAA;AAAA;AAAA;AAAA;EAKE;;AAEA;AAAA;AAAA;AAAA;AAAA;EACE;EACA;EACA;EACA;EACA;;AAGF;AAAA;AAAA;AAAA;AAAA;EACE;;;AAKJ;AAEA;EAEE;AAEA;AAAA;EAEA;EACA;EAEA;EACA;EAGA;;AAGA;EACE;;AAGF;EACE;;;AAIJ;EAEE;EAGA;EACA;EAGA;EAEA;EACA;EAGA;;AAGA;EACE;EAEA;;AAGF;EACE;;;AAKJ;AAKE;EACE;EACA;;AAIF;EACE;;AAKA;EACE;EACA;EACA;;AAEA;EACE;;;AAOR;AAII;EACE;EACA;;AAEA;EACE","file":"closeread.css"} \ No newline at end of file diff --git a/_extensions/closeread/closeread.scss b/_extensions/closeread/closeread.scss index dda101d..8c64619 100644 --- a/_extensions/closeread/closeread.scss +++ b/_extensions/closeread/closeread.scss @@ -26,6 +26,12 @@ p { margin-bottom: 0; // override bootstrap rule } + + .narrative { + &:has(.cr-spacer) { + visibility: hidden; + } + } } } diff --git a/_extensions/closeread/spacer.lua b/_extensions/closeread/spacer.lua new file mode 100644 index 0000000..52e1bba --- /dev/null +++ b/_extensions/closeread/spacer.lua @@ -0,0 +1,11 @@ +function spacer(args) + local spacerLength = "40svh" + if args[1] ~= nil then + spacerLength = pandoc.utils.stringify(args[1]) + end + + return pandoc.Div({}, + pandoc.Attr("", + { "cr-spacer" }, + { style = "height: " .. spacerLength })) +end diff --git a/docs/index.qmd b/docs/index.qmd index 9da9849..af272e5 100644 --- a/docs/index.qmd +++ b/docs/index.qmd @@ -40,6 +40,8 @@ Step three: flag an element to become a sticky. [@cr-doc]{highlight="14-18"} Step four: create a trigger to make the sticky appear. [@cr-doc]{highlight="12"} ::: +{{< spacer 80svh >}} + :::{#cr-doc filename="myfirstcr.qmd"} ````markdown --- From 0f43653440c9b3f7cab3e6a0f32aa7212778c8a1 Mon Sep 17 00:00:00 2001 From: andrewpbray Date: Sat, 19 Oct 2024 18:23:58 -0700 Subject: [PATCH 2/5] move shortcode under format key --- _extensions/closeread/_extension.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/_extensions/closeread/_extension.yml b/_extensions/closeread/_extension.yml index cda8078..8736e97 100644 --- a/_extensions/closeread/_extension.yml +++ b/_extensions/closeread/_extension.yml @@ -3,12 +3,12 @@ author: Andrew Bray and James Goldie version: 0.7.0 quarto-required: ">=1.3.0" contributes: - shortcodes: - - spacer.lua formats: html: filters: - closeread.lua + shortcodes: + - spacer.lua css: closeread.css page-layout: full execute: From c625fc3cca541b18d5dd1e757b255a2c72c2ee37 Mon Sep 17 00:00:00 2001 From: andrewpbray Date: Sat, 19 Oct 2024 18:24:39 -0700 Subject: [PATCH 3/5] swap out padding div with spacer --- docs/gallery/examples/minards-map/index.qmd | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/docs/gallery/examples/minards-map/index.qmd b/docs/gallery/examples/minards-map/index.qmd index aade891..3ef3105 100644 --- a/docs/gallery/examples/minards-map/index.qmd +++ b/docs/gallery/examples/minards-map/index.qmd @@ -20,8 +20,7 @@ An especially effective device for enhancing the explanatory power of time-serie :::{.cr-section} -:::{style="padding-block: 20svh"} -::: +{{< spacer 20svh >}} The first is the classic of Charles Joseph Minard (1781-1870), the French engineer, which shows the terrible fate of Napoleon's army in Russia. Described by E. J. Marey as seeming to defy the pen of the historian by its brutal eloquence, 12 this combination of data map and time-series, drawn in 1869, portrays a sequence of devastating losses suffered in Napoleon's Russian campaign of 1812. @cr-map From caed1b710b9ed2348764e797e3ff93796e01175a Mon Sep 17 00:00:00 2001 From: andrewpbray Date: Sat, 19 Oct 2024 18:29:12 -0700 Subject: [PATCH 4/5] change to 10svh --- docs/gallery/examples/minards-map/index.qmd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/gallery/examples/minards-map/index.qmd b/docs/gallery/examples/minards-map/index.qmd index 3ef3105..0ed4859 100644 --- a/docs/gallery/examples/minards-map/index.qmd +++ b/docs/gallery/examples/minards-map/index.qmd @@ -20,7 +20,7 @@ An especially effective device for enhancing the explanatory power of time-serie :::{.cr-section} -{{< spacer 20svh >}} +{{< spacer 10svh >}} The first is the classic of Charles Joseph Minard (1781-1870), the French engineer, which shows the terrible fate of Napoleon's army in Russia. Described by E. J. Marey as seeming to defy the pen of the historian by its brutal eloquence, 12 this combination of data map and time-series, drawn in 1869, portrays a sequence of devastating losses suffered in Napoleon's Russian campaign of 1812. @cr-map From 64f91a58ef1c4e16c317c8679771c6112296e41f Mon Sep 17 00:00:00 2001 From: James Goldie Date: Wed, 30 Oct 2024 16:31:34 +1100 Subject: [PATCH 5/5] Refactor spacer to use padding --- _extensions/closeread/closeread.css | 3 ++- _extensions/closeread/closeread.css.map | 2 +- _extensions/closeread/closeread.scss | 7 +++---- _extensions/closeread/spacer.lua | 17 +++++++++++++++-- 4 files changed, 21 insertions(+), 8 deletions(-) diff --git a/_extensions/closeread/closeread.css b/_extensions/closeread/closeread.css index a4ecef6..8c4041c 100644 --- a/_extensions/closeread/closeread.css +++ b/_extensions/closeread/closeread.css @@ -20,8 +20,9 @@ .cr-section .narrative-col .trigger p { margin-bottom: 0; } -.cr-section .narrative-col .trigger .narrative:has(.cr-spacer) { +.cr-section .narrative-col .trigger:has(.cr-spacer) { visibility: hidden; + padding-block: 0; } .cr-section .sticky-col { grid-row: 1; diff --git a/_extensions/closeread/closeread.css.map b/_extensions/closeread/closeread.css.map index 0148509..3b4edda 100644 --- a/_extensions/closeread/closeread.css.map +++ b/_extensions/closeread/closeread.css.map @@ -1 +1 @@ -{"version":3,"sourceRoot":"","sources":["closeread.scss"],"names":[],"mappings":"AACA;AAGA;AAEA;AAEA;AAAA;AAAA;AAAA;AAAA;AAMA;EACE;EACA;;AAEA;EACE;;AAEA;EACE;EACA;;AAEA;EACE;;AAIA;EACE;;AAMR;EACE;;AAIA;EACE;EACA;EACA;EACA;EACA;;AAEA;EACE;EACA;EAGA;EAEA,YACE;;AAMJ;EACE,YACE;;AAGJ;EACE,YACE;;AAKJ;EACE;;AAIA;EACE;EAEA,YACE;;AAGF;EACE;EAEA,YACA;;AAMJ;EACE;EAEA;;AAGA;EACE;EAEA;;AAIF;EACE;EAEA;;;AASZ;AAEA;EACE;AAAA;AAAA;AAAA;AAAA;IAKE;;EAEA;AAAA;AAAA;AAAA;AAAA;IACE;IACA;IACA;;EAEA;AAAA;AAAA;AAAA;AAAA;IACE;IACA;IACA;IACA;;EAIJ;AAAA;AAAA;AAAA;AAAA;IACE;;;AAQN;AAAA;AAAA;EAGE;;AAEA;AAAA;AAAA;EACE;EACA;EACA;;AAEA;AAAA;AAAA;EACE;EACA;EACA;EACA;;AAIJ;AAAA;AAAA;EACE;;;AAMF;EACE;EACA;;;AAIF;EACE;;;AAIF;EACE;EACA;;;AAMJ;EACE;;AAEA;EACE;EACA;;AAGF;EACE;;;AAGJ;EACE;;AAEA;EACE;EACA;;AAGF;EACE;;;AAKJ;AAAA;AAAA;AAAA;AAAA;EAKE;;AAEA;AAAA;AAAA;AAAA;AAAA;EACE;EACA;EACA;EACA;EACA;;AAGF;AAAA;AAAA;AAAA;AAAA;EACE;;;AAKJ;AAEA;EAEE;AAEA;AAAA;EAEA;EACA;EAEA;EACA;EAGA;;AAGA;EACE;;AAGF;EACE;;;AAIJ;EAEE;EAGA;EACA;EAGA;EAEA;EACA;EAGA;;AAGA;EACE;EAEA;;AAGF;EACE;;;AAKJ;AAKE;EACE;EACA;;AAIF;EACE;;AAKA;EACE;EACA;EACA;;AAEA;EACE;;;AAOR;AAII;EACE;EACA;;AAEA;EACE","file":"closeread.css"} \ No newline at end of file +{"version":3,"sourceRoot":"","sources":["closeread.scss"],"names":[],"mappings":"AACA;AAGA;AAEA;AAEA;AAAA;AAAA;AAAA;AAAA;AAMA;EACE;EACA;;AAEA;EACE;;AAEA;EACE;EACA;;AAEA;EACE;;AAGF;EACE;EACA;;AAKN;EACE;;AAIA;EACE;EACA;EACA;EACA;EACA;;AAEA;EACE;EACA;EAGA;EAEA,YACE;;AAMJ;EACE,YACE;;AAGJ;EACE,YACE;;AAKJ;EACE;;AAIA;EACE;EAEA,YACE;;AAGF;EACE;EAEA,YACA;;AAMJ;EACE;EAEA;;AAGA;EACE;EAEA;;AAIF;EACE;EAEA;;;AASZ;AAEA;EACE;AAAA;AAAA;AAAA;AAAA;IAKE;;EAEA;AAAA;AAAA;AAAA;AAAA;IACE;IACA;IACA;;EAEA;AAAA;AAAA;AAAA;AAAA;IACE;IACA;IACA;IACA;;EAIJ;AAAA;AAAA;AAAA;AAAA;IACE;;;AAQN;AAAA;AAAA;EAGE;;AAEA;AAAA;AAAA;EACE;EACA;EACA;;AAEA;AAAA;AAAA;EACE;EACA;EACA;EACA;;AAIJ;AAAA;AAAA;EACE;;;AAMF;EACE;EACA;;;AAIF;EACE;;;AAIF;EACE;EACA;;;AAMJ;EACE;;AAEA;EACE;EACA;;AAGF;EACE;;;AAGJ;EACE;;AAEA;EACE;EACA;;AAGF;EACE;;;AAKJ;AAAA;AAAA;AAAA;AAAA;EAKE;;AAEA;AAAA;AAAA;AAAA;AAAA;EACE;EACA;EACA;EACA;EACA;;AAGF;AAAA;AAAA;AAAA;AAAA;EACE;;;AAKJ;AAEA;EAEE;AAEA;AAAA;EAEA;EACA;EAEA;EACA;EAGA;;AAGA;EACE;;AAGF;EACE;;;AAIJ;EAEE;EAGA;EACA;EAGA;EAEA;EACA;EAGA;;AAGA;EACE;EAEA;;AAGF;EACE;;;AAKJ;AAKE;EACE;EACA;;AAIF;EACE;;AAKA;EACE;EACA;EACA;;AAEA;EACE;;;AAOR;AAII;EACE;EACA;;AAEA;EACE","file":"closeread.css"} \ No newline at end of file diff --git a/_extensions/closeread/closeread.scss b/_extensions/closeread/closeread.scss index 8c64619..0d26f19 100644 --- a/_extensions/closeread/closeread.scss +++ b/_extensions/closeread/closeread.scss @@ -27,10 +27,9 @@ margin-bottom: 0; // override bootstrap rule } - .narrative { - &:has(.cr-spacer) { - visibility: hidden; - } + &:has(.cr-spacer) { + visibility: hidden; + padding-block: 0; } } } diff --git a/_extensions/closeread/spacer.lua b/_extensions/closeread/spacer.lua index 52e1bba..681d6bd 100644 --- a/_extensions/closeread/spacer.lua +++ b/_extensions/closeread/spacer.lua @@ -1,11 +1,24 @@ function spacer(args) local spacerLength = "40svh" if args[1] ~= nil then - spacerLength = pandoc.utils.stringify(args[1]) + spacerString = pandoc.utils.stringify(args[1]) end + -- split spacer height into number and units + local _, _, spacerNumStr, spacerUnits = + string.find(spacerString, "(%d+)%s?(%a+);?") + local spacerNum = tonumber(spacerNumStr) + + if (spacerNum == nil) then + error("Spacer height should be a number followed by a CSS unit, not " .. + spacerString) + end + + -- halve and join back up + local spacerHeightHalved = tostring(spacerNum / 2) .. (spacerUnits or "") + return pandoc.Div({}, pandoc.Attr("", { "cr-spacer" }, - { style = "height: " .. spacerLength })) + { style = "padding-block: " .. spacerHeightHalved .. ";" })) end