diff options
author | Philipp Gesang <pgesang@ix.urz.uni-heidelberg.de> | 2010-09-17 17:11:35 +0200 |
---|---|---|
committer | Philipp Gesang <pgesang@ix.urz.uni-heidelberg.de> | 2010-09-17 17:11:35 +0200 |
commit | a47844a42cfabc9eb893eef80dd375d75bdd436f (patch) | |
tree | f7bb03c87630b33e3a6c9c363535852f175e256f /rst_helpers.lua | |
parent | 3320a5822121e59f07e0f5363edf22fe0c76f67c (diff) | |
download | context-rst-a47844a42cfabc9eb893eef80dd375d75bdd436f.tar.gz |
revised bullet list enumeration, accepting irregular numbering.
Diffstat (limited to 'rst_helpers.lua')
-rw-r--r-- | rst_helpers.lua | 69 |
1 files changed, 61 insertions, 8 deletions
diff --git a/rst_helpers.lua b/rst_helpers.lua index 0f6e10c..b8902ca 100644 --- a/rst_helpers.lua +++ b/rst_helpers.lua @@ -354,11 +354,9 @@ function helpers.table.simple(raw) --ignore = false } cell.content = string.strip(row:sub(start, stop)) - print(">>".. row:sub(start, stop) .."<<", ">>"..cell.content.."<<") if check_span then local start_at, stop_at for colnr, slice in ipairs(bounds.slices) do - print(start, slice.start, stop, slice.stop) if slice.start == start then start_at = colnr end @@ -373,7 +371,6 @@ function helpers.table.simple(raw) end end cell.span.x = 1 + stop_at - start_at - print(start_at, stop_at, cell.span.x) end newrow[nc] = cell end @@ -412,8 +409,8 @@ do local c = {} c.roman = S"ivxlcdm"^1 c.Roman = S"IVXLCDM"^1 - c.alpha = R"az" - P"i" - c.Alpha = R"AZ" - P"I" + c.alpha = R"az" - P"i" - P"v" - P"x" - P"l" + c.Alpha = R"AZ" - P"I" - P"V" - P"X" - P"L" c.digit = R"09"^1 c.auto = P"#" @@ -422,7 +419,6 @@ do local itemstripper = stripme^0 * C(dontstrip^1) * stripme^0 local con = function (str) - --print("This is it: >"..str.."<") str = itemstripper:match(str) for conv, pat in next, c do if pat:match(str) then @@ -498,7 +494,6 @@ do return false end - local trc = state.roman_cache n_str = trc[str] or nil n_old = trc[old] or nil @@ -510,11 +505,69 @@ do n_old = roman_to_arab(old:lower()) trc[old] = n_old end - --print(n_str, n_old, n_str == n_old + 1 ) return n_str == n_old + 1 end end helpers.list.successor = suc + + local greater = function (str, old) + str, old = itemstripper:match(str), itemstripper:match(old) + local n_str, n_old = tonumber(str), tonumber(old) + if n_str and n_old then -- arabic numeral + return n_str > n_old + end + + local con_str, con_old = con(str), con(old) + if con_str == "alpha" or + con_str == "Alpha" then + return str:byte() > old:byte() + else + if not (str:lower() == str or + str:upper() == str) then -- uneven cased --> fail + return false + end + + + local trc = state.roman_cache + n_str = trc[str] or nil + n_old = trc[old] or nil + if not n_str then + n_str = roman_to_arab(str:lower()) + trc[str] = n_str + end + if not n_old then + n_old = roman_to_arab(old:lower()) + trc[old] = n_old + end + return n_str > n_old + end + end + helpers.list.greater = greater + + local gd = function(str) + str = itemstripper:match(str) + local value + local con_str = con(str) + if con_str == "alpha" or + con_str == "Alpha" then + return str:byte() + else + if not (str:lower() == str or + str:upper() == str) then + return false + end + + local trc = state.roman_cache + n_str = trc[str] or nil + if not n_str then + n_str = roman_to_arab(str:lower()) + trc[str] = n_str + end + return n_str + end + end + + helpers.list.get_decimal = gd end helpers.string = {} |