From 008c8958d3f19acaac24ce995ce22bb7d9636b58 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Sun, 2 Mar 2014 17:04:05 +0100 Subject: simplify itemization level stack handling --- src/rst_context.lua | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/rst_context.lua b/src/rst_context.lua index db05537..699064e 100644 --- a/src/rst_context.lua +++ b/src/rst_context.lua @@ -819,10 +819,8 @@ end local item_stack = { } -local current_itemdepth = 0 function rst_context.stopitemize(str) - item_stack[current_itemdepth] = nil - current_itemdepth = current_itemdepth - 1 + item_stack[#item_stack] = nil return str .. [[ \\stopitemize ]] @@ -836,18 +834,18 @@ function rst_context.bullet_item (tab) local itemtype = tab[1] local result = startstr or "" if startstr then - current_itemdepth = current_itemdepth + 1 - item_stack[current_itemdepth] = itemtype - elseif item_stack[current_itemdepth] then - if helpers.list.successor(itemtype, item_stack[current_itemdepth]) then + item_stack[#item_stack + 1] = itemtype + elseif next (item_stack) then + local current_item = item_stack [#item_stack] + if helpers.list.successor(itemtype, current_item) then -- just leave it alone - elseif helpers.list.greater(itemtype, item_stack[current_itemdepth]) then + elseif helpers.list.greater(itemtype, current_item) then local itemnum = tonumber(stringstrip(itemtype)) or helpers.list.get_decimal(itemtype) result = result .. stringformat([[ \\setnumber[itemgroup:itemize]{%s} ]], itemnum) end - item_stack[current_itemdepth] = itemtype + item_stack[#item_stack] = itemtype end return result .. [[ -- cgit v1.2.3