summaryrefslogtreecommitdiff
path: root/rst_context.lua
diff options
context:
space:
mode:
Diffstat (limited to 'rst_context.lua')
-rw-r--r--rst_context.lua39
1 files changed, 33 insertions, 6 deletions
diff --git a/rst_context.lua b/rst_context.lua
index 19a5167..39d375b 100644
--- a/rst_context.lua
+++ b/rst_context.lua
@@ -49,6 +49,7 @@ rst_context.anonymous_targets = 0
rst_context.anonymous_links = 0
rst_context.context_references = {}
rst_context.substitutions = {}
+rst_context.lastitemnumber = 0 -- enumerations in RST allow arbitrary skips
rst_context.current_footnote_number = 0
rst_context.current_symbolnote_number = 0
@@ -589,12 +590,12 @@ local function parse_itemstring(str)
if str:match("%.$") then
setup = setup .. [[stopper={.\\space}]]
end
- if str:match("^%d") then
+ local num = str:match("^%d")
+ if num then
-- http://thread.gmane.org/gmane.comp.tex.context/61728/focus=61729
- setup = setup .. ",start=" .. tonumber(str:match("^%d+")) - 1
+ setup = setup .. ",start=" .. num
str = "n"
end
- setup = setup
str = itemstripper:match(str)
str = enumeration_types[str] or str
@@ -619,16 +620,42 @@ function rst_context.startitemize(str)
return result
end
+local last_item = {} -- stack
+local current_itemdepth = 0
function rst_context.stopitemize(str)
+ last_item[current_itemdepth] = nil
+ current_itemdepth = current_itemdepth - 1
return str .. [[
\\stopitemize
]]
end
-function rst_context.bullet_item (str)
- return [[
+function rst_context.bullet_item (tab)
+ local li = last_item
+ -- The capture of the first item has the \startitemize as
+ -- *second* element in the array.
+ local content = #tab == 2 and tab[2] or tab[3]
+ local startstr = #tab == 3 and tab[2] or nil
+ local itemtype = tab[1]
+ local result = startstr or ""
+ if startstr then
+ current_itemdepth = current_itemdepth + 1
+ li[current_itemdepth] = itemtype
+ elseif li[current_itemdepth] then
+ if helpers.list.successor(itemtype, li[current_itemdepth]) then
+ -- just leave it alone
+ elseif helpers.list.greater(itemtype, li[current_itemdepth]) then
+ local itemnum = tonumber(string.strip(itemtype)) or helpers.list.get_decimal(itemtype)
+ result = result .. string.format([[
+\\setnumber[itemgroup:itemize]{%s}
+]], itemnum)
+ end
+ li[current_itemdepth] = itemtype
+ end
+
+ return result .. [[
-\\item ]] .. inline_parser:match(str) .. [[
+\\item ]] .. inline_parser:match(content) .. [[
]]
end