summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilipp Gesang <pgesang@ix.urz.uni-heidelberg.de>2010-09-15 20:34:46 +0200
committerPhilipp Gesang <pgesang@ix.urz.uni-heidelberg.de>2010-09-15 20:34:46 +0200
commitc0b5a4227e09a708ed0440599600cb784d071b9f (patch)
tree6aa5f8a3734b323b99d389cae6ec85b8e51aa713
parentf1786af10f0be9675f83a335581593d45d56836c (diff)
downloadcontext-rst-c0b5a4227e09a708ed0440599600cb784d071b9f.tar.gz
ignoring inline markup delimiters enclosed by parentheses or quotes
-rw-r--r--rst_context.lua90
-rw-r--r--rst_helpers.lua10
2 files changed, 67 insertions, 33 deletions
diff --git a/rst_context.lua b/rst_context.lua
index b85ef2c..6420b5d 100644
--- a/rst_context.lua
+++ b/rst_context.lua
@@ -230,13 +230,22 @@ function rst_context.joinindented (tab)
return table.concat (tab, "")
end
+local corresponding = {
+ ['"'] = '"',
+ ["'"] = "'",
+ ["{"] = "}",
+ ["("] = ")",
+ ["["] = "]",
+ ["<"] = ">",
+}
+
local inline_parser = P{
[1] = "block",
- block = Cs((V"inline_element" + 1)^1),
-
+ block = Cs((V"inquotes" + V"inline_element" + 1)^1),
- inline_element = Cs((V"strong_emphasis"
+ inline_element = V"precede_inline"
+ * Cs((V"strong_emphasis"
+ V"substitution_reference"
+ V"anon_reference"
+ V"reference"
@@ -248,14 +257,44 @@ local inline_parser = P{
+ V"link_standalone")
* V"succede_inline"),
+ precede_inline = V"spacing"
+ + V"eol"
+ + S[['"([{<-/:]]
+ + P"‘" + P"“" + P"’" + P"«" + P"¡" + P"¿"
+ + V"inline_delimiter"
+ + P"„", -- not in standard Murkin reST
+
+ succede_inline = V"spacing"
+ + S[['")]}>-/:.,;!?\]]
+ + P"’" + P"”" + P"»"
+ + V"inline_delimiter"
+ + -P(1)
+ + P"“", -- non-standard again but who cares
+
+ inquotes = V"precede_inline"^-1
+ * Cg(V"quote_single" + V"quote_double" + V"leftpar", "lastgroup")
+ * V"inline_delimiter"
+ * Cmt(C(V"quote_single" + V"quote_double" + V"rightpar") * Cb("lastgroup"), function(s, i, char, oldchar)
+ return corresponding[oldchar] == char
+ end)
+ --* V"succede_inline"
+ ,
+
space = P" ",
whitespace = (P" " + Cs(P"\t") / " " + Cs(S"\v") / " "),
spacing = V"whitespace"^1,
eol = P"\n",
- inline_delimiters = P"‐" + P"‑" + P"‒" + P"–" + V"emdash" + V"space", -- inline markup
- --inline_delimiter = P"**" + P"``" + S"*`",
+ --inline_delimiters = P"‐" + P"‑" + P"‒" + P"–" + V"emdash" + V"space", -- inline markup
+ inline_delimiter = P"‐" + P"‑" + P"‒" + P"–" + V"emdash" + V"space"
+ + V"bareia"
+ + V"asterisk"
+ + V"bar"
+ + V"lsquare" + V"rsquare"
+ , -- inline markup
asterisk = P"*",
+ quote_single = P"'",
+ quote_double = P'"',
double_asterisk = V"asterisk" * V"asterisk",
bareia = P"`",
backslash = P"\\",
@@ -279,7 +318,20 @@ local inline_parser = P{
triple_dash = V"double_dash" * V"dash",
hyphen = P"‐",
dashes = V"dash" + P"‒" + P"–" + V"emdash" + P"―",
- groupchars = S"()[]{}",
+
+ lparenthesis = P"(",
+ rparenthesis = P")",
+ lsquare = P"[",
+ rsquare = P"]",
+ lbrace = P"{",
+ rbrace = P"}",
+ less = P"<",
+ greater = P">",
+ leftpar = V"lparenthesis" + V"lsquare" + V"lbrace" + V"less",
+ rightpar = V"rparenthesis" + V"rsquare" + V"rbrace" + V"greater",
+
+ --groupchars = S"()[]{}",
+ groupchars = V"leftpar" + V"rightpar",
apostrophe = P"’" + P"'",
guillemets = P"«" + P"»",
@@ -288,9 +340,6 @@ local inline_parser = P{
slash = P"/",
gartenzaun = P"#",
- lsquare = P"[",
- rsquare = P"]",
-
digit = R"09",
letter = R"az" + R"AZ",
@@ -313,19 +362,6 @@ local inline_parser = P{
+ V"underscore"
,
- precede_inline = V"spacing"
- + V"eol"
- + S[['"([{<-/:]]
- + P"‘" + P"“" + P"’" + P"«" + P"¡" + P"¿"
- + V"inline_delimiters"
- + P"„", -- not in standard Murkin reST
-
- succede_inline = V"spacing"
- + S[['")]}>-/:.,;!?\]]
- + P"’" + P"”" + P"»"
- + V"inline_delimiters"
- + P"“", -- non-standard again but who cares
-
emphasis = (V"asterisk" - V"double_asterisk")
* Cs((1 - V"spacing" - V"eol" - V"asterisk")
* ((1 - (1 * V"asterisk"))^0
@@ -859,7 +895,6 @@ function rst_context.grid_table (tab)
nr = nr + 1
end
local tail = [[
-
\\eTABLEbody
\\eTABLE
%\\stoplinecorrection
@@ -873,8 +908,8 @@ function rst_context.simple_table(tab)
local nr = 1
if tab.head_end then
head = [[
-\\setupTABLE[c][each] [frame=on]
-\\setupTABLE[r][each] [frame=on]
+\\setupTABLE[c][each] [frame=off]
+\\setupTABLE[r][each] [frame=off]
%\\startlinecorrection
\\bTABLE[split=yes,option=stretch]
\\bTABLEhead
@@ -905,15 +940,14 @@ function rst_context.simple_table(tab)
]]
else
head = [[
-\\setupTABLE[c][each] [frame=on]
-\\setupTABLE[r][each] [frame=on]
+\\setupTABLE[c][each] [frame=off]
+\\setupTABLE[r][each] [frame=off]
%\\startlinecorrection
\\bTABLE[split=yes,option=stretch]
\\bTABLEbody
]]
end
local tail = [[
-
\\eTABLEbody
\\eTABLE
%\\stoplinecorrection
diff --git a/rst_helpers.lua b/rst_helpers.lua
index f7eb950..bb48aed 100644
--- a/rst_helpers.lua
+++ b/rst_helpers.lua
@@ -93,7 +93,7 @@ do
end
function helpers.cell.create(raw, n_row, n_col, parent, variant)
- local p = patterns
+ local p = helpers.patterns
local cell = {}
cell.stripped = raw and p.strip:match(raw) or ""
cell.content = raw
@@ -130,7 +130,7 @@ end
local function set_layout (line)
- local p = patterns
+ local p = helpers.patterns
local layout = {}
local slice = Ct((p.plus * C(p.dash^1) * #p.plus)^1)
@@ -314,7 +314,7 @@ function helpers.table.create(raw)
self.rows = {}
self.layout = set_layout(raw[1])
- local p = patterns
+ local p = helpers.patterns
self.resolve_parent = function(row, col, array)
local array = array or self.rows
@@ -492,7 +492,7 @@ end
-- Check the column boundaries of a simple table.
function helpers.get_st_boundaries (str)
- local p = patterns
+ local p = helpers.patterns
local starts, stops, slices = {}, {}, {}
for n, elm in ipairs({ p.column_starts:match(str) }) do
slices[n] = { start = elm }
@@ -509,7 +509,7 @@ function helpers.table.simple(raw)
local rows = {}
local multispans = {}
local bounds = helpers.get_st_boundaries(raw[1])
- local p = patterns
+ local p = helpers.patterns
for nr, row in ipairs(raw) do
local newrow = {}