summaryrefslogtreecommitdiff
path: root/tex/context/base/mkiv/typo-wrp.lua
diff options
context:
space:
mode:
authorHans Hagen <pragma@wxs.nl>2018-07-20 21:48:33 +0200
committerContext Git Mirror Bot <phg@phi-gamma.net>2018-07-20 21:48:33 +0200
commitdeab0bfe7f4be57121779e93bf291e518fda7cf3 (patch)
treed206a8e495944e2f6ce1d3dea688309012904825 /tex/context/base/mkiv/typo-wrp.lua
parente09328e5e3230ee408f6af2cd454848c4d056702 (diff)
downloadcontext-deab0bfe7f4be57121779e93bf291e518fda7cf3.tar.gz
2018-07-20 21:28:00
Diffstat (limited to 'tex/context/base/mkiv/typo-wrp.lua')
-rw-r--r--tex/context/base/mkiv/typo-wrp.lua75
1 files changed, 47 insertions, 28 deletions
diff --git a/tex/context/base/mkiv/typo-wrp.lua b/tex/context/base/mkiv/typo-wrp.lua
index 13bb5a0cc..3be64f53e 100644
--- a/tex/context/base/mkiv/typo-wrp.lua
+++ b/tex/context/base/mkiv/typo-wrp.lua
@@ -8,48 +8,67 @@ if not modules then modules = { } end modules ['typo-wrp'] = {
-- begin/end par wrapping stuff ... more to come
-local nodecodes = nodes.nodecodes
+local nodecodes = nodes.nodecodes
+local gluecodes = nodes.gluecodes
+local penaltycodes = nodes.penaltycodes
+local boundarycodes = nodes.boundarycodes
-local glue_code = nodecodes.glue
-local penalty_code = nodecodes.penalty
-local parfill_skip_code = nodes.gluecodes.parfillskip
-local user_penalty_code = nodes.penaltycodes.userpenalty
+local glue_code = nodecodes.glue
+local penalty_code = nodecodes.penalty
+local boundary_code = nodecodes.boundary
-local nuts = nodes.nuts
+local parfill_skip_code = gluecodes.parfillskip
-local find_node_tail = nuts.tail
-local getprev = nuts.getprev
-local getid = nuts.getid
-local getsubtype = nuts.getsubtype
-local getpenalty = nuts.getpenalty
-local remove = nuts.remove
+local user_penalty_code = penaltycodes.userpenalty
+local line_penalty_code = penaltycodes.linepenalty
+local linebreak_penalty_code = penaltycodes.linebreakpenalty
-local enableaction = nodes.tasks.enableaction
+local word_boundary_code = boundarycodes.word
-local wrappers = { }
-typesetters.wrappers = wrappers
+local nuts = nodes.nuts
-local trace_wrappers = trackers.register("typesetters.wrappers",function(v) trace_wrappers = v end)
+local find_node_tail = nuts.tail
+local getprev = nuts.getprev
+local getid = nuts.getid
+local getsubtype = nuts.getsubtype
+local getpenalty = nuts.getpenalty
+local remove = nuts.remove
-local report = logs.reporter("paragraphs","wrappers")
+local enableaction = nodes.tasks.enableaction
+
+local wrappers = { }
+typesetters.wrappers = wrappers
+
+local trace_wrappers = trackers.register("typesetters.wrappers",function(v) trace_wrappers = v end)
+
+local report = logs.reporter("paragraphs","wrappers")
-- we really need to pass tail too ... but then we need to check all the plugins
-- bah ... slowdown
+-- This check is very tight to the crlf definition. We check for:
+--
+-- [break -10000] [wordboundary] [line(break)penalty] [parfillskip]
+--
+-- If needed we can extend this checker for other cases but then we will also
+-- use attributes.
+
local function remove_dangling_crlf(head,tail)
- if tail and getid(tail) == glue_code and getsubtype(tail) == parfill_skip_code then
+ if head and tail and getid(tail) == glue_code and getsubtype(tail) == parfill_skip_code then
tail = getprev(tail)
- if tail and getid(tail) == penalty_code and getsubtype(tail) == user_penalty_code and getpenalty(tail) == 10000 then
- tail = getprev(tail)
- if tail and getid(tail) == penalty_code and getsubtype(tail) == user_penalty_code and getpenalty(tail) == -10000 then
- if tail == head then
- -- can't happen
- else
- if trace_wrappers then
- report("removing a probably unwanted end-of-par break in line %s (guess)",tex.inputlineno)
+ if tail and getid(tail) == penalty_code then
+ local subtype = getsubtype(tail)
+ if subtype == line_penalty_code or subtype == linebreak_penalty_code then
+ tail = getprev(tail)
+ if tail and getid(tail) == boundary_code and getsubtype(tail) == word_boundary_code then
+ tail = getprev(tail)
+ if tail ~= head and getid(tail) == penalty_code and getsubtype(tail) == user_penalty_code and getpenalty(tail) == -10000 then
+ if trace_wrappers then
+ report("removing a probably unwanted end-of-par break in line %s (guess)",tex.inputlineno)
+ end
+ remove(head,tail,true)
+ return head, tail
end
- remove(head,tail,true)
- return head, tail
end
end
end