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

Test and fix verbatim line handling #2129

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
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
14 changes: 6 additions & 8 deletions packages/autodoc/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -372,10 +372,13 @@ function package:registerCommands ()
-- Homogenizing the appearance of blocks of code
self:registerCommand("autodoc:codeblock", function (_, 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()
SILE.settings:temporarily(function ()
-- Note: We avoid using the verbatim environment and simplify things a bit
-- (and try to better enforce novbreak points of insertion)
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 ()
Expand All @@ -391,20 +394,15 @@ function package:registerCommands ()
end
SILE.settings:set("typesetter.parseppattern", "\n")
SILE.settings:set("typesetter.obeyspaces", true)
SILE.settings:set("document.lskip", SILE.types.node.glue(lskip.width.length))
SILE.settings:set("document.rskip", SILE.types.node.glue(rskip.width.length))
SILE.settings:set("document.parindent", SILE.types.node.glue())
SILE.settings:set("document.parskip", SILE.types.node.vglue(0.3 * ex))
SILE.settings:set("document.baselineskip", SILE.types.node.glue(2.3 * ex))
SILE.settings:set("document.parskip", SILE.types.node.vglue())
SILE.settings:set("document.spaceskip", SILE.types.length("1spc"))
SILE.settings:set("shaper.variablespaces", false)
SILE.settings:set("document.language", "und")
colorWrapper("codeblock", function ()
SILE.call("skip", { height = ex })
pushline()
SILE.typesetter:pushVglue(SILE.settings:get("document.parskip"))
SILE.call("novbreak")
SILE.process(content)
SILE.call("novbreak")
SILE.typesetter:pushVglue(SILE.settings:get("document.parskip"))
pushline()
end)
SILE.typesetter:leaveHmode()
Expand Down
18 changes: 10 additions & 8 deletions packages/verbatim/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,22 @@ function package:registerCommands ()
self:registerCommand("verbatim", function (_, content)
SILE.typesetter:pushVglue(6)
SILE.typesetter:leaveHmode()
SILE.settings:temporarily(function ()
local lskip = SILE.settings:get("document.lskip") or SILE.types.node.glue()
local rskip = SILE.settings:get("document.rskip") or SILE.types.node.glue()
SILE.settings:temporarily(function()
SILE.call("verbatim:font")
SILE.call("language", { main = "und" })
SILE.settings:set("typesetter.parseppattern", "\n")
SILE.settings:set("typesetter.obeyspaces", true)
SILE.settings:set("document.rskip", SILE.types.node.glue("0 plus 10000pt"))
SILE.settings:set("document.parindent", SILE.types.node.glue("0"))
SILE.settings:set("document.baselineskip", SILE.types.node.vglue("0"))
SILE.settings:set("document.lineskip", SILE.types.node.vglue("2pt"))
SILE.call("verbatim:font")
SILE.settings:set("document.lskip", SILE.types.node.glue(lskip.width.length))
SILE.settings:set("document.rskip", SILE.types.node.glue(rskip.width.length))
SILE.settings:set("document.parindent", SILE.types.node.glue())
SILE.settings:set("document.parskip", SILE.types.node.vglue())
SILE.settings:set("document.spaceskip", SILE.types.length("1spc"))
SILE.settings:set("shaper.variablespaces", false)
SILE.settings:set("document.language", "und")
SILE.process(content)
SILE.typesetter:leaveHmode()
end)
SILE.typesetter:leaveHmode()
end, "Typesets its contents in a monospaced font.")

self:registerCommand("obeylines", function (_, content)
Expand Down
32 changes: 32 additions & 0 deletions tests/verbatim-lines.sil
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
\begin[papersize=a6]{document}
\nofolios
\neverindent
\use[module=packages.verbatim]
\use[module=packages.autodoc]

\begin{verbatim}
Foo

Bar
Bar

Baz
\end{verbatim}

\begin[type=autodoc:codeblock]{raw}
Foo

Bar
Bar

Baz
\end{raw}

\begin{verbatim}
Two


Lines
\end{verbatim}

\end{document}
17 changes: 16 additions & 1 deletion typesetters/base.lua
Original file line number Diff line number Diff line change
Expand Up @@ -295,10 +295,25 @@ function typesetter:typeset (text)
return
end
local pId = SILE.traceStack:pushText(text)
for token in SU.gtoke(text, SILE.settings:get("typesetter.parseppattern")) do
local parsepattern = SILE.settings:get("typesetter.parseppattern")
-- NOTE: Big assumption on how to guess were are in "obeylines" mode.
-- See https://github.com/sile-typesetter/sile/issues/2128
local obeylines = parsepattern == "\n"

local seenParaContent = true
for token in SU.gtoke(text, parsepattern) do
if token.separator then
if obeylines and not seenParaContent then
-- In obeylines mode, each standalone line must be kept.
-- The zerohbox is not discardable, so it will be kept in the output,
-- and the baseline skip will do the rest.
self:pushHorizontal(SILE.types.node.zerohbox())
else
seenParaContent = false
end
self:endline()
else
seenParaContent = true
if SILE.settings:get("typesetter.softHyphen") then
local warnedshy = false
for token2 in SU.gtoke(token.string, luautf8.char(0x00AD)) do
Expand Down
Loading