summaryrefslogtreecommitdiff
path: root/rst_context.lua
diff options
context:
space:
mode:
authorPhilipp Gesang <pgesang@ix.urz.uni-heidelberg.de>2010-09-03 04:25:36 +0200
committerPhilipp Gesang <pgesang@ix.urz.uni-heidelberg.de>2010-09-03 04:25:36 +0200
commita5bbf034b6264780bd5144c48fdd9be61ec9030a (patch)
tree86af6eca63beb856bee86b95c43d7e29fc911a66 /rst_context.lua
parente2208e66effcc50e5cd63d0debfc65560d9003af (diff)
downloadcontext-rst-a5bbf034b6264780bd5144c48fdd9be61ec9030a.tar.gz
enumerations (most types, incl. conversions)
Diffstat (limited to 'rst_context.lua')
-rw-r--r--rst_context.lua72
1 files changed, 68 insertions, 4 deletions
diff --git a/rst_context.lua b/rst_context.lua
index 8b4c8d6..8131505 100644
--- a/rst_context.lua
+++ b/rst_context.lua
@@ -195,12 +195,76 @@ function rst_context.transition (str)
return "\n\\hrule\n"
end
-function rst_context.bullet_list (str)
- return [[
+function rst_context.bullet_marker(str)
+ return "marker"
+end
+
+do
+ local space = lpeg.S(" \t\v\n")
+ local nospace = 1 - space
+ local stripper = space^0 * lpeg.C((space^0 * nospace^1)^0)
+ function string.strip(str)
+ return match(stripper,str) or ""
+ end
+end
+
+local enumeration_types = {
+ ["*"] = "*", -- unordered bulleted
+ ["+"] = "*",
+ ["-"] = "*",
+ ["•"] = "*",
+ ["‣"] = "*",
+ ["⁃"] = "*",
+
+ ["#"] = "1", -- numbered lists and conversion
+ ["A"] = "A",
+ ["a"] = "a",
+ ["I"] = "R",
+ ["i"] = "r",
+}
+
+-- \setupitemize[left=(, right=), margin=4em, stopper=]
+
+local stripme = S"()."
+local dontstrip = 1 - stripme
+local itemstripper = stripme^0 * C(dontstrip) * stripme^0
+local function parse_itemstring(str)
+ local setup = [[\setupitemize[]]
+ -- string.match is slightly faster than string.find
+ if str:match("^%(") then
+ setup = setup .. [[left=(,]]
+ end
+ if str:match("%)$") then
+ setup = setup .. [[right=)]]
+ end
+ if str:match("%.$") then
+ setup = setup .. [[stopper=.]]
+ end
+ setup = setup .. "]\n"
+
+ str = itemstripper:match(str)
+ return {setup = setup, str=str}
+end
-\\startitemize
-]] .. str .. [[
+function rst_context.startitemize(str)
+ local setup = ""
+ str = string.strip(str)
+
+ local listtype = enumeration_types[str] or parse_itemstring(str)
+
+ if type(listtype) == "table" then
+ print(type(listtype), listtype[2])
+ setup = listtype.setup
+ listtype = listtype.str
+ end
+
+ return setup .. [[
+\\startitemize[]] .. listtype .. [[]
+]]
+end
+function rst_context.stopitemize(str)
+ return str .. [[
\\stopitemize
]]
end