Skip to content

Commit

Permalink
Merge pull request #1995 from alerque/more-hyphens-please
Browse files Browse the repository at this point in the history
  • Loading branch information
alerque authored Feb 7, 2024
2 parents 23697f9 + 00df1f7 commit 3bc3814
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 28 deletions.
28 changes: 26 additions & 2 deletions documentation/c08-language.sil
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,19 @@ The default is \code{left}.
\set[parameter=languages.am.justification,value=centered]
\font[family=Noto Sans Ethiopic,language=am]{ሰላም፡ልዑል}

\begin[command=document-repeated-hyphen]{define}
According to \process typography conventions, when a break occurs at an explicit hyphen, the hyphen gets repeated at the beginning of the new line.
SILE automatically handles this.
\end{define}

\subsection{Croatian}

\document-repeated-hyphen{Croatian}

\subsection{Czech}

\document-repeated-hyphen{Czech}

\subsection{Esperanto}

\define[command=eo]{\font[language=eo]{\process}}
Expand All @@ -188,8 +201,19 @@ The size of these spaces is determined by

\subsection{Polish}

According to Polish typography conventions, when a break occurs at an explicit hyphen, the hyphen gets repeated at the beginning of the new line.
SILE automatically handles this.
\document-repeated-hyphen{Polish}

\subsection{Portuguese}

\document-repeated-hyphen{Portuguese}

\subsection{Slovak}

\document-repeated-hyphen{Slovak}

\subsection{Spanish}

\document-repeated-hyphen{Spanish}

\subsection{Turkish}

Expand Down
6 changes: 6 additions & 0 deletions languages/cs.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
SILE.nodeMakers.cs = pl.class(SILE.nodeMakers.unicode)

-- According to Czech rules, when a break occurs at an explicit hyphen, the hyphen gets repeated on the next line...
SILE.nodeMakers.cs.handleWordBreak = SILE.nodeMakers.unicode._handleWordBreakRepeatHyphen
SILE.nodeMakers.cs.handlelineBreak = SILE.nodeMakers.unicode._handlelineBreakRepeatHyphen

SILE.hyphenator.languages["cs"] = {}
SILE.hyphenator.languages["cs"].patterns =
{
Expand Down
6 changes: 6 additions & 0 deletions languages/es.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
SILE.nodeMakers.es = pl.class(SILE.nodeMakers.unicode)

-- According to Spanish rules, when a break occurs at an explicit hyphen, the hyphen gets repeated on the next line...
SILE.nodeMakers.es.handleWordBreak = SILE.nodeMakers.unicode._handleWordBreakRepeatHyphen
SILE.nodeMakers.es.handlelineBreak = SILE.nodeMakers.unicode._handlelineBreakRepeatHyphen

SILE.hyphenator.languages["es"] = {}
SILE.hyphenator.languages["es"].patterns =
{
Expand Down
6 changes: 6 additions & 0 deletions languages/hr.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
SILE.nodeMakers.hr = pl.class(SILE.nodeMakers.unicode)

-- According to Croation rules, when a break occurs at an explicit hyphen, the hyphen gets repeated on the next line...
SILE.nodeMakers.hr.handleWordBreak = SILE.nodeMakers.unicode._handleWordBreakRepeatHyphen
SILE.nodeMakers.hr.handlelineBreak = SILE.nodeMakers.unicode._handlelineBreakRepeatHyphen

SILE.hyphenator.languages["hr"] = {}
SILE.hyphenator.languages["hr"].patterns =
{
Expand Down
29 changes: 3 additions & 26 deletions languages/pl.lua
Original file line number Diff line number Diff line change
@@ -1,31 +1,8 @@
SILE.nodeMakers.pl = pl.class(SILE.nodeMakers.unicode)

function SILE.nodeMakers.pl:handleWordBreak (item)
-- According to Polish rules, when a break occurs at an explicit hyphen,
-- the hyphen gets repeated at the beginning of the new line
if item.text == "-" then
self:addToken(item.text, item)
self:makeToken()
if self.lastnode ~= "discretionary" then
coroutine.yield(SILE.nodefactory.discretionary({
postbreak = SILE.shaper:createNnodes("-", self.options)
}))
self.lastnode = "discretionary"
end
else
self._base.handleWordBreak(self, item)
end
end

function SILE.nodeMakers.pl:handleLineBreak (item, subtype)
if self.lastnode == "discretionary" then
-- Initial word boundary after a discretionary:
-- Bypass it and just deal with the token.
self:dealWith(item)
else
self._base.handleLineBreak(self, item, subtype)
end
end
-- According to Polish rules, when a break occurs at an explicit hyphen, the hyphen gets repeated on the next line...
SILE.nodeMakers.pl.handleWordBreak = SILE.nodeMakers.unicode._handleWordBreakRepeatHyphen
SILE.nodeMakers.pl.handlelineBreak = SILE.nodeMakers.unicode._handlelineBreakRepeatHyphen

SILE.hyphenator.languages["pl"] = {}
SILE.hyphenator.languages["pl"].patterns =
Expand Down
6 changes: 6 additions & 0 deletions languages/pt.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
SILE.nodeMakers.pt = pl.class(SILE.nodeMakers.unicode)

-- According to Portuguese rules, when a break occurs at an explicit hyphen, the hyphen gets repeated on the next line...
SILE.nodeMakers.pt.handleWordBreak = SILE.nodeMakers.unicode._handleWordBreakRepeatHyphen
SILE.nodeMakers.pt.handlelineBreak = SILE.nodeMakers.unicode._handlelineBreakRepeatHyphen

SILE.hyphenator.languages["pt"] = {}
SILE.hyphenator.languages["pt"].patterns =
{
Expand Down
6 changes: 6 additions & 0 deletions languages/sk.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
SILE.nodeMakers.sk = pl.class(SILE.nodeMakers.unicode)

-- According to Slovak rules, when a break occurs at an explicit hyphen, the hyphen gets repeated on the next line...
SILE.nodeMakers.sk.handleWordBreak = SILE.nodeMakers.unicode._handleWordBreakRepeatHyphen
SILE.nodeMakers.sk.handlelineBreak = SILE.nodeMakers.unicode._handlelineBreakRepeatHyphen

SILE.hyphenator.languages["sk"] = {}
SILE.hyphenator.languages["sk"].patterns =
{
Expand Down
27 changes: 27 additions & 0 deletions languages/unicode.lua
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,23 @@ function SILE.nodeMakers.unicode:handleWordBreak (item)
end
end

function SILE.nodeMakers.unicode:_handleWordBreakRepeatHyphen (item)
-- According to some language rules, when a break occurs at an explicit hyphen,
-- the hyphen gets repeated at the beginning of the new line
if item.text == "-" then
self:addToken(item.text, item)
self:makeToken()
if self.lastnode ~= "discretionary" then
coroutine.yield(SILE.nodefactory.discretionary({
postbreak = SILE.shaper:createNnodes("-", self.options)
}))
self.lastnode = "discretionary"
end
else
SILE.nodeMakers.unicode.handleWordBreak(self, item)
end
end

function SILE.nodeMakers.unicode:handleLineBreak (item, subtype)
-- Because we are in charge of paragraphing, we
-- will override space-type line breaks, and treat
Expand All @@ -211,6 +228,16 @@ function SILE.nodeMakers.unicode:handleLineBreak (item, subtype)
self.lasttype = chardata[cp] and chardata[cp].linebreak
end

function SILE.nodeMakers.unicode:_handleLineBreakRepeatHyphen (item, subtype)
if self.lastnode == "discretionary" then
-- Initial word boundary after a discretionary:
-- Bypass it and just deal with the token.
self:dealWith(item)
else
SILE.nodeMakers.unicode.handleLineBreak(self, item, subtype)
end
end

function SILE.nodeMakers.unicode:iterator (items)
local fulltext = ""
for i = 1, #items do
Expand Down

0 comments on commit 3bc3814

Please sign in to comment.