summaryrefslogtreecommitdiff
path: root/tex/context/base/supp-box.lua
diff options
context:
space:
mode:
authorHans Hagen <pragma@wxs.nl>2013-10-10 14:36:00 +0200
committerHans Hagen <pragma@wxs.nl>2013-10-10 14:36:00 +0200
commit3d619de789d22758716e3d327b53da4bd790592a (patch)
tree5a0f8c8085f7b442df6a907488253f8dd19061ee /tex/context/base/supp-box.lua
parent08f0e17c9be1e146728ca331fb892cb6c6023597 (diff)
downloadcontext-3d619de789d22758716e3d327b53da4bd790592a.tar.gz
beta 2013.10.10 14:36
Diffstat (limited to 'tex/context/base/supp-box.lua')
-rw-r--r--tex/context/base/supp-box.lua67
1 files changed, 61 insertions, 6 deletions
diff --git a/tex/context/base/supp-box.lua b/tex/context/base/supp-box.lua
index a8603ace3..bc0a7056e 100644
--- a/tex/context/base/supp-box.lua
+++ b/tex/context/base/supp-box.lua
@@ -10,8 +10,12 @@ if not modules then modules = { } end modules ['supp-box'] = {
local report_hyphenation = logs.reporter("languages","hyphenation")
-local tex, node = tex, node
-local context, commands, nodes = context, commands, nodes
+local tex = tex
+local context = context
+local commands = commands
+local nodes = nodes
+
+local splitstring = string.split
local nodecodes = nodes.nodecodes
@@ -25,10 +29,10 @@ local new_penalty = nodes.pool.penalty
local new_hlist = nodes.pool.hlist
local new_glue = nodes.pool.glue
-local free_node = node.free
-local copy_list = node.copy_list
-local copy_node = node.copy
-local find_tail = node.tail
+local free_node = nodes.free
+local copy_list = nodes.copy_list
+local copy_node = nodes.copy
+local find_tail = nodes.tail
local texsetbox = tex.setbox
local texgetbox = tex.getbox
@@ -117,6 +121,57 @@ end
commands.applytochars = applytochars
commands.applytowords = applytowords
+local split_char = lpeg.Ct(lpeg.C(1)^0)
+local split_word = lpeg.tsplitat(lpeg.patterns.space)
+local split_line = lpeg.tsplitat(lpeg.patterns.eol)
+
+function commands.processsplit(str,command,how,spaced)
+ how = how or "word"
+ if how == "char" then
+ local words = lpeg.match(split_char,str)
+ for i=1,#words do
+ local word = words[i]
+ if word == " " then
+ if spaced then
+ context.space()
+ end
+ elseif command then
+ context[command](word)
+ else
+ context(word)
+ end
+ end
+ elseif how == "word" then
+ local words = lpeg.match(split_word,str)
+ for i=1,#words do
+ local word = words[i]
+ if spaced and i > 1 then
+ context.space()
+ end
+ if command then
+ context[command](word)
+ else
+ context(word)
+ end
+ end
+ elseif how == "line" then
+ local words = lpeg.match(split_line,str)
+ for i=1,#words do
+ local word = words[i]
+ if spaced and i > 1 then
+ context.par()
+ end
+ if command then
+ context[command](word)
+ else
+ context(word)
+ end
+ end
+ else
+ context(str)
+ end
+end
+
function commands.vboxlisttohbox(original,target,inbetween)
local current = texgetbox(original).list
local head = nil