summaryrefslogtreecommitdiff
path: root/tex/context/base/mkiv/lang-rep.lua
diff options
context:
space:
mode:
authorHans Hagen <pragma@wxs.nl>2020-08-24 20:03:53 +0200
committerContext Git Mirror Bot <phg@phi-gamma.net>2020-08-24 20:03:53 +0200
commit89f7bbac9616406b3990b8608c17c542f5fb476d (patch)
tree9e487938454fd224025391d975ae85dff85a10f8 /tex/context/base/mkiv/lang-rep.lua
parent4ba731dd6ff370a42984b4df050906fd9a884bc8 (diff)
downloadcontext-89f7bbac9616406b3990b8608c17c542f5fb476d.tar.gz
2020-08-24 19:49:00
Diffstat (limited to 'tex/context/base/mkiv/lang-rep.lua')
-rw-r--r--tex/context/base/mkiv/lang-rep.lua24
1 files changed, 16 insertions, 8 deletions
diff --git a/tex/context/base/mkiv/lang-rep.lua b/tex/context/base/mkiv/lang-rep.lua
index d0f6f6d5f..a48215781 100644
--- a/tex/context/base/mkiv/lang-rep.lua
+++ b/tex/context/base/mkiv/lang-rep.lua
@@ -40,6 +40,10 @@ local trace_details = false trackers.register("languages.replacements.deta
local report_replacement = logs.reporter("languages","replacements")
local glyph_code = nodes.nodecodes.glyph
+local glue_code = nodes.nodecodes.glue
+
+local spaceskip_code = nodes.gluecodes.spaceskip
+local xspaceskip_code = nodes.gluecodes.xspaceskip
local nuts = nodes.nuts
@@ -47,6 +51,7 @@ local getnext = nuts.getnext
local getprev = nuts.getprev
local getattr = nuts.getattr
local getid = nuts.getid
+local getsubtype = nuts.getsubtype
local getchar = nuts.getchar
local isglyph = nuts.isglyph
@@ -105,7 +110,7 @@ lists[v_reset].attribute = unsetvalue -- so we discard 0
local function add(root,word,replacement)
local processor, replacement = splitprocessor(replacement,true) -- no check
replacement = lpegmatch(stripper,replacement) or replacement
- local list = utfsplit(word,true)
+ local list = utfsplit(word) -- ,true)
local size = #list
for i=1,size do
local l = utfbyte(list[i])
@@ -169,9 +174,12 @@ local function hit(a,head)
local lastfinal = false
while current do
local char, id = isglyph(current)
- -- if not char and id == glue_code then
- -- char = " " -- if needed we can also deal with spaces and special nbsp and such
- -- end
+ if not char and id == glue_code then
+ local s = getsubtype(current)
+ if s == spaceskip_code or s == xspaceskip_code then
+ char = 32 -- if needed we can also deal with spaces and special nbsp and such
+ end
+ end
if char then
local newroot = root[char]
if not newroot then
@@ -288,9 +296,9 @@ function replacements.handler(head)
i = i + 1
end
flush_list(list)
- elseif newlength == 0 then
- -- nothing gets replaced
- current = getnext(last)
+ -- elseif newlength == 0 then
+ -- -- nothing gets replaced
+ -- current = getnext(last)
elseif oldlength == newlength then -- #old == #new
if final.word == final.replacement then
-- nothing to do but skip
@@ -311,7 +319,7 @@ function replacements.handler(head)
setchar(current,newcodes[i])
current = getnext(current)
end
- else -- #old > #new
+ else -- #old > #new or #new == 0
for i=1,oldlength-newlength do
head, current = remove_node(head,current,true)
end