summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilipp Gesang <pgesang@ix.urz.uni-heidelberg.de>2010-09-17 13:59:34 +0200
committerPhilipp Gesang <pgesang@ix.urz.uni-heidelberg.de>2010-09-17 13:59:34 +0200
commite9a66b9dc2fba26ba6b8feec152511512e6870a6 (patch)
tree18722aff64bc3ae905544d38892204adc4a06d88
parentc3f271b54f49742caad01663c00d2911c31ed8fc (diff)
downloadcontext-rst-e9a66b9dc2fba26ba6b8feec152511512e6870a6.tar.gz
field lists default to 2column table output
-rw-r--r--rst_context.lua50
-rw-r--r--rst_parser.lua19
2 files changed, 55 insertions, 14 deletions
diff --git a/rst_context.lua b/rst_context.lua
index f0fae72..15655a8 100644
--- a/rst_context.lua
+++ b/rst_context.lua
@@ -223,6 +223,7 @@ end
function rst_context.escape (str)
str = str:gsub("\\(.)", "%1")
+ str = str:gsub("&", "\\letterampersand")
return str
end
@@ -473,7 +474,9 @@ function rst_context.paragraph (data)
if not data then
return ""
elseif type(data) == "table" then
- str = helpers.string.wrapat(inline_parser:match(table.concat(data, " ")), 65)
+ 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
@@ -691,9 +694,10 @@ end
-- when using docinfo and, after all, we have .bib files that are portable.
function rst_context.field_list (str)
+ rst_context.addsetups("fieldlist")
return [[
-\\startfieldlist]] .. str .. [[\\stopfieldlist
+\\startRSTfieldlist]] .. str .. [[\\eTABLEbody\\stopRSTfieldlist
]]
end
@@ -702,17 +706,15 @@ function rst_context.field_name (str)
end
function rst_context.field_body (str)
- return [[\\fieldbody{]] .. str .. [[}]]
+ return [[\\fieldbody{]] .. inline_parser:match(str) .. [[}]]
end
function rst_context.field (tab)
local name, body = tab[1], tab[2]
return string.format([[
- \\startfield
- \\fieldname{%s}
- \\fieldbody{%s}
- \\stopfield
+ \\RSTfieldname{%s}
+ \\RSTfieldbody{%s}
]], name, inline_parser:match(body))
end
@@ -1276,4 +1278,38 @@ function optional_setups.breaks ()
]]
end
+function optional_setups.fieldlist ()
+ return [[
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% Fieldlists %
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+\def\startRSTfieldlist{%
+ \bgroup%
+ \unexpanded\def\RSTfieldname##1{\bTR\bTC ##1\eTC}
+ \unexpanded\def\RSTfieldbody##1{\bTC ##1\eTC\eTR}
+%
+ \setupTABLE[c][first] [background=color, backgroundcolor=grey, style=\bf]
+ \setupTABLE[c][2] [align=right]
+ \setupTABLE[c][each] [frame=off]
+ \setupTABLE[r][each] [frame=off]
+ \bTABLE[split=yes,option=stretch]
+ \bTABLEhead
+ \bTR
+ \bTH Field \eTH
+ \bTH Body \eTH
+ \eTR
+ \eTABLEhead
+ \bTABLEbody
+}
+
+\def\stopRSTfieldlist{%
+ %\eTABLEbody % doesn't work, temporarily moved to rst_context.field_list()
+ \eTABLE
+ \egroup%
+}
+]]
+end
+
return rst_context
diff --git a/rst_parser.lua b/rst_parser.lua
index dec4b6b..26636a1 100644
--- a/rst_parser.lua
+++ b/rst_parser.lua
@@ -719,12 +719,12 @@ local parser = P{
-- Field lists (for bibliographies etc.)
--------------------------------------------------------------------------------
- field_list = Cs(V"field"^1)
- * V"blank_line"^1
+ field_list = Cs(V"field"
+ * (V"blank_line"^-1 * V"field")^0)
+ * V"end_block"
/ rst.field_list,
field = Ct(V"field_marker"
- * V"whitespace"
* V"field_body")
/ rst.field,
@@ -734,14 +734,18 @@ local parser = P{
field_name = (V"escaped_colon" + (1 - V"colon"))^1,
- field_body = C((1 - V"eol")^1 * V"eol"
- * V"indented_lines"^-1),
+ field_body = V"field_single" + V"field_multi",
+
+ field_single = C((1 -V"eol")^1) * V"eol",
+
+ field_multi = C((1 - V"eol")^0 * V"eol"
+ * V"indented_lines"^-1),
--------------------------------------------------------------------------------
-- Definition lists
--------------------------------------------------------------------------------
- definition_list = Ct(V"definition_item"
+ definition_list = Ct((V"definition_item" - V"comment")
* (V"blank_line" * V"definition_item")^0)
* V"end_block"
/ rst.deflist
@@ -753,7 +757,8 @@ local parser = P{
* Ct(V"definition_def"))
,
- definition_term = -#V"space" * (1 - V"eol" - V"definition_classifier_separator")^1
+ definition_term = #(1 - V"space" - V"field_marker")
+ * (1 - V"eol" - V"definition_classifier_separator")^1
,
definition_classifier_separator = V"space" * V"colon" * V"space",