Skip to content

Commit

Permalink
feat(typesetters): Support U+00AD soft hyphen as discretionary break
Browse files Browse the repository at this point in the history
  • Loading branch information
Omikhleia authored and Didier Willis committed Dec 13, 2023
1 parent 44b7f10 commit 285507e
Showing 1 changed file with 36 additions and 1 deletion.
37 changes: 36 additions & 1 deletion typesetters/base.lua
Expand Up @@ -132,6 +132,19 @@ function typesetter.declareSettings(_)
help = "Width to break lines at"
})

SILE.settings:declare({
parameter = "typesetter.softHyphen",
type = "boolean",
default = true,
help = "When true, soft hyphens are rendered as discretionary breaks, otherwise they are ignored"
})

SILE.settings:declare({
parameter = "typesetter.softHyphenWarning",
type = "boolean",
default = false,
help = "When true, a warning is issued when a soft hyphen is encountered"
})
end

function typesetter:initState ()
Expand Down Expand Up @@ -276,7 +289,29 @@ function typesetter:typeset (text)
if token.separator then
self:endline()
else
self:setpar(token.string)
if SILE.settings:get("typesetter.softHyphen") then
local warnedshy = false
for token2 in SU.gtoke(token.string, luautf8.char(0x00AD)) do
if token2.separator then -- soft hyphen support
local discretionary = SILE.nodefactory.discretionary({})
local hbox = SILE.typesetter:makeHbox({ SILE.settings:get("font.hyphenchar") })
discretionary.prebreak = { hbox }
table.insert(SILE.typesetter.state.nodes, discretionary)
if not warnedshy and SILE.settings:get("typesetter.softHyphenWarning") then
SU.warn("Soft hyphen encountered and replaced with discretionary")
end
warnedshy = true
else
self:setpar(token2.string)
end
end
else
if SILE.settings:get("typesetter.softHyphenWarning") and luautf8.match(token.string, luautf8.char(0x00AD)) then
SU.warn("Soft hyphen encountered and ignored")
end
text = luautf8.gsub(token.string, luautf8.char(0x00AD), "")
self:setpar(text)
end
end
end
SILE.traceStack:pop(pId)
Expand Down

0 comments on commit 285507e

Please sign in to comment.