diff options
author | Philipp Gesang <pgesang@ix.urz.uni-heidelberg.de> | 2010-09-17 14:25:52 +0200 |
---|---|---|
committer | Philipp Gesang <pgesang@ix.urz.uni-heidelberg.de> | 2010-09-17 14:25:52 +0200 |
commit | 3320a5822121e59f07e0f5363edf22fe0c76f67c (patch) | |
tree | 355d4c1e9d26ef40d2a535d006182831cd5c05ad | |
parent | e9a66b9dc2fba26ba6b8feec152511512e6870a6 (diff) | |
download | context-rst-3320a5822121e59f07e0f5363edf22fe0c76f67c.tar.gz |
literal blocks now align precisely
-rw-r--r-- | rst_context.lua | 34 | ||||
-rw-r--r-- | rst_parser.lua | 23 |
2 files changed, 29 insertions, 28 deletions
diff --git a/rst_context.lua b/rst_context.lua index 15655a8..19a5167 100644 --- a/rst_context.lua +++ b/rst_context.lua @@ -57,30 +57,29 @@ function rst_context.footnote_reference (label) local tf = state.footnotes if label:match("^%d+$") then -- all digits local c = tonumber(label) - print("creating footnote nr " .. c) + --print("creating footnote nr " .. c) return [[\\footnote{\\getbuffer[__footnote_number_]].. c .."]}" elseif label == "#" then --autonumber local rc = rst_context.current_footnote_number rc = rc + 1 - --rst_context.current_footnote_number = rst_context.current_footnote_number + 1 - print("creating footnote nr " .. rc) + --print("creating footnote nr " .. rc) rst_context.current_footnote_number = rc return [[\\footnote{\\getbuffer[__footnote_number_]].. rc .."]}" elseif label:match("^#.+$") then local thelabel = label:match("^#(.+)$") - print("creating labeled footnote " .. thelabel) + --print("creating labeled footnote " .. thelabel) return [[\\footnote{\\getbuffer[__footnote_label_]].. thelabel .."]}" elseif label == "*" then local rc = rst_context.current_symbolnote_number rc = rc + 1 - print("creating symbolnote nr " .. rc) + --print("creating symbolnote nr " .. rc) rst_context.current_symbolnote_number = rc return [[\\symbolnote{\\getbuffer[__footnote_symbol_]].. rc .."]}" else -- “citation reference” for now treating them like footnotes local rc = rst_context.current_footnote_number rc = rc + 1 --rst_context.current_footnote_number = rst_context.current_footnote_number + 1 - print("creating footnote nr " .. rc) + --print("creating footnote nr " .. rc) rst_context.current_footnote_number = rc return [[\\footnote{\\getbuffer[__footnote_number_]].. rc .."]}" --return [[\\cite{]] .. label .. "}" @@ -126,7 +125,6 @@ end function rst_context.interpreted_text (...) local tab = { ... } - --print (tab, #tab, tab[1], tab[2], tab[3]) local role, str role = tab[1]:match("^:(.*):$") or tab[3]:match("^:(.*):$") str = tab[2] @@ -135,8 +133,6 @@ function rst_context.interpreted_text (...) role = "emphasis" end - --print(role, str) - return rst_context[role](str) end @@ -167,7 +163,6 @@ local removewhitespace = Cs((nowhitespace^1 + Cs(whitespace / ""))^0) function rst_context.target (tab) rst_context.addsetups("references") - --print("GOT ONE!") --local tab = { ... } local refs = rst_context.collected_references local target = tab[#tab] -- Ct + C could be clearer but who cares @@ -185,7 +180,6 @@ function rst_context.target (tab) --if removewhitespace:match(target) == "" then if target == "" then -- links here for _, id in next, tab do - print(id) insert = insert .. "\n\\reference[__target_" .. id .. "]{}" end else @@ -474,9 +468,7 @@ function rst_context.paragraph (data) if not data then return "" elseif type(data) == "table" then - print(data,#data,data[1]) str = #data > 1 and helpers.string.wrapat(inline_parser:match(table.concat(data, " ")), 65) or data[1] - print(str) else str = data end @@ -653,7 +645,6 @@ function rst_context.deflist (list) \\startRSTdefinitionlist ]] for nd, item in ipairs(list) do - print(#item) local term = item[1] local nc = 2 local tmp = [[ @@ -719,12 +710,10 @@ function rst_context.field (tab) end function rst_context.line_comment (str) - print(">>"..str.."<<") return "% " .. str end function rst_context.block_comment (str) - print(">>"..str.."<<") return string.format([[ \iffalse @@ -758,13 +747,20 @@ function rst_context.option_item (tab) end function rst_context.test(str) - print("This:>>"..str.."<<") return ":" end function rst_context.literal_block (str, included) local indent = P" "^1 - local stripme = indent:match(str) or 0 + --local stripme = indent:match(str) or 0 + local stripme = #str + for line in str:gmatch("[^\n]+") do + -- setting to the lowest indend of all lines + local idt = indent:match(line) + if line and idt then + stripme = idt < stripme and idt or stripme + end + end local strip = P{ [1] = "strip", @@ -1052,7 +1048,6 @@ end function rst_context.substitution_definition (subtext, directive, data) data = table.concat(data, "\n") - print(subtext,directive,data) local rs = rst_context.substitutions rs[subtext] = { directive = directive, data = data } return "" @@ -1101,7 +1096,6 @@ function optional_setups.references () local refs = rst_context.collected_references local function resolve_indirect (r) if r and r:match(".*_$") then -- pointing elsewhere - --print(">>"..r.."<<",">>"..r:match("^`?([^`]*)`?_$").."<<", refs[r:match("^`?([^`]*)`?_$")]) return resolve_indirect (refs[r:match("^`?([^`]*)`?_$")]) or "need another run!" -- TODO multiple runs && data collection end return r diff --git a/rst_parser.lua b/rst_parser.lua index 26636a1..01cd42d 100644 --- a/rst_parser.lua +++ b/rst_parser.lua @@ -331,7 +331,6 @@ local parser = P{ while n < #tcb.slices do local from = tcb.slices[n] .stop local to = tcb.slices[n+1].start - --print(n, from, to, content) local between = spaces_only:match(content, from) if not between then -- Cell spanning more than one row. -- pass @@ -590,10 +589,10 @@ local parser = P{ literal_block = V"literal_block_marker" * Cs(V"literal_block_lines" * (V"blank_line"^1 * V"literal_block_lines")^0) - * V"blank_line"^0 + * V"end_block" / rst.literal_block, - literal_block_marker = V"double_colon" * V"eol" * V"blank_line", + literal_block_marker = V"double_colon" * V"whitespace"^0 * V"eol" * V"blank_line", literal_block_lines = V"unquoted_literal_block_lines" + V"quoted_literal_block_lines", @@ -608,12 +607,17 @@ local parser = P{ literal_block_first = Cmt(V"space"^1, function (s, i, indent) warn("lbk-f", #indent, "", "", i) - if not indent or + if not indent or indent == "" then return false end - state.currentindent = indent - return true + if state.currentindent and #state.currentindent < #indent then + state.currentindent = state.currentindent .. " " + return true + else + state.currentindent = " " + return true + end end) * V"rest_of_line" * V"eol", @@ -957,14 +961,17 @@ local parser = P{ section_before = C(Cmt(V"section_adorn", function(s,i, adorn) state.previousadorn = adorn warn ("sec-f", state.valid_adornment:match(adorn), adorn:sub(1,2) .. "...", "", i) - return state.valid_adornment:match(adorn) + if state.valid_adornment:match(adorn) then + return true + end + return false end)) * V"whitespace"^0 * V"eol" * V"whitespace"^0 , - section_text = C((1 - V"space" - V"eol")^1) * V"eol", + section_text = C((1 - V"space" - V"eol") * (1 - V"eol")^1) * V"eol", section_after = C(Cmt(V"section_adorn", function(s,i, adorn) local tests = false |