Skip to content

Commit

Permalink
Merge 144cbbe into c8a1467
Browse files Browse the repository at this point in the history
  • Loading branch information
Omikhleia committed Mar 14, 2023
2 parents c8a1467 + 144cbbe commit 234a677
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions packages/tableofcontents/init.lua
Expand Up @@ -58,14 +58,19 @@ end
-- (Similar to SU.contentToString(), but allows passing typeset
-- objects to functions that need plain strings).
local function _nodesToText (nodes)
local spc = SILE.measurement("0.8spc"):tonumber() -- approx. see below.
local string = ""
for i = 1, #nodes do
local node = nodes[i]
if node.is_nnode or node.is_unshaped then
string = string .. node:toText()
elseif node.is_glue then
-- Not so sure about this one...
if node.width:tonumber() > 0 then
elseif node.is_glue or node.is_kern then
-- What we want to avoid is "small" glues or kerns to be expanded as
-- full spaces. Comparing to a "decent" ratio of a space is fragile and
-- empirical: the content could contain font changes, so the comparison
-- is wrong in the general case. It's still better than nothing.
-- (That's what the debug text outputter does to, by the way).
if node.width:tonumber() > spc then
string = string .. " "
end
elseif not (node.is_zerohbox or node.is_migrating) then
Expand All @@ -77,7 +82,8 @@ local function _nodesToText (nodes)
SU.warn("Some content could not be converted to text: "..node)
end
end
return string
-- Trim leading and trailing spaces, and simplify internal spaces.
return pl.stringx.strip(string):gsub("%s%s+", " ")
end

if not SILE.scratch.pdf_destination_counter then
Expand Down

0 comments on commit 234a677

Please sign in to comment.