summaryrefslogtreecommitdiff
path: root/tex/context/base/node-par.lua
diff options
context:
space:
mode:
Diffstat (limited to 'tex/context/base/node-par.lua')
-rw-r--r--tex/context/base/node-par.lua75
1 files changed, 53 insertions, 22 deletions
diff --git a/tex/context/base/node-par.lua b/tex/context/base/node-par.lua
index ee0dfaf8a..a8ad969fe 100644
--- a/tex/context/base/node-par.lua
+++ b/tex/context/base/node-par.lua
@@ -9,54 +9,85 @@ if not modules then modules = { } end modules ['node-par'] = {
parbuilders = parbuilders or { }
parbuilders.constructors = parbuilders.constructors or { }
parbuilders.names = parbuilders.names or { }
+parbuilders.numbers = parbuilders.numbers or { }
parbuilders.attribute = attributes.numbers['parbuilder'] or 999
-local constructors, names, p_attribute = parbuilders.constructors, parbuilders.names, parbuilders.attribute
+storage.register("parbuilders.names", parbuilders.names, "parbuilders.names")
+storage.register("parbuilders.numbers", parbuilders.numbers, "parbuilders.numbers")
-storage.register("parbuilders.names", parbuilders.names, "parbuilders.names")
+local constructors, names, numbers, p_attribute = parbuilders.constructors, parbuilders.names, parbuilders.numbers, parbuilders.attribute
local has_attribute = node.has_attribute
local starttiming, stoptiming = statistics.starttiming, statistics.stoptiming
--- store parbuilders.names
+local mainconstructor = nil -- not stored in format
-function parbuilders.register(name,attribute)
- parbuilders.names[attribute] = name
+function parbuilders.register(name,number)
+ parbuilders.names[number] = name
+ parbuilders.numbers[name] = number
end
-function parbuilders.constructor(head,is_display)
- local attribute = has_attribute(head,p_attribute)
- if attribute then
- local constructor = names[attribute]
- if constructor then
- return constructors[constructor](head,is_display)
+function parbuilders.setmain(name)
+ mainconstructor = numbers[name]
+end
+
+-- return values:
+--
+-- true : tex will break itself
+-- false : idem but dangerous
+-- head : list of valid vmode nodes with last being hlist
+
+function parbuilders.constructor(head,followed_by_display)
+ if type(head) == "boolean" then
+ return head
+ else
+ local attribute = has_attribute(head,p_attribute) or mainconstructor
+ if attribute then
+ local constructor = names[attribute]
+ if constructor then
+ return constructors[constructor](head,followed_by_display)
+ end
end
+ return true -- let tex break
end
- return false
end
-- just for testing
-function parbuilders.constructors.default(head,is_display)
- return false
+function parbuilders.constructors.default(head,followed_by_display)
+ return true -- let tex break
end
-- also for testing (no surrounding spacing done)
-function parbuilders.constructors.oneline(head,is_display)
+function parbuilders.constructors.oneline(head,followed_by_display)
return node.hpack(head)
end
-local actions = tasks.actions("parbuilders",1)
+-- It makes no sense to have a sequence here as we already have
+-- pre and post hooks and only one parbuilder makes sense, so no:
+--
+-- local actions = tasks.actions("parbuilders",1)
+
+-- todo: enable one as main
-local function processor(head,is_display)
- starttiming(parbuilders)
- local _, done = actions(head,is_display)
- stoptiming(parbuilders)
- return done
+local actions = parbuilders.constructor
+local enabled = false
+
+function parbuilders.enable () enabled = true end
+function parbuilders.disable() enabled = false end
+
+local function processor(head,followed_by_display)
+ if enabled then
+ starttiming(parbuilders)
+ local head = actions(head,followed_by_display)
+ stoptiming(parbuilders)
+ return head
+ else
+ return true -- ler tex do the work
+ end
end
---~ callbacks.register('linebreak_filter', actions, "breaking paragraps into lines")
callbacks.register('linebreak_filter', processor, "breaking paragraps into lines")
statistics.register("linebreak processing time", function()