From a5bbf034b6264780bd5144c48fdd9be61ec9030a Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Fri, 3 Sep 2010 04:25:36 +0200 Subject: enumerations (most types, incl. conversions) --- rst_context.lua | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 68 insertions(+), 4 deletions(-) (limited to 'rst_context.lua') 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 -- cgit v1.2.3