diff options
-rw-r--r-- | rst_context.lua | 23 | ||||
-rw-r--r-- | rst_parser.lua | 83 |
2 files changed, 96 insertions, 10 deletions
diff --git a/rst_context.lua b/rst_context.lua index 8913fb9..6a0d2f3 100644 --- a/rst_context.lua +++ b/rst_context.lua @@ -435,4 +435,27 @@ function rst_context.line_block_empty() return "\n" end +function rst_context.block_quote (tab) + local str = [[ +\\setupdelimitedtext [blockquote][style={\\setupbodyfont[11pt]}] % awful placeholder +\\definedelimitedtext[attribution][blockquote] +\\setupdelimitedtext [attribution][style={\\setupbodyfont[11pt]\\it}] + +\\startlinecorrection +\\startblockquote +]] .. tab[1] .. [[ + +\\stopblockquote +]] + + return tab[2] and str .. [[ +\\startattribution +]] .. tab[2] .. [[ +\\stopattribution +\\stoplinecorrection +]] or str .. [[ +\\stoplinecorrection +]] +end + return rst_context diff --git a/rst_parser.lua b/rst_parser.lua index 075ff29..4e767b5 100644 --- a/rst_parser.lua +++ b/rst_parser.lua @@ -37,7 +37,11 @@ end local debugme = function(x) print ("HERE >"..x.."<") return x end -local C, Cb, Cc, Cg, Cmt, Cp, Cs, Ct, P, R, S, V, match = lpeg.C, lpeg.Cb, lpeg.Cc, lpeg.Cg, lpeg.Cmt, lpeg.Cp, lpeg.Cs, lpeg.Ct, lpeg.P, lpeg.R, lpeg.S, lpeg.V, lpeg.match +local C, Cb, Cc, Cg, Cmt, Cp, Cs, Ct + = lpeg.C, lpeg.Cb, lpeg.Cc, lpeg.Cg, lpeg.Cmt, lpeg.Cp, lpeg.Cs, lpeg.Ct + +local P, R, S, V, match + = lpeg.P, lpeg.R, lpeg.S, lpeg.V, lpeg.match local utf = unicode.utf8 @@ -51,8 +55,6 @@ tracklists.lastbullet = "" tracklists.roman_cache = {} -- storing roman numerals that were already converted tracklists.currentindent = "" -- used in definition lists and elsewhere ---n = 0 - local enclosed_mapping = { ["'"] = "'", ['"'] = '"', @@ -195,14 +197,72 @@ local parser = P{ block = V"target_block" + V"comment" + V"line_block" - + Cs(V"section") / rst.escape - + Cs(V"transition") --/ rst.escape + + Cs(V"section") / rst.escape + + Cs(V"transition") --/ rst.escape + V"literal_block" - + Cs(V"list") / rst.escape - + Cs(V"paragraph") / rst.escape + + Cs(V"list") / rst.escape + + Cs(V"block_quote") / rst.escape + + Cs(V"paragraph") / rst.escape , -------------------------------------------------------------------------------- +-- Block quotes +-------------------------------------------------------------------------------- + + block_quote = Ct(Cs(V"block_quote_first" + * V"block_quote_other"^0 + * (V"blank_line" * V"block_quote_other"^1)^0) + * (V"blank_line" + * Cs(V"block_quote_attri"))^-1) + * V"blank_line" + / rst.block_quote + , + + block_quote_first = Cmt(V"space"^1, function (s, i, indent) + warn("bkq-i", #indent, "", indent, "", i) + tracklists.currentindent = indent + return true + end) / "" + * -V"attrib_dash" + * V"text_elements"^1 + * V"eol" + , + + block_quote_other = Cmt(V"space"^1, function (s, i, indent) + warn("bkq-m", #indent, #tracklists.currentindent, + indent, tracklists.currentindent, i) + return tracklists.currentindent == indent + end) / "" + * -V"attrib_dash" + * V"text_elements"^1 + * V"eol" + , + + block_quote_attri = V"block_quote_attri_first" + * V"block_quote_attri_other"^0, + + block_quote_attri_first = Cmt(V"space"^1 * V"attrib_dash" * V"space", function (s, i, indent) + local t = tracklists + warn("bqa-i", utf.len(indent), #t.currentindent, + indent, t.currentindent, i) + local ret = indent:match(" *") == t.currentindent + t.currentindent = ret and indent or t.currentindent + return ret + end) / "" + * V"text_elements"^1 + * V"eol" + , + + block_quote_attri_other = Cmt(V"space"^1, function (s, i, indent) + warn("bqa-m", #indent, utf.len(tracklists.currentindent), + indent, tracklists.currentindent, i) + return utf.len(tracklists.currentindent) == #indent + end) / "" + * V"text_elements"^1 + * V"eol" + , + +-------------------------------------------------------------------------------- -- Line blocks -------------------------------------------------------------------------------- @@ -861,7 +921,10 @@ local parser = P{ double_underscore = V"underscore" * V"underscore", dash = P"-", double_dash = V"dash" * V"dash", - dashes = V"dash" + P"‒" + P"–" + P"—" + P"―", + triple_dash = V"double_dash" * V"dash", + emdash = P"—", + attrib_dash = V"triple_dash" + V"double_dash" + V"emdash", -- begins quote attribution blocks + dashes = V"dash" + P"‒" + P"–" + V"emdash" + P"―", hyphen = P"‐", semicolon = P";", questionmark = P"?", @@ -920,7 +983,7 @@ local parser = P{ endpar = V"eol" * (V"blank_line"^1 + V"eof"), -- diverse markup character sets - delimiters = P"‐" + P"‑" + P"‒" + P"–" + P"—" + V"space", -- inline markup + delimiters = P"‐" + P"‑" + P"‒" + P"–" + V"emdash" + V"space", -- inline markup adornment_char = S[[!"#$%&'()*+,-./:;<=>?@[]^_`{|}~]] + P[[\\]], -- headings bullet_char = S"*+-" + P"•" + P"‣" + P"⁃", -- bullet lists argument_char = V"double_dash" * V"dash" * V"slash", -- option lists @@ -936,7 +999,7 @@ local parser = P{ enclosed_close = S[['")]}>]], } -f = io.open("option_lists.rst", "r") +f = io.open("blockquote.rst", "r") testdata = f:read("*all") f:close() |