From 6fca7b9582ac97d772152ad0bef822d37605b616 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Tue, 21 Sep 2010 22:05:49 +0200 Subject: error printing for formatter. whitespace issues. --- rst_context.lua | 36 +++++++++++++++++++----------------- rst_helpers.lua | 7 +++++-- 2 files changed, 24 insertions(+), 19 deletions(-) diff --git a/rst_context.lua b/rst_context.lua index 12c6817..e5737e0 100644 --- a/rst_context.lua +++ b/rst_context.lua @@ -39,8 +39,13 @@ do end end -local rst_context = {} +local err = function(str) + if str then + io.write("\n*[rstctx] Error: " .. str .. "\n\n") + end +end +local rst_context = {} rst_context.collected_references = {} rst_context.collected_adornments = {} @@ -118,7 +123,6 @@ function rst_context.strong_emphasis (str) end function rst_context.literal (str) - print(str) str = str:gsub([[\]], [[\\]]) -- evade escaping of backslashes return [[\\type{]] .. str .. [[}]] --return [[\\starttyping ]] .. str .. [[\\stoptyping]] @@ -470,14 +474,8 @@ function rst_context.paragraph (data) local str if not data then return "" - --elseif type(data) == "table" then - --str = #data > 1 and helpers.string.wrapat(inline_parser:match(table.concat(data, " ")), 65) or data[1] elseif type(data) == "table" then - str = table.concat(data, " ") - str = inline_parser:match(str) - str = helpers.string.wrapat(str) - print(str) - --str = #data > 1 and helpers.string.wrapat(inline_parser:match(table.concat(data, " ")), 65) or data[1] + str = #data > 1 and helpers.string.wrapat(inline_parser:match(table.concat(data, " ")), 65) or data[1] else str = data end @@ -1169,9 +1167,9 @@ function optional_setups.references () % #1 target name, #2 link text \def\RSTchoosegoto#1#2{% - \rawdoifinsetelse{#1}{\RSTexternalreferences} - {\from[#1]} - {\goto{#2}[#1]} + \rawdoifinsetelse{#1}{\RSTexternalreferences}% + {\from[#1]}% + {\goto{#2}[#1]}% } ]] @@ -1277,12 +1275,12 @@ rst_context.directives.image = function(name, data) \def\RSTsubstitution%s{%% \placefigure[here]{%s}{\externalfigure[%s]%s} } -]], name, properties.caption, name, properties.setup) +]], name, inline_parser:match(properties.caption), name, properties.setup) else -- image won't be referenced but used instantly img = img .. string.format([[ \placefigure[here]{%s}{\externalfigure[%s]%s} -]], properties.caption, data, properties.setup) +]], inline_parser:match(properties.caption), data, properties.setup) end return img end @@ -1375,7 +1373,7 @@ rst_context.directives.ctx = function(name, data) \startbuffer[%s] %s \stopbuffer -\def\RSTsubstitution%s{ +\def\RSTsubstitution%s{%% \getbuffer[%s] } ]], name, data, name, name) @@ -1416,7 +1414,11 @@ function optional_setups.substitutions () for name, content in next, rs do local directive, data = content.directive, content.data name, data = name:gsub("%s", ""), string.strip(data) - substitutions = substitutions .. directives[directive](name, data) + if directives[directive] then + substitutions = substitutions .. directives[directive](name, data) + else + err(directive .. " does not exist.") + end end return substitutions end @@ -1573,7 +1575,7 @@ function optional_setups.caution () \def\startRSTcaution{% \startparagraph -\lettrine[Lines=2,Raise=.5,Findent=\RSTbendskip,Nindent=0pt]{\symbol[dbend]}{}% +\dontleavehmode\lettrine[Lines=2,Raise=.5,Findent=\RSTbendskip,Nindent=0pt]{\symbol[dbend]}{}% } \let\stopRSTcaution\stopparagraph diff --git a/rst_helpers.lua b/rst_helpers.lua index 92f41a2..d70e247 100644 --- a/rst_helpers.lua +++ b/rst_helpers.lua @@ -594,19 +594,22 @@ do whitespace = S" \t\v" + P"\n" / function() linelength = 0 end, nowhitespace = 1 - V"whitespace", ignore = P[[\\type{]] * (1 - P"}")^0 * P"}", + -- the initial whitespace of the “other” pattern must not be + -- enforced (“^1”) as it will break the exceptions (“ignore” + -- pattern)! In general it is better to have the wrapper ignore some + -- valid breaks than to not have it matching some valid strings at + -- all. other = Cmt(V"whitespace"^0 * (V"ignore" + (1 - V"whitespace")^1), function(s,i,w) linelength = linelength + ulen(w) return true end), wrapme = Cmt(V"whitespace"^1 * (1 - V"whitespace" - V"ignore")^1, function(s,i,w) local lw = ulen(w) - print(w) if linelength + lw > width then linelength = lw return true end return false - --end) / function (word) return "\n" .. match(V"whitespace"^1 * C((1 - V"whitespace")^1), word) end, end) / function (word) return "\n" .. word:match("[^%s]+") end, } -- cgit v1.2.3