From eba2c4f2e152ffcf75a571ece2b08915e073db89 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Fri, 17 Sep 2010 12:34:16 +0200 Subject: hacked comments into enumerations. hope that does not break anything. --- rst_context.lua | 25 +++++++++++++++++++++---- rst_parser.lua | 19 ++++++++++--------- 2 files changed, 31 insertions(+), 13 deletions(-) diff --git a/rst_context.lua b/rst_context.lua index 71e9e09..80bbd3b 100644 --- a/rst_context.lua +++ b/rst_context.lua @@ -568,7 +568,7 @@ local enumeration_types = { ["‣"] = "*", ["⁃"] = "*", - ["#"] = "1", -- numbered lists and conversion + ["#"] = "n", -- numbered lists and conversion ["A"] = "A", ["a"] = "a", ["I"] = "R", @@ -580,7 +580,9 @@ local enumeration_types = { local stripme = S"()." local dontstrip = 1 - stripme local itemstripper = stripme^0 * C(dontstrip^1) * stripme^0 + local function parse_itemstring(str) + local offset = nil local setup = ",fit][itemalign=flushright," -- string.match is slightly faster than string.find if str:match("^%(") then @@ -590,16 +592,23 @@ local function parse_itemstring(str) setup = setup .. [[right=)]] end if str:match("%.$") then - setup = setup .. [[stopper=.]] + setup = setup .. [[stopper={.\\space}]] end setup = setup str = itemstripper:match(str) - return {setup = setup, str=str} + str = enumeration_types[str] or str + if str:match("^%d") then + offset = tonumber(str:match("^%d+")) - 1 + str = "n" + end + return {setup = setup, str = str, offset = offset} end function rst_context.startitemize(str) local setup = "" + local result = "" + local offset str = string.strip(str) local listtype = enumeration_types[str] or parse_itemstring(str) @@ -607,12 +616,20 @@ function rst_context.startitemize(str) if type(listtype) == "table" then --print(type(listtype), listtype[2]) setup = listtype.setup + offset = listtype.offset listtype = listtype.str end - return [[ + result = [[ \\startitemize[]] .. listtype .. setup .. [[] ]] + if offset then + result = result .. [[ + +\\setnumber[itemgroup:itemize]{]] .. offset .. [[} +]] + end + return result end function rst_context.stopitemize(str) diff --git a/rst_parser.lua b/rst_parser.lua index b17e2fd..dec4b6b 100644 --- a/rst_parser.lua +++ b/rst_parser.lua @@ -130,10 +130,10 @@ local parser = P{ + Cs(V"line_block") / rst.escape + Cs(V"table_block") / rst.escape + V"transition" --/ rst.escape + + V"comment_block" + Cs(V"section") / rst.escape + V"literal_block" + Cs(V"block_quote") / rst.escape - + V"comment_block" + Cs(V"paragraph") / rst.escape , @@ -802,10 +802,8 @@ local parser = P{ -- the next rule handles enumerations as well bullet_list = V"bullet_init" - --* (V"bullet_list" - --+ V"bullet_continue")^0 - --* (V"bullet_continue" + V"bullet_list")^0 - * (V"blank_line"^-1 * (V"bullet_list" + V"bullet_continue"))^0 + --* ((V"blank_line" - V"end_block")^-1 * (V"bullet_list" + V"bullet_continue"))^0 + * (V"blank_line"^-1 * (V"bullet_list" + V"bullet_continue" + V"comment"))^0 * V"bullet_stop" * Cmt(Cc(nil), function (s, i) local t = state @@ -817,7 +815,7 @@ local parser = P{ end), --bullet_stop = V"blank_line" * Cs(Cc("")) / rst.stopitemize, - bullet_stop = V"end_block" * Cs(Cc("")) / rst.stopitemize, + bullet_stop = V"end_block" / rst.stopitemize, bullet_init = V"bullet_first" * V"bullet_itemrest", @@ -897,7 +895,8 @@ local parser = P{ bullet_rest = Cs((1 - V"eol")^1 * V"eol"), -- rest of one line - bullet_next = V"space"^1, + bullet_next = V"space"^1 + , bullet_match = #Cmt(V"bullet_next", function (s, i, this) local t = state @@ -906,7 +905,8 @@ local parser = P{ string.len(this) == utf.len(t.bullets[t.depth]), utf.len(t.bullets[t.depth]), string.len(this) ) return string.len(this) == utf.len(t.bullets[t.depth]) - end), + end) + , bullet_expr = V"bullet_char" + (P"(" * V"number_char" * P")") @@ -920,7 +920,8 @@ local parser = P{ + P"#" + V"digit"^1 + R"AZ" - + R"az", + + R"az" + , -------------------------------------------------------------------------------- -- Transitions -- cgit v1.2.3