Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Patch up autodoc code blocks #2180

Merged
merged 4 commits into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 14 additions & 13 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)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this change sound right to you @Omikhleia? The whitespace being passed in the \raw blocks now being (legitimately) treated as actual lines seems to be the main problem that blew up the manual. My previous fix was obviously wrong, this seems right now. I did tweak the alignment of the rule just a little bit and used raise instead of manually pushing VGlue because sorting out when to add spacing or not was much easier that way. Hence the final test expectations did change just a small shim. I also did not place \novbreak before and after the cod blocks as that seems to introduce yet another problem we'd have to cancel out.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I can say viewing the code (not tested yet), it seems ok.
What is the problem your are having with novbreak, if I may ask? I've some regression (it seems) on them too, though I've not been able yet to track its origin. (Something changed in paragraphing, possibly unrelated however.)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inside the verbatim (or autodoc:codeblock which does the same thing with line handling, if you do not explicitly leave hmode before adding the novbreaks then it flips you over to vmode itself and you end up with a double break. I didn't work on an MWE.

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,17 +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 bs = SILE.types.measurement("1bs"):absolute()
local ex = SILE.types.measurement("1ex"):absolute()
local pushline = function ()
local pushline = function (offset)
colorWrapper("note", function ()
SILE.call("novbreak")
SILE.typesetter:pushVglue(-bs)
SILE.call("novbreak")
SILE.call("fullrule", { thickness = "0.5pt" })
SILE.call("novbreak")
SILE.typesetter:pushVglue(-bs - 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 @@ -402,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
8 changes: 4 additions & 4 deletions tests/verbatim-lines.expected
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ T 12 118 201 w=12.6431 (Bar)
Mx 31.7393
My 68.0794
T 12 118 238 w=12.6431 (Baz)
Draw line 14.8819 75.3075 267.8740 0.5000
Draw line 14.8819 75.7138 267.8740 0.0000
Mx 14.8819
My 84.8794
T 31 184 184 w=12.6431 (Foo)
Expand All @@ -22,11 +22,11 @@ T 12 118 201 w=12.6431 (Bar)
Mx 31.7393
My 126.8794
T 12 118 238 w=12.6431 (Baz)
Draw line 14.8819 134.1075 267.8740 0.5000
Draw line 14.8819 135.0513 267.8740 0.0000
Mx 14.8819
My 149.6794
My 153.2794
T 87 227 184 w=12.6431 (Two)
My 174.8794
My 178.4794
T 51 158 178 139 205 w=21.0718 (Lines)
End page
Finish
1 change: 0 additions & 1 deletion tests/verbatim-lines.sil
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
% KNOWNBAD https://github.com/sile-typesetter/sile/issues/2168
\begin[papersize=a6]{document}
\nofolios
\neverindent
Expand Down
Loading