From 65bee7f493520e0dc75084f2dc68c52e6a5521d1 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Thu, 16 Sep 2010 15:33:22 +0200 Subject: fixed literal blocks inside paragraphs --- rst_context.lua | 17 +++++++++++++---- rst_parser.lua | 53 ++++++++++++++++++++++++++++++++++++++++------------- 2 files changed, 53 insertions(+), 17 deletions(-) diff --git a/rst_context.lua b/rst_context.lua index 0abcdc6..a46e0a2 100644 --- a/rst_context.lua +++ b/rst_context.lua @@ -740,7 +740,7 @@ function rst_context.option_item (tab) ]], tab[1], tab[2]) end -function rst_context.literal_block (str) +function rst_context.literal_block (str, included) local indent = P" "^1 local stripme = indent:match(str) or 0 @@ -758,13 +758,22 @@ function rst_context.literal_block (str) str = strip:match(str) --strip:print() -- grammar consists of 45 rules only; wheras a plain -- pattern has 60+ - return [[ + str = [[ -\\starttyping[lines=hyphenated] +\starttyping[lines=hyphenated] ]] .. str .. [[ -\\stoptyping +\stoptyping ]] + if included then -- escaping can ruin your day + return str:gsub("\\", "\\\\") + else + return str + end +end + +function rst_context.included_literal_block (str) + return rst_context.literal_block(str, true) end function rst_context.line_block (str) diff --git a/rst_parser.lua b/rst_parser.lua index 432f11a..46142ba 100644 --- a/rst_parser.lua +++ b/rst_parser.lua @@ -55,9 +55,10 @@ state.bullets.max = 0 state.lastbullet = "" state.lastbullets = {} state.roman_cache = {} -- storing roman numerals that were already converted -state.currentindent = "" -- used in definition lists and elsewhere -state.currentwidth = 0 -- table layout -state.currentlayout = {} -- table layout +state.currentindent = "" -- used in definition lists and elsewhere +state.previousindent = "" -- for literal blocks included in paragraphs to restore the paragraph indent +state.currentwidth = 0 -- table layout +state.currentlayout = {} -- table layout state.footnotes = {} state.footnotes.autonumber = 0 @@ -987,14 +988,26 @@ local parser = P{ -- Paragraphs * Inline Markup -------------------------------------------------------------------------------- - paragraph = V"par_setindent" - * Ct(C((1 - V"eol")^1) * V"eol" - * (V"par_matchindent" * C((1 - V"eol")^1) * V"eol")^0) + --paragraph = V"par_setindent" + --* Ct(C((1 - V"eol")^1) * V"eol" + --* (V"par_matchindent" * C((1 - V"eol")^1) * V"eol")^0) + --* V"end_block" + --/ rst.paragraph, + + paragraph = Ct(V"par_first" + * V"par_other"^0) * V"end_block" / rst.paragraph, + par_first = V"par_setindent" * C((1 - V"eol")^1) * V"eol", + + par_other = V"par_matchindent" + * C((1 - V"literal_block_shorthand" - V"eol")^1) + * (V"included_literal_block" + V"eol"), + par_setindent = Cmt(V"space"^0, function (s, i, indent) warn("par-i", #indent, "", "", i) + state.previousindent = state.currentindent state.currentindent = indent return true end), @@ -1013,17 +1026,31 @@ local parser = P{ _reference = (1 - V"underscore" - V"spacing" - V"eol" - V"punctuation" - V"groupchars")^1 * V"underscore", included_literal_block = V"literal_block_shorthand" - * V"literal_block_markerless", - - literal_block_shorthand = ((V"colon" * V"space"^1)^-1 - * V"double_colon") / ":" - * (V"eol" * V"blank_line" / "") + * V"literal_block_markerless" + * Cmt(Cp(), function (s, i, _) + warn("par-s", "", #state.previousindent, #state.currentindent, i) + state.currentindent = state.previousindent + return true + end) + , + + --literal_block_shorthand = ((V"colon" * V"space"^1)^-1 + --* V"double_colon") / ":" + --* (V"eol" * V"blank_line" / "") + --, + + literal_block_shorthand = (((V"double_colon" * V"space"^0) + + (V"colon" * V"space"^1 * V"double_colon")) + * V"eol" + * V"blank_line" / ":") , literal_block_markerless = Cs(V"literal_block_lines" * (V"blank_line"^1 * V"literal_block_lines")^0) - * V"blank_line"^0 - / rst.literal_block, + --* V"end_block" + * V"blank_line" + / rst.included_literal_block + , -------------------------------------------------------------------------------- -- Comments -- cgit v1.2.3