summaryrefslogtreecommitdiff
path: root/tex/context/base/mkiv/strc-lev.lua
diff options
context:
space:
mode:
authorContext Git Mirror Bot <phg42.2a@gmail.com>2016-01-12 17:15:07 +0100
committerContext Git Mirror Bot <phg42.2a@gmail.com>2016-01-12 17:15:07 +0100
commit8d8d528d2ad52599f11250cfc567fea4f37f2a8b (patch)
tree94286bc131ef7d994f9432febaf03fe23d10eef8 /tex/context/base/mkiv/strc-lev.lua
parentf5aed2e51223c36c84c5f25a6cad238b2af59087 (diff)
downloadcontext-8d8d528d2ad52599f11250cfc567fea4f37f2a8b.tar.gz
2016-01-12 16:26:00
Diffstat (limited to 'tex/context/base/mkiv/strc-lev.lua')
-rw-r--r--tex/context/base/mkiv/strc-lev.lua75
1 files changed, 75 insertions, 0 deletions
diff --git a/tex/context/base/mkiv/strc-lev.lua b/tex/context/base/mkiv/strc-lev.lua
new file mode 100644
index 000000000..d7ffd6af4
--- /dev/null
+++ b/tex/context/base/mkiv/strc-lev.lua
@@ -0,0 +1,75 @@
+if not modules then modules = { } end modules ['strc-lev'] = {
+ version = 1.001,
+ comment = "companion to strc-lev.mkiv",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+local insert, remove = table.insert, table.remove
+
+local context = context
+local interfaces = interfaces
+
+local sections = structures.sections
+local implement = interfaces.implement
+
+local v_default = interfaces.variables.default
+
+sections.levels = sections.levels or { }
+
+local level = 0
+local levels = sections.levels
+local categories = { }
+
+local f_two_colon = string.formatters["%s:%s"]
+
+storage.register("structures/sections/levels", levels, "structures.sections.levels")
+
+local function definesectionlevels(category,list)
+ levels[category] = utilities.parsers.settings_to_array(list)
+end
+
+local function startsectionlevel(category)
+ category = category ~= "" and category or v_default
+ level = level + 1
+ local lc = levels[category]
+ if not lc or level > #lc then
+ context.nostarthead { f_two_colon(category,level) }
+ else
+ context.dostarthead { lc[level] }
+ end
+ insert(categories,category)
+end
+
+local function stopsectionlevel()
+ local category = remove(categories)
+ if category then
+ local lc = levels[category]
+ if not lc or level > #lc then
+ context.nostophead { f_two_colon(category,level) }
+ else
+ context.dostophead { lc[level] }
+ end
+ level = level - 1
+ else
+ -- error
+ end
+end
+
+implement {
+ name = "definesectionlevels",
+ actions = definesectionlevels,
+ arguments = { "string", "string" }
+}
+
+implement {
+ name = "startsectionlevel",
+ actions = startsectionlevel,
+ arguments = "string"
+}
+
+implement {
+ name = "stopsectionlevel",
+ actions = stopsectionlevel,
+}