Skip to content

Commit

Permalink
refactor(packages): Align rules in autodoc code blocks without disrup…
Browse files Browse the repository at this point in the history
…ting location
  • Loading branch information
alerque committed Nov 25, 2024
1 parent 3a9181a commit 3c0bd31
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions packages/autodoc/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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")
Expand All @@ -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)
Expand Down

0 comments on commit 3c0bd31

Please sign in to comment.