summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--rst_context.lua85
-rw-r--r--rst_parser.lua31
2 files changed, 76 insertions, 40 deletions
diff --git a/rst_context.lua b/rst_context.lua
index 692f458..d8b8516 100644
--- a/rst_context.lua
+++ b/rst_context.lua
@@ -629,34 +629,43 @@ end
--------------------------------------------------------------------------------
-- TODO define proper setups (probably bnf-like and some narrower for def-paragraphs)
-function rst_context.deflist (str)
- return [[
+function rst_context.deflist (list)
+ rst_context.addsetups("deflist")
-\\startdefinitionlist
-]] .. str .. [[
+ local deflist = [[
+\\startRSTdefinitionlist
+]]
+ for nd, item in ipairs(list) do
+ print(#item)
+ local term = item[1]
+ local nc = 2
+ local tmp = [[
+
+ \\RSTdeflistterm{]] .. string.strip(term) .. "}"
+ if #item > 2 then
+ while nc < #item do
+ tmp = tmp .. [[
+
+ \\RSTdeflistclassifier{]] .. string.strip(item[nc]) .. "}"
+ nc = nc + 1
+ end
+ end
+ tmp = tmp .. [[
-\\stopdefinitionlist
+ \\RSTdeflistdefinition{%
]]
-end
-
-function rst_context.deflist_item (str)
- return [[\\definitionitem{%]] .. str .. [[}% end definition item]]
-end
-
-function rst_context.deflist_classifier (str)
- return [[\\definitionclassifier{]] .. str .. [[}]]
-end
-
-function rst_context.deflist_term (str)
- return [[
-
- \\definitionterm{]] .. str .. [[}]]
-end
+ for np, par in ipairs(item[#item]) do -- definitions, multi-paragraph
+ tmp = tmp .. [[
+ \\RSTdeflistparagraph{%
+]] .. inline_parser:match(par) .. "}\n"
+ end
+ tmp = tmp .. " }"
+ deflist = deflist .. tmp
+ end
+ return deflist .. [[
-function rst_context.deflist_def (str)
- return [[
-
- \\definitiondef{%]] .. str .. [[}]]
+\\stopRSTdefinitionlist
+]]
end
--------------------------------------------------------------------------------
@@ -1163,11 +1172,39 @@ end
function optional_setups.blockquote ()
return [[
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% Blockquotes %
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\setupdelimitedtext [blockquote][style={\tfx}] % awful placeholder
\definedelimitedtext[attribution][blockquote]
\setupdelimitedtext [attribution][style={\tfx\it}]
]]
end
+function optional_setups.deflist ()
+ return [[
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% Definitionlist %
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+\def\startRSTdefinitionlist{
+ \bgroup
+ \def \RSTdeflistterm##1{{\bf ##1}}
+ \def\RSTdeflistclassifier##1{\hbox to 1em{\it ##1}}
+ \def\RSTdeflistdefinition##1{%
+ \startnarrower[left]
+ ##1%
+ \stopnarrower}
+ \def\RSTdeflistparagraph ##1{%
+ \startparagraph{%
+ \noindentation ##1
+ \stopparagraph}
+ }
+}
+
+\let\stopRSTdefinitionlist\egroup
+]]
+end
return rst_context
diff --git a/rst_parser.lua b/rst_parser.lua
index 88c894d..bee69f7 100644
--- a/rst_parser.lua
+++ b/rst_parser.lua
@@ -722,32 +722,31 @@ local parser = P{
-- Definition lists
--------------------------------------------------------------------------------
- definition_list = Cs(V"definition_item"
+ definition_list = Ct(V"definition_item"
* (V"blank_line" * V"definition_item")^0)
* V"end_block"
/ rst.deflist
,
- definition_item = Cs(V"definition_term"
+ definition_item = Ct(C(V"definition_term")
* V"definition_classifiers"
* V"eol"
- * V"definition_def")
- / rst.deflist_item,
+ * Ct(V"definition_def"))
+ ,
- definition_term = Cs((1 - V"eol" - V"definition_classifier_separator")^1)
- / rst.deflist_term,
+ definition_term = (1 - V"eol" - V"definition_classifier_separator")^1
+ ,
definition_classifier_separator = V"space" * V"colon" * V"space",
definition_classifiers = V"definition_classifier"^0,
definition_classifier = V"definition_classifier_separator"
- * Cs((1 - V"eol" - V"definition_classifier_separator")^1)
- / rst.deflist_classifier,
+ * C((1 - V"eol" - V"definition_classifier_separator")^1)
+ ,
- definition_def = Cs(V"definition_firstpar"
- * V"definition_par"^0)
- / rst.deflist_def,
+ definition_def = C(V"definition_firstpar") * C(V"definition_par")^0
+ ,
definition_indent = Cmt(V"space"^1, function(s, i, indent)
warn("def-i", #indent, #state.currentindent, indent == state.currentindent, i)
@@ -755,13 +754,13 @@ local parser = P{
return true
end),
- definition_firstpar = Cs(V"definition_parinit"
- * (V"definition_parline" - V"blank_line")^0)
- / rst.paragraph,
+ definition_firstpar = V"definition_parinit"
+ * (V"definition_parline" - V"blank_line")^0
+ ,
definition_par = V"blank_line"
- * Cs((V"definition_parline" - V"blank_line")^1)
- / rst.paragraph,
+ * (V"definition_parline" - V"blank_line")^1
+ ,
definition_parinit = V"definition_indent"
* (1 - V"eol")^1