From 3c0bd311996469779f36890c2836f5f1892d5eb4 Mon Sep 17 00:00:00 2001 From: Caleb Maclennan Date: Mon, 25 Nov 2024 16:11:29 +0300 Subject: [PATCH] refactor(packages): Align rules in autodoc code blocks without disrupting location --- packages/autodoc/init.lua | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/packages/autodoc/init.lua b/packages/autodoc/init.lua index 765f85c9b..c0c5f4b88 100644 --- a/packages/autodoc/init.lua +++ b/packages/autodoc/init.lua @@ -371,6 +371,11 @@ function package:registerCommands () -- Homogenizing the appearance of blocks of code self:registerCommand("autodoc:codeblock", function (_, content) + -- The way we use this command in the SILE manual is both on it's own *and* nested inside + -- a \raw environment. For this purpose we don't care about and don't want to bother with + -- making sure the leading and trailing whitespace is minimized in the SIL source, so + -- we trim it off here. + content = SU.ast.trimSubContent(content) SILE.typesetter:leaveHmode() local lskip = SILE.settings:get("document.lskip") or SILE.types.node.glue() local rskip = SILE.settings:get("document.rskip") or SILE.types.node.glue() @@ -380,16 +385,11 @@ function package:registerCommands () SILE.call("verbatim:font") SILE.call("language", { main = "und" }) -- Rather than absolutizing 4 different values, just do it once and cache it - local ex = SILE.types.measurement("1ex"):absolute() - local pushline = function () + local pushline = function (offset) colorWrapper("note", function () - SILE.call("novbreak") - SILE.typesetter:pushVglue(ex) - SILE.call("novbreak") - SILE.call("fullrule", { thickness = "0.5pt" }) - SILE.call("novbreak") - SILE.typesetter:pushVglue(-ex) - SILE.call("novbreak") + SILE.call("raise", { height = offset }, function () + SILE.call("hrule", { thickness = "0.5pt", width = "100%lw" }) + end) end) end SILE.settings:set("typesetter.parseppattern", "\n") @@ -401,12 +401,14 @@ function package:registerCommands () SILE.settings:set("document.spaceskip", SILE.types.length("1spc")) SILE.settings:set("shaper.variablespaces", false) colorWrapper("codeblock", function () - pushline() + pushline("0.2ex") + SILE.call("novbreak") SILE.process(content) - pushline() + SILE.call("novbreak") + pushline("1ex") end) - SILE.typesetter:leaveHmode() end) + SILE.typesetter:leaveHmode() end, "Outputs its content as a standardized block of code") self:registerCommand("autodoc:example", function (_, content)