summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/context
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/tex/context')
-rw-r--r--Master/texmf-dist/tex/context/interface/third/t-rst.xml55
-rw-r--r--Master/texmf-dist/tex/context/third/rst/rst_context.lua94
-rw-r--r--Master/texmf-dist/tex/context/third/rst/rst_directives.lua67
-rw-r--r--Master/texmf-dist/tex/context/third/rst/rst_helpers.lua29
-rw-r--r--Master/texmf-dist/tex/context/third/rst/rst_parser.lua483
-rw-r--r--Master/texmf-dist/tex/context/third/rst/rst_setups.lua26
-rw-r--r--Master/texmf-dist/tex/context/third/rst/t-rst.mkiv80
7 files changed, 555 insertions, 279 deletions
diff --git a/Master/texmf-dist/tex/context/interface/third/t-rst.xml b/Master/texmf-dist/tex/context/interface/third/t-rst.xml
index 52a93803718..40015e26586 100644
--- a/Master/texmf-dist/tex/context/interface/third/t-rst.xml
+++ b/Master/texmf-dist/tex/context/interface/third/t-rst.xml
@@ -3,14 +3,27 @@
<cd:interface xmlns:cd="http://www.pragma-ade.com/commands"
name="context"
language="en"
- version="0.4; 2011-05-08 15:08:34+0200">
+ version="0.6; 2011-08-28 13:46:23+0200">
<cd:command name="typesetRSTfile" generated="no" file="t-rst.mkiv">
<cd:sequence>
<cd:variable value="typesetRSTfile"/>
</cd:sequence>
<cd:arguments>
- <cd:content n="1" optional="no"/>
+ <cd:assignments n="1" list="yes" optional="yes">
+ <cd:parameter name="expandtab">
+ <cd:constant type="false" default="false"/>
+ <cd:constant type="true"/>
+ </cd:parameter>
+ <cd:parameter name="shiftwidth">
+ <cd:constant type="cd:number" default="4"/>
+ </cd:parameter>
+ <cd:parameter name="stripBOM">
+ <cd:constant type="false" default="false"/>
+ <cd:constant type="true"/>
+ </cd:parameter>
+ </cd:assignments>
+ <cd:content n="2" optional="no"/>
</cd:arguments>
</cd:command>
@@ -29,4 +42,42 @@
</cd:sequence>
</cd:command>
+ <cd:command name="RSTproject" generated="no" type="environment" file="t-rst.mkiv">
+ <cd:sequence>
+ <cd:variable value="RST"/>
+ </cd:sequence>
+ </cd:command>
+
+ <cd:command name="defineRSTinclusion" generated="no" file="t-rst.mkiv">
+ <cd:sequence>
+ <cd:variable value="defineRSTinclusion"/>
+ </cd:sequence>
+ <cd:arguments>
+ <cd:content n="1" optional="yes" name="id"/>
+ <cd:content n="2" optional="yes" name="filename"/>
+ <cd:assignments n="3" list="yes" optional="yes">
+ <cd:parameter name="expandtab">
+ <cd:constant type="false" default="false"/>
+ <cd:constant type="true"/>
+ </cd:parameter>
+ <cd:parameter name="shiftwidth">
+ <cd:constant type="cd:number" default="4"/>
+ </cd:parameter>
+ <cd:parameter name="stripBOM">
+ <cd:constant type="false" default="false"/>
+ <cd:constant type="true"/>
+ </cd:parameter>
+ </cd:assignments>
+ </cd:arguments>
+ </cd:command>
+
+ <cd:command name="RSTinclusion" generated="no" file="t-rst.mkiv">
+ <cd:sequence>
+ <cd:variable value="RSTinclusion"/>
+ </cd:sequence>
+ <cd:arguments>
+ <cd:content n="1" optional="yes" name="id"/>
+ </cd:arguments>
+ </cd:command>
+
</cd:interface>
diff --git a/Master/texmf-dist/tex/context/third/rst/rst_context.lua b/Master/texmf-dist/tex/context/third/rst/rst_context.lua
index 86f4177c9e0..6a5aa05daaf 100644
--- a/Master/texmf-dist/tex/context/third/rst/rst_context.lua
+++ b/Master/texmf-dist/tex/context/third/rst/rst_context.lua
@@ -4,7 +4,7 @@
-- USAGE: called by rst_parser.lua
-- DESCRIPTION: Complement to the reStructuredText parser
-- AUTHOR: Philipp Gesang (Phg), <megas.kapaneus@gmail.com>
--- CREATED: 2011-05-04 17:42:04+0200
+-- CHANGED: 2011-08-28 13:46:46+0200
--------------------------------------------------------------------------------
--
--- TODO
@@ -18,11 +18,16 @@
local helpers = helpers or thirddata and thirddata.rst_helpers
local rst_directives = rst_directives or thirddata and thirddata.rst_directives
-local utf = unicode.utf8
+local utf = unicode.utf8
+local utflen = utf.len
+local utflower = utf.lower
+local utfupper = utf.upper
+local iowrite = io.write
local dbg_write = helpers.dbg_writef
-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, 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
-- This one should ignore escaped spaces.
do
@@ -37,14 +42,16 @@ do
return stripper:match(str) or ""
end
end
+local stringstrip = string.strip
+local fmt = string.format
local err = function(str)
if str then
- io.write("\n*[rstctx] Error: " .. str .. "\n\n")
+ iowrite("\n*[rstctx] Error: " .. str .. "\n\n")
end
end
-rst_context = {}
+local rst_context = thirddata.rst
rst_context.collected_adornments = {}
rst_context.last_section_level = 0
@@ -145,11 +152,11 @@ rst_context.roles.sans_serif = rst_context.roles.sans
rst_context.roles.ss = rst_context.roles.sans
rst_context.roles.uppercase = function(str)
- return utf.upper(str)
+ return utfupper(str)
end
rst_context.roles.lowercase = function(str)
- return utf.lower(str)
+ return utflower(str)
end
rst_context.roles.color = function(color, str)
@@ -157,12 +164,14 @@ rst_context.roles.color = function(color, str)
local definition = color:match("^color_(.+)$")
if definition:match("^rgb_") then -- assume rgb
local rgb = p.rgbvalues:match(definition)
- definition = string.format([[r=%s,g=%s,b=%s]], rgb[1], rgb[2], rgb[3])
+ definition = fmt([[r=%s,g=%s,b=%s]], rgb[1], rgb[2], rgb[3])
end
- return string.format([[\\colored[%s]{%s}]], definition, str)
+ return fmt([[\\colored[%s]{%s}]], definition, str)
end
+--------------------------------------------------------------------------------
--- Inofficial text roles for my private bib
+--------------------------------------------------------------------------------
-- Afterthought:
-- Different citation commands are essentially typographical instructions:
@@ -223,7 +232,22 @@ function rst_context.roles.nocite(str) -- nocite
return [[\\nocite[]] .. str .. [=[]]=]
end
+--------------------------------------------------------------------------------
--- End citator roles
+--------------------------------------------------------------------------------
+
+--------------------------------------------------------------------------------
+--- Experimental roles.
+--------------------------------------------------------------------------------
+
+--- Feature request by Philipp A.
+function rst_context.roles.math(str)
+ return [[\\mathematics{]] .. str .. [[}]]
+end
+
+--------------------------------------------------------------------------------
+--- End roles
+--------------------------------------------------------------------------------
function rst_context.interpreted_text (...)
local tab = { ... }
@@ -259,7 +283,7 @@ function rst_context.anon_reference (str)
str = str:match("^`?([^`]+)`?__$")
rst_context.anonymous_links[#rst_context.anonymous_links+1] = str
link = "__target_anon_" .. #rst_context.anonymous_links
- return string.format([[\\RSTchoosegoto{%s}{%s}]], link, str)
+ return fmt([[\\RSTchoosegoto{%s}{%s}]], link, str)
end
local whitespace = S" \n\t\v"
@@ -311,7 +335,7 @@ function rst_context.substitution_reference (str, underscores)
local sub = ""
rst_context.addsetups("substitutions")
if underscores == "_" then -- normal reference
- sub = sub .. [[\\reference[__target_]] .. rst_context.whitespace_to_underscore(string.strip(str)) .. "]{}"
+ sub = sub .. [[\\reference[__target_]] .. rst_context.whitespace_to_underscore(stringstrip(str)) .. "]{}"
elseif underscores == "__" then -- normal reference
rst_context.anonymous_targets = rst_context.anonymous_targets + 1
sub = sub .. [[\\reference[__target_anon_]] .. rst_context.anonymous_targets .. "]{}"
@@ -342,7 +366,8 @@ do
skip1 = P"\\starttyping" * (1 - P"\\stoptyping")^1,
balanced = P"{" * (V"balanced" + (1 - P"}"))^0 * P"}",
skip2 = P"\\type" * V"balanced",
- skip = V"skip1" + V"skip2",
+ skip3 = P"\\mathematics" * V"balanced",
+ skip = V"skip1" + V"skip2" + V"skip3",
--literal = Cs(P"\\" / "") * 1
}
@@ -368,7 +393,7 @@ local corresponding = {
local inline_parser = P{
[1] = "block",
- block = Cs(V"inline_as_first"^-1 * (V"except" + V"inline_element" + 1)^1),
+ block = Cs(V"inline_as_first"^-1 * (V"except" + V"inline_element" + 1)^0),
inline_element = V"precede_inline"
* Cs(V"inline_do_elements")
@@ -526,11 +551,12 @@ local inline_parser = P{
* V"double_bareia"
/ rst_context.literal,
+ interpreted_single_char = (1 - V"spacing" - V"eol" - V"bareia") * #V"bareia",
+ interpreted_multi_char = (1 - V"spacing" - V"eol" - V"bareia") * (1 - (1 * V"bareia"))^0 * (1 - V"spacing" - V"eol" - V"bareia"),
+
interpreted_text = C(V"role_marker"^-1)
* (V"bareia" - V"double_bareia")
- * C ((1 - V"spacing" - V"eol" - V"bareia")
- * ((1 - (1 * V"bareia"))^0
- * (1 - V"spacing" - V"eol" - V"bareia"))^-1)
+ * C(V"interpreted_single_char" + V"interpreted_multi_char")
* V"bareia"
* C(V"role_marker"^-1)
/ rst_context.interpreted_text,
@@ -612,7 +638,7 @@ function rst_context.paragraph (data)
else
str = data
end
- return string.format([[
+ return fmt([[
\\startparagraph
%s
@@ -636,12 +662,12 @@ function rst_context.section (...) -- TODO general cleanup; move validity
local tab = { ... } -- checking to parser.
local section, str = true, ""
local adornchar
- local ulen = unicode.utf8.len
+ local ulen = utflen
if #tab == 3 then -- TODO use unicode length with ConTeXt
adornchar = tab[1]:sub(1,1)
section = ulen(tab[1]) >= ulen(tab[2])
--section = get_line_pattern(adornchar):match(tab[1]) ~= nil and section
- str = string.strip(tab[2])
+ str = stringstrip(tab[2])
else -- no overline
adornchar = tab[2]:sub(1,1)
section = ulen(tab[1]) <= ulen(tab[2])
@@ -662,7 +688,7 @@ function rst_context.section (...) -- TODO general cleanup; move validity
ref = get_context_reference (str)
- str = string.format("\n\\\\%s[%s]{%s}\n", sectionlevels[level], ref, str)
+ str = fmt("\n\\\\%s[%s]{%s}\n", sectionlevels[level], ref, str)
else
return [[{\\bf fix your sectioning!}\\endgraf}]]
end
@@ -690,7 +716,7 @@ do
escaped = P"\\" * V"space",
nospace = V"escaped" + (1 - V"space"),
}
- function string.strip(str)
+ function stringstrip(str)
return stripper:match(str) or ""
end
end
@@ -744,7 +770,7 @@ end
function rst_context.startitemize(str)
local setup = ""
local result = ""
- str = string.strip(str)
+ str = stringstrip(str)
local listtype = enumeration_types[str] or parse_itemstring(str)
@@ -784,8 +810,8 @@ function rst_context.bullet_item (tab)
if helpers.list.successor(itemtype, li[current_itemdepth]) then
-- just leave it alone
elseif helpers.list.greater(itemtype, li[current_itemdepth]) then
- local itemnum = tonumber(string.strip(itemtype)) or helpers.list.get_decimal(itemtype)
- result = result .. string.format([[
+ local itemnum = tonumber(stringstrip(itemtype)) or helpers.list.get_decimal(itemtype)
+ result = result .. fmt([[
\\setnumber[itemgroup:itemize]{%s}
]], itemnum)
end
@@ -815,12 +841,12 @@ function rst_context.deflist (list)
local nc = 2
local tmp = [[
- \\RSTdeflistterm{]] .. string.strip(term) .. "}"
+ \\RSTdeflistterm{]] .. stringstrip(term) .. "}"
if #item > 2 then
while nc < #item do
tmp = tmp .. [[
- \\RSTdeflistclassifier{]] .. string.strip(item[nc]) .. "}"
+ \\RSTdeflistclassifier{]] .. stringstrip(item[nc]) .. "}"
nc = nc + 1
end
end
@@ -868,7 +894,7 @@ end
function rst_context.field (tab)
local name, body = tab[1], tab[2]
- return string.format([[
+ return fmt([[
\\RSTfieldname{%s}
\\RSTfieldbody{%s}
@@ -880,10 +906,10 @@ function rst_context.line_comment (str)
end
function rst_context.block_comment (str)
- return string.format([[
+ return fmt([[
-\iffalse
-%s\fi
+\iffalse %% start block comment
+%s\fi %% stop block comment
]], str)
end
@@ -908,7 +934,7 @@ function rst_context.option_list (str)
end
function rst_context.option_item (tab)
- return string.format([[\\bTR\\bTC %s \\eTC\\bTC %s \\eTC\\eTR
+ return fmt([[\\bTR\\bTC %s \\eTC\\bTC %s \\eTC\\eTR
]], tab[1], tab[2])
end
@@ -1134,7 +1160,7 @@ function rst_context.simple_table(tab)
dbg_write("%7s | ", cell.content)
local celltext = inline_parser:match(cell.content)
if cell.span then
- head = head .. string.format([=[\\bTH[nc=%s]%s\\eTH]=], cell.span.x, celltext or "")
+ head = head .. fmt([=[\\bTH[nc=%s]%s\\eTH]=], cell.span.x, celltext or "")
else
head = head .. [[\\bTH ]] .. celltext .. [[\\eTH]]
end
@@ -1173,7 +1199,7 @@ function rst_context.simple_table(tab)
dbg_write("%7s | ", cell.content)
local celltext = inline_parser:match(cell.content)
if cell.span then
- body = body .. string.format([=[\\bTC[nc=%s]%s\\eTC]=], cell.span.x, celltext or "")
+ body = body .. fmt([=[\\bTC[nc=%s]%s\\eTC]=], cell.span.x, celltext or "")
else
body = body .. [[\\bTC ]] .. celltext .. [[\\eTC]]
end
@@ -1229,5 +1255,3 @@ function rst_context.directive(directive, ...)
end
return result
end
-
-return rst_context
diff --git a/Master/texmf-dist/tex/context/third/rst/rst_directives.lua b/Master/texmf-dist/tex/context/third/rst/rst_directives.lua
index a8a5eb76bdd..96eaf591fa5 100644
--- a/Master/texmf-dist/tex/context/third/rst/rst_directives.lua
+++ b/Master/texmf-dist/tex/context/third/rst/rst_directives.lua
@@ -4,7 +4,7 @@
-- USAGE: called by rst_parser.lua
-- DESCRIPTION: Complement to the reStructuredText parser
-- AUTHOR: Philipp Gesang (Phg), <megas.kapaneus@gmail.com>
--- CHANGED: 2011-05-08 17:56:25+0200
+-- CHANGED: 2011-08-28 13:47:00+0200
--------------------------------------------------------------------------------
--
@@ -14,10 +14,12 @@ local helpers = helpers or thirddata and thirddata.rst_helpers
-- Directives for use with |substitutions|
--------------------------------------------------------------------------------
-local rst_directives = { }
-if context then
- thirddata.rst_directives = rst_directives
-end
+local rst_directives = { }
+thirddata.rst_directives = rst_directives
+local rst_context = thirddata.rst
+
+local stringstrip = string.strip
+local fmt = string.format
rst_directives.anonymous = 0
rst_directives.images = {}
@@ -95,7 +97,7 @@ rst_directives.image = function(name, data)
end
properties[key] = val
else
- processed = processed .. (str and str ~= "" and string.strip(str))
+ processed = processed .. (str and str ~= "" and stringstrip(str))
end
end
end
@@ -106,19 +108,19 @@ rst_directives.image = function(name, data)
local images_done = rd.images.done
if not anon then
if not images_done[name] then
- img = img .. string.format([[
+ img = img .. fmt([[
\useexternalfigure[%s][%s][]
]], name, data)
images_done[name] = true
end
- img = img .. string.format([[
+ img = img .. fmt([[
\def\RSTsubstitution%s{%%
\placefigure[here]{%s}{\externalfigure[%s]%s}
}
]], name, rst_context.escape(inline_parser:match(properties.caption)), name, properties.setup)
else -- image won't be referenced but used instantly
- img = img .. string.format([[
+ img = img .. fmt([[
\placefigure[here]{%s}{\externalfigure[%s]%s}
]], rst_context.escape(inline_parser:match(properties.caption)), data, properties.setup)
@@ -143,7 +145,7 @@ rst_directives.caution = function(raw)
end
end
text = rst_context.escape(helpers.string.wrapat(inline_parser:match(text)))
- return string.format([[
+ return fmt([[
\startRSTcaution
%s
\stopRSTcaution
@@ -167,7 +169,7 @@ rst_directives.danger = function(raw)
end
end
text = rst_context.escape(helpers.string.wrapat(inline_parser:match(text)))
- return string.format([[
+ return fmt([[
\startRSTdanger
%s
\stopRSTdanger
@@ -178,9 +180,9 @@ end
rst_directives.DANGER = function(addendum)
local result = ""
for _,str in ipairs(addendum) do
- result = result .. (string.strip(str))
+ result = result .. (stringstrip(str))
end
- return string.format([[
+ return fmt([[
%% The Rabbit of Caerbannog
\startlinecorrection
@@ -211,12 +213,12 @@ rst_directives.DANGER = function(addendum)
end
rst_directives.mp = function(name, data)
- local mpcode = string.format([[
+ local mpcode = fmt([[
\startreusableMPgraphic{%s}
%s
\stopreusableMPgraphic
]], name, data)
- mpcode = mpcode .. string.format([[
+ mpcode = mpcode .. fmt([[
\def\RSTsubstitution%s{%%
\reuseMPgraphic{%s}%%
}
@@ -225,7 +227,7 @@ rst_directives.mp = function(name, data)
end
rst_directives.ctx = function(name, data)
- local ctx = string.format([[
+ local ctx = fmt([[
\startbuffer[%s]
%s\stopbuffer
@@ -237,7 +239,7 @@ rst_directives.ctx = function(name, data)
end
rst_directives.lua = function(name, data)
- local luacode = string.format([[
+ local luacode = fmt([[
\startbuffer[%s]
\startluacode
@@ -251,11 +253,38 @@ rst_directives.lua = function(name, data)
return luacode
end
+--------------------------------------------------------------------------------
+--- Experimental math directive
+--------------------------------------------------------------------------------
+
+rst_directives.math = function (name, data)
+ data = data or name
+ local formula
+ if type(data) == "table" then
+ local last, i = table.maxn(data), 1
+ while i <= last do
+ local line = stringstrip(data[i])
+ if line and line ~= "" then
+ formula = formula and formula .. " " .. line or line
+ end
+ i = i + 1
+ end
+ end
+ return fmt([[
+\startformula
+%s
+\stopformula
+]], formula)
+end
+
+--------------------------------------------------------------------------------
+--- End math directive
+--------------------------------------------------------------------------------
+
rst_directives.replace = function(name, data)
- return string.format([[
+ return fmt([[
\def\RSTsubstitution%s{%s}
]], name, data)
end
-return rst_directives
diff --git a/Master/texmf-dist/tex/context/third/rst/rst_helpers.lua b/Master/texmf-dist/tex/context/third/rst/rst_helpers.lua
index 73420d0db10..9f388c100d1 100644
--- a/Master/texmf-dist/tex/context/third/rst/rst_helpers.lua
+++ b/Master/texmf-dist/tex/context/third/rst/rst_helpers.lua
@@ -4,11 +4,10 @@
-- USAGE: called by rst_parser.lua
-- DESCRIPTION: Complement to the reStructuredText parser
-- AUTHOR: Philipp Gesang (Phg), <megas.kapaneus@gmail.com>
--- CHANGED: 2011-05-08 17:56:07+0200
+-- CHANGED: 2011-08-28 13:47:07+0200
--------------------------------------------------------------------------------
--
-local utf = unicode.utf8
local P, R, S, V, match
= lpeg.P, lpeg.R, lpeg.S, lpeg.V, lpeg.match
@@ -20,9 +19,15 @@ helpers = thirddata.rst_helpers
helpers.table = {}
helpers.cell = {}
+local utf = unicode.utf8
+local utflen = utf.len
+
+local stringstrip = string.strip
+local fmt = string.format
+
function helpers.dbg_writef(...)
if helpers.rst_debug then
- io.write(string.format(...))
+ io.write(fmt(...))
end
end
@@ -95,7 +100,7 @@ do
local escaped_colon = P"\\:"
local nocolon = (escaped_colon + (1 - colon))^1
p.colon_right = nocolon * colon
- p.colon_keyval = C(nocolon) * colon * p.space^1 * C((1 - (p.space^0 * P(-1)))^1)
+ p.colon_keyval = colon^-1 * C(nocolon) * colon * p.space^1 * C((1 - (p.space^0 * P(-1)))^1)
-- color expression matching for text roles
local digit = R"09"
@@ -113,7 +118,7 @@ function helpers.cell.create(raw, n_row, n_col, parent, variant)
local cell = {}
cell.stripped = raw and p.strip:match(raw) or ""
cell.content = raw
- cell.width = raw and utf.len(raw) or 0
+ cell.width = raw and utflen(raw) or 0
cell.bytes = raw and #raw or 0
cell.variant = "normal" -- [normal|separator|y_continue|x_continue]
cell.pos = {}
@@ -131,7 +136,7 @@ function helpers.cell.get_x_span(content, layout, init)
local lw = layout.widths
for n=init, #lw do
acc = acc + lw[n] + 1
- if utf.len(content) + 1 == acc then
+ if utflen(content) + 1 == acc then
return n - init
end
end
@@ -215,7 +220,7 @@ function helpers.table.create(raw)
this.variant = "empty1"
end
else
- local cellwidth = utf.len(splitpos)
+ local cellwidth = utflen(splitpos)
if cellwidth > layoutwidth then
span = span + hc.get_x_span(splitpos, newtablayout, pos_layout)
end
@@ -367,7 +372,7 @@ function helpers.table.simple(raw)
content = "",
span = { x = 1, y = 1 },
}
- cell.content = string.strip(row:sub(start, stop))
+ cell.content = stringstrip(row:sub(start, stop))
if check_span then
local start_at, stop_at
for colnr, slice in ipairs(bounds.slices) do
@@ -590,7 +595,7 @@ do
-- This grammar inside the function is slightly faster than the same as an upvalue
-- with the value of “width” repeatedly given via lpeg.Carg(). This holds
-- for repeated calls as well.
- local ulen = utf.len
+ local ulen = utflen
function helpers.string.wrapat (str, width)
local width = width or 65
local linelength = 0
@@ -600,7 +605,9 @@ do
wrapper = Cs(V"nowhitespace"^0 * (Cs(V"wrapme") + V"other")^1),
whitespace = S" \t\v" + P"\n" / function() linelength = 0 end,
nowhitespace = 1 - V"whitespace",
- ignore = P[[\\type{]] * (1 - P"}")^0 * P"}",
+ typing = P[[\\type{]] * (1 - P"}")^0 * P"}",
+ typingenv = P[[\\starttyping]] * (1 - P[[\\stoptyping]])^0 * P[[\\stoptyping]],
+ ignore = V"typing" + V"typingenv",
-- the initial whitespace of the “other” pattern must not be
-- enforced (“^1”) as it will break the exceptions (“ignore”
-- pattern)! In general it is better to have the wrapper ignore some
@@ -625,5 +632,3 @@ do
end
end
-return helpers
-
diff --git a/Master/texmf-dist/tex/context/third/rst/rst_parser.lua b/Master/texmf-dist/tex/context/third/rst/rst_parser.lua
index 6aeeb7d584a..9735635e6fe 100644
--- a/Master/texmf-dist/tex/context/third/rst/rst_parser.lua
+++ b/Master/texmf-dist/tex/context/third/rst/rst_parser.lua
@@ -4,54 +4,60 @@
-- USAGE: refer to doc/documentation.rst
-- DESCRIPTION: https://bitbucket.org/phg/context-rst/overview
-- AUTHOR: Philipp Gesang (Phg), <megas.kapaneus@gmail.com>
--- VERSION: 0.3
--- CHANGED: 2011-05-08 17:55:54+0200
+-- VERSION: 0.5
+-- CHANGED: 2011-08-28 22:29:33+0200
--------------------------------------------------------------------------------
--
-local rst
-local optional_setups
thirddata = thirddata or { }
thirddata.rst = { }
thirddata.rst_helpers = { }
+
+environment.loadluafile"rst_helpers"
+environment.loadluafile"rst_directives"
+environment.loadluafile"rst_setups"
+environment.loadluafile"rst_context"
+
+local rst = thirddata.rst
local helpers = thirddata.rst_helpers
-if context then
- --thirddata.rst_setups = optional_setups
-
- environment.loadluafile("rst_helpers")
- environment.loadluafile("rst_directives")
- environment.loadluafile("rst_setups" )
- environment.loadluafile("rst_context")
-
- rst = rst_context
- optional_setups = thirddata.rst_setups
-else
- --helpers = require "rst_helpers"
- require "rst_helpers"
- rst_directives = require "rst_directives"
- optional_setups = require "rst_setups"
- rst = require "rst_context"
-end
+local optional_setups = thirddata.rst_setups
+rst.strip_BOM = false
+rst.expandtab = false
+rst.shiftwidth = 4
+rst.crlf = true
helpers.rst_debug = false
-local warn = function(str, ...)
- if not helpers.rst_debug then return false end
- local slen = #str + 3
- str = "*["..str.."]"
- for i,j in ipairs({...}) do
- if 80 - i * 8 - slen < 0 then
- local indent = ""
- for i=1, slen do
- indent = indent .. " "
+local iowrite = io.write
+local fmt = string.format
+local stringlen = string.len
+local stringstrip = string.strip
+local utf = unicode.utf8
+local utflen = utf.len
+
+local warn
+do
+ local ndebug = 0
+ warn = function(str, ...)
+ if not helpers.rst_debug then return false end
+ ndebug = ndebug + 1
+ local slen = #str + 3
+ --str = "*["..str.."]"
+ str = fmt("*[%4d][%s]", ndebug, str)
+ for i,j in ipairs({...}) do
+ if 80 - i * 8 - slen < 0 then
+ local indent = ""
+ for i=1, slen do
+ indent = indent .. " "
+ end
+ str = str .. "\n" .. indent
end
- str = str .. "\n" .. indent
+ str = str .. fmt(" |%6s", stringstrip(tostring(j)))
end
- str = str .. string.format(" |%6s", string.strip(tostring(j)))
+ iowrite(str .. " |\n")
+ return 0
end
- io.write(str .. " |\n")
- return 0
end
local C, Cb, Cc, Cg, Cmt, Cp, Cs, Ct
@@ -62,41 +68,33 @@ local P, R, S, V, match
local utf = unicode.utf8
-local eol = P"\n"
-
-state = {}
-state.depth = 0
-state.bullets = {} -- mapping bullet forms to depth
-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.previousindent = "" -- for literal blocks included in paragraphs to restore the paragraph indent
-state.currentwidth = 0 -- table layout
-state.currentlayout = {} -- table layout
+state = {}
+state.depth = 0
+state.bullets = {} -- mapping bullet forms to depth
+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.previousindent = "" -- for literal blocks included in paragraphs to restore the paragraph indent
+state.currentwidth = 0 -- table layout
+state.currentlayout = {} -- table layout
state.previousadorn = nil -- section underlining and overlining
-state.footnotes = {}
+state.footnotes = {}
state.footnotes.autonumber = 0
state.footnotes.numbered = {}
state.footnotes.labeled = {}
state.footnotes.autolabel = {}
state.footnotes.symbol = {}
-state.addme = {}
+state.addme = {}
do
local first_adornment = ""
local valid_adornment = P{
[1] = "adorncheck",
adorncheck = V"check_first" * V"check_other"^1 * -P(1),
-
- -- check_first = Cg(V"adornment_char", "first"), -- This *should* work but but due to some heavenly
- -- intervention the governing rules of the universe
- -- have been altered so as to annoy everybody
- -- trying to deploy it.
-
check_first = Cmt(V"adornment_char", function(_,_, first)
first_adornment = first
return true
@@ -197,7 +195,7 @@ local parser = P{
substitution_definition = V"explicit_markup_start"
* V"substitution_text"
- * V"whitespace"
+ * V"whitespace"^1
* C((1 - V"colon" - V"space" - V"eol")^1) -- directive
* V"double_colon"
* Ct(V"data_directive_block")
@@ -285,7 +283,7 @@ local parser = P{
return true
end)
* (1 - V"eol")^1 * V"eol"
- ,
+ ,
fn_matchindent = Cmt(V"space"^1, function(s, i, indent)
local tc = state.currentindent
@@ -550,7 +548,7 @@ local parser = P{
block_quote_attri_first = Cmt(V"space"^1 * V"attrib_dash" * V"space", function (s, i, indent)
local t = state
- warn("bqa-i", utf.len(indent), #t.currentindent,
+ warn("bqa-i", utflen(indent), #t.currentindent,
indent, t.currentindent, i)
local ret = indent:match(" *") == t.currentindent
t.currentindent = ret and indent or t.currentindent
@@ -561,9 +559,9 @@ local parser = P{
,
block_quote_attri_other = Cmt(V"space"^1, function (s, i, indent)
- warn("bqa-m", #indent, utf.len(state.currentindent),
+ warn("bqa-m", #indent, utflen(state.currentindent),
indent, state.currentindent, i)
- return utf.len(state.currentindent) == #indent
+ return utflen(state.currentindent) == #indent
end) / ""
* (1 - V"eol")^1
* V"eol"
@@ -635,15 +633,16 @@ local parser = P{
literal_block_marker = V"double_colon" * V"whitespace"^0 * V"eol" * V"blank_line",
literal_block_lines = V"unquoted_literal_block_lines"
- + V"quoted_literal_block_lines",
+ + V"quoted_literal_block_lines"
+ ,
unquoted_literal_block_lines = V"literal_block_first"
* (V"blank_line"^-1 * V"literal_block_other")^0
,
- quoted_literal_block_lines = V"quoted_literal_block_first"
- * (V"blank_line"^-1 * V"quoted_literal_block_other")^0
- ,
+ quoted_literal_block_lines = V"quoted_literal_block_first"
+ * V"quoted_literal_block_other"^0 -- no blank lines allowed
+ ,
literal_block_first = Cmt(V"space"^1, function (s, i, indent)
warn("lbk-f", #indent, "", "", i)
@@ -671,10 +670,11 @@ local parser = P{
return #indent >= #state.currentindent
end)
* V"rest_of_line"
- * V"eol",
+ * V"eol"
+ ,
quoted_literal_block_first = Cmt(V"adornment_char", function (s, i, indent)
- warn("lbk-f", #indent, "", "", i)
+ warn("qlb-f", #indent, indent, "", i)
if not indent or
indent == "" then
return false
@@ -683,10 +683,11 @@ local parser = P{
return true
end)
* V"rest_of_line"
- * V"eol",
+ * V"eol"
+ ,
quoted_literal_block_other = Cmt(V"adornment_char", function (s, i, indent)
- warn("lbk-m",
+ warn("qlb-m",
#indent,
#state.currentindent,
#indent >= #state.currentindent,
@@ -769,6 +770,7 @@ local parser = P{
/ rst.field_list,
field = Ct(V"field_marker"
+ * V"whitespace"
* V"field_body")
/ rst.field,
@@ -887,7 +889,7 @@ local parser = P{
t.bullets.max = t.bullets.max < t.depth and t.depth or t.bullets.max
return true
elseif t.depth > 0 and n_spaces > 1 then -- sublist (of sublist)^0
- if n_spaces >= utf.len(oldbullet) then
+ if n_spaces >= utflen(oldbullet) then
t.lastbullets[t.depth] = t.lastbullet
t.depth = t.depth + 1
t.bullets[t.depth] = bullet
@@ -917,7 +919,7 @@ local parser = P{
conversion(bullet)
)
- if utf.len(t.bullets[t.depth]) ~= utf.len(bullet) then
+ if utflen(t.bullets[t.depth]) ~= utflen(bullet) then
return false
elseif not conversion(bullet) and t.bullets[t.depth] == bullet then
return true
@@ -950,9 +952,9 @@ local parser = P{
local t = state
warn("match",
t.depth,
- string.len(this) == utf.len(t.bullets[t.depth]),
- utf.len(t.bullets[t.depth]), string.len(this) )
- return string.len(this) == utf.len(t.bullets[t.depth])
+ stringlen(this) == utflen(t.bullets[t.depth]),
+ utflen(t.bullets[t.depth]), stringlen(this) )
+ return stringlen(this) == utflen(t.bullets[t.depth])
end)
,
@@ -1096,7 +1098,10 @@ local parser = P{
* V"reset_depth"
,
- par_first = V"par_setindent" * C((1 - V"literal_block_shorthand" - V"eol")^1) * V"eol",
+ par_first = V"par_setindent"
+ * C((1 - V"literal_block_shorthand" - V"eol")^1)
+ * (V"included_literal_block" + V"eol")
+ ,
par_other = V"par_matchindent"
* C((1 - V"literal_block_shorthand" - V"eol")^1)
@@ -1115,14 +1120,6 @@ local parser = P{
return state.currentindent == indent
end),
- link_standalone = C(V"uri")
- / rst.link_standalone,
-
- reference = Cs(V"_reference")
- / rst.reference,
-
- _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"
* Cmt(Cp(), function (s, i, _)
@@ -1132,8 +1129,8 @@ local parser = P{
end)
,
- literal_block_shorthand = Cs(((V"colon" * V"space" * V"double_colon")
- + V"double_colon")
+ literal_block_shorthand = Cs((V"colon" * V"space" * V"double_colon"
+ + V"double_colon")
* V"whitespace"^0
* V"eol"
* V"blank_line")
@@ -1149,8 +1146,7 @@ local parser = P{
/ "\\\\unskip:"
,
- literal_block_markerless = Cs(V"literal_block_lines"
- * (V"blank_line"^1 * V"literal_block_lines")^0)
+ literal_block_markerless = Cs(V"literal_block_lines")
* V"blank_line"
/ rst.included_literal_block
,
@@ -1162,6 +1158,7 @@ local parser = P{
-- should be safe because this pattern always matches last.
reset_depth = Cmt(Cc("nothing") / "", function (s,i, something)
state.depth = 0
+ warn("reset", "", state.depth, #state.currentindent, i)
return true
end)
,
@@ -1170,20 +1167,21 @@ local parser = P{
-- Comments
--------------------------------------------------------------------------------
- comment_block = V"comment"^1
- * V"end_block"
+ comment_block = V"comment"
+ * V"end_block"^-1
,
comment = V"double_dot" / ""
* (V"block_comment" + V"line_comment")
,
- block_comment = V"eol"
- * Cs(V"indented_lines")
+ block_comment = V"whitespace"^0
+ * Cs((1 - V"eol")^0 * V"eol"
+ * V"indented_lines")
/ rst.block_comment,
line_comment = V"whitespace"^1
- * Cs((1 - V"eol")^0 * V"eol")
+ * C((1 - V"eol")^0 * V"eol")
/ rst.line_comment
,
@@ -1200,84 +1198,74 @@ local parser = P{
warn("idt-f", indent, i)
state.currentindent = indent
return true
- end)
+ end) / ""
* (1 - V"eol")^1
- * V"eol",
+ * V"eol"
+ ,
indented_other = Cmt(V"space"^1, function (s, i, indent)
warn("idt-m", #indent, #state.currentindent, #indent == #state.currentindent, i)
return indent == state.currentindent
- end)
+ end) / ""
* (1 - V"eol")^1
- * V"eol",
+ * V"eol"
+ ,
--------------------------------------------------------------------------------
-- Urls
--------------------------------------------------------------------------------
- uri = V"url_protocol" * V"url_domain" * (V"slash" * V"url_path")^0,
+ uri = V"url_protocol" * V"url_domain" * (V"slash" * V"url_path")^0,
- url_protocol = (P"http" + P"ftp" + P"shttp" + P"sftp") * P"://",
+ url_protocol = (P"http" + P"ftp" + P"shttp" + P"sftp") * P"://",
url_domain_char = 1 - V"dot" - V"spacing" - V"eol" - V"punctuation",
- url_domain = V"url_domain_char"^1 * (V"dot" * V"url_domain_char"^1)^0,
- url_path_char = R("az", "AZ", "09") + S"-_.!~*'()",
- url_path = V"slash" * (V"url_path_char"^1 * V"slash"^-1)^1,
+ url_domain = V"url_domain_char"^1 * (V"dot" * V"url_domain_char"^1)^0,
+ url_path_char = R("az", "AZ", "09") + S"-_.!~*'()",
+ url_path = V"slash" * (V"url_path_char"^1 * V"slash"^-1)^1,
--------------------------------------------------------------------------------
-- Terminal Symbols and Low-Level Elements
--------------------------------------------------------------------------------
- word = (1 - V"punctuation" - V"end_block" - V"spacing" - V"eol")^1, -- TODO : no punctuation (later)
-
- asterisk = P"*",
- double_asterisk = V"asterisk" * V"asterisk",
-
- bareia = P"`",
- double_bareia = V"bareia" * V"bareia",
- escaped_bareia = (Cs(V"backslash") / "" * V"bareia") + 1,
-
- slash = P"/",
- doubleslash = V"slash" * V"slash",
-
- backslash = P"\\",
- bar = P"|",
-
- groupchars = S"()[]{}",
+ asterisk = P"*",
+ backslash = P"\\",
+ bar = P"|",
+ bareia = P"`",
+ slash = P"/",
+ solidus = P"⁄",
+ equals = P"=",
--- Punctuation
-- Some of the following are used for markup as well as for punctuation.
- comma = P",",
- colon = P":",
- double_colon = V"colon" * V"colon",
- escaped_colon = V"backslash" * V"colon",
- dot = P".",
- period = V"dot",
- double_dot = V"dot" * V"dot",
- interpunct = P"·",
- underscore = P"_",
+ apostrophe = P"’" + P"'",
+ comma = P",",
+ colon = P":",
+ dot = P".",
+ interpunct = P"·",
+ semicolon = P";",
+ underscore = P"_",
+ dash = P"-",
+ emdash = P"—",
+ hyphen = P"‐",
+ questionmark = P"?",
+ exclamationmark = P"!",
+ interrobang = P"‽",
+ lsquare = P"[",
+ rsquare = P"]",
+ ellipsis = P"…" + P"...",
+ guillemets = P"«" + P"»",
+ quotationmarks = P"‘" + P"’" + P"“" + P"”",
+
+ period = V"dot",
+ double_dot = V"dot" * V"dot",
+ double_colon = V"colon" * V"colon",
+ escaped_colon = V"backslash" * V"colon",
double_underscore = V"underscore" * V"underscore",
- dash = P"-",
- double_dash = V"dash" * V"dash",
- 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"?",
- exclamationmark = P"!",
- inverted_exclamationmark = P"¡",
- inverted_questionmark = P"¿",
- interrobang = P"‽",
-
- apostrophe = P"’" + P"'",
- --brackets = P"[ ], (",, { }, ⟨ ⟩ )
- lsquare = P"[",
- rsquare = P"]",
- ellipsis = P"…" + P"...",
- guillemets = P"«" + P"»",
- quotationmarks= P"‘" + P"’" + P"“" + P"”",
- solidus= P"⁄",
+ double_dash = V"dash" * V"dash",
+ triple_dash = V"double_dash" * V"dash",
+ attrib_dash = V"triple_dash" + V"double_dash" + V"emdash", -- begins quote attribution blocks
+ dashes = V"dash" + P"‒" + P"–" + V"emdash" + P"―",
+
punctuation = V"apostrophe"
@@ -1299,63 +1287,109 @@ local parser = P{
+ V"underscore"
,
- -- These are treated separately as the might begin a paragraph (sigh!).
- inverted_punctuation = V"inverted_exclamationmark"
- + V"inverted_questionmark",
-
-- End punctuation
- letter = R"az" + R"AZ",
-
- equals = P"=",
-
- space = P" ",
- spaces = V"space"^1,
- whitespace = (P" " + Cs(P"\t") / " " + Cs(S"\v") / " "),
- spacing = V"whitespace"^1,
- blank_line = V"space"^0 * V"eol",
+ letter = R"az" + R"AZ",
+ digit = R"09",
+
+ space = P" ",
+ spaces = V"space"^1,
+ whitespace = (P" " + Cs(P"\t") / " " + Cs(S"\v") / " "),
+ spacing = V"whitespace"^1,
+ blank_line = V"whitespace"^0 * V"eol",
rest_of_line = (1 - V"eol")^1,
- eol = P"\n",
- eof = V"eol"^0 * -P(1),
+ eol = S"\r\n",
+ eof = V"eol"^0 * -P(1),
- end_block = V"blank_line"^1
- + V"eof"
- + (V"whitespace"^0 * V"eol"
- * (V"whitespace"^0 * V"eol")^0 * V"eof")
- ,
+ end_block = V"blank_line"^1 * V"eof"^-1
+ + V"eof"
+ ,
-- diverse markup character sets
- 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
-
- digit = R"09",
- roman_numeral = S"ivxlcdm"^1,
- Roman_numeral = S"IVXLCDM"^1,
+ adornment_char = S[[!"#$%&'()*+,-./:;<=>?@[]^_`{|}~]] + P[[\\]], -- headings
+ bullet_char = S"*+-" + P"•" + P"‣" + P"⁃", -- bullet lists
- inline_delimiter = P"**" + P"``" + S"*`",
- angle_left = P"<",
- angle_right = P">",
- enclosed_open = S[['"([{<]],
- enclosed_close = S[['")]}>]],
+ roman_numeral = S"ivxlcdm"^1,
+ Roman_numeral = S"IVXLCDM"^1,
- gartenzaun = P"#",
+ angle_left = P"<",
+ angle_right = P">",
+ gartenzaun = P"#",
table_intersection = P"+",
- table_hline = V"dash",
- table_vline = V"bar",
+ table_hline = V"dash",
+ table_vline = V"bar",
table_header_hline = P"=",
}
+local file_helpers = { }
+
+function file_helpers.strip_BOM (raw)
+ if raw:match"^\239\187\191" then
+ return raw:sub(4)
+ end
+ return raw
+end
+
+--- Tab expansion: feature request by Philipp A.
+do
+ local shiftwidth = rst.shiftwidth
+ local stringrep = string.rep
+ local position = 1
+
+ local reset_position = function () position = 1 return "\n" end
+ local increment_position = function (c) position = position + 1 return c end
+ local expand_tab = function ()
+ local expand = (shiftwidth - position) % shiftwidth + 1
+ position = position + expand
+ return stringrep(" ", expand)
+ end
+
+ local tab = S"\t\v" / expand_tab
+ local utfchar = utfchar / increment_position
+ local eol = P"\n" / reset_position
+ local p_expand = Cs((tab + eol + utfchar)^1)
+
+ function file_helpers.expandtab (raw)
+ position = 1
+ return p_expand:match(raw)
+ end
+end
+
+--- Spotted by Philipp A.
+function file_helpers.insert_blank (raw)
+ if not raw:find"\n%s$" then
+ return raw .. "\n\n"
+ end
+ return raw
+end
+
+function file_helpers.crlf (raw)
+ if raw:find"\r\n" then
+ return raw:gsub("\r\n", "\n")
+ end
+ return raw
+end
+
local function load_file (name)
f = assert(io.open(name, "r"), "Not a file!")
if not f then return 1 end
local tmp = f:read("*all")
f:close()
- return tmp
+
+ local fh = file_helpers
+ if thirddata.rst.strip_BOM then
+ tmp = fh.strip_BOM(tmp)
+ end
+ if thirddata.rst.crlf then
+ tmp = fh.crlf(tmp)
+ end
+ if thirddata.rst.expandtab then
+ tmp = fh.expandtab(tmp)
+ end
+ return fh.insert_blank(tmp)
end
local function save_file (name, data)
@@ -1368,7 +1402,9 @@ end
local function get_setups (inline)
local optional_setups = optional_setups -- might expect lots of calls
- local setups = [[
+ local setups = ""
+ if not inline then
+ setups = setups .. [[
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~%
%{ Setups }%
@@ -1377,6 +1413,10 @@ local function get_setups (inline)
% General %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+]]
+ end
+
+ setups = setups .. [[
\setupcolors[state=start]
\setupinteraction[state=start,focus=standard,color=darkgreen,contrastcolor=darkgreen]
\setupbodyfontenvironment [default] [em=italic]
@@ -1391,12 +1431,12 @@ local function get_setups (inline)
}
]]
-
for item, _ in next, state.addme do
local f = optional_setups[item]
setups = f and setups .. f() or setups
end
- setups = setups .. [[
+ if not inline then
+ setups = setups .. [[
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -1405,19 +1445,18 @@ local function get_setups (inline)
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+\starttext
]]
- if not inline then
- setups = setups .. "\n\\starttext"
end
return setups
end
-local function main()
- local testdata = load_file(arg[1])
+function thirddata.rst.standalone (infile, outfile)
+ local testdata = load_file(infile)
if testdata == 1 then return 1 end
local processeddata = parser:match(testdata)
- local setups = get_setups()
+ local setups = get_setups(false)
processeddata = setups .. processeddata .. [[
@@ -1433,7 +1472,7 @@ local function main()
]]
if processeddata then
- save_file(arg[2], processeddata)
+ save_file(outfile, processeddata)
else
return 1
end
@@ -1457,11 +1496,46 @@ function thirddata.rst.do_rst_file(fname)
if processed then
processed = strip_comments:match(setups..processed.."\n\\stoptext\n")
- save_file (tmp_file,processed)
+ save_file(tmp_file, processed)
context.input("./"..tmp_file)
end
end
+local rst_inclusions = { }
+local rst_incsetups = { }
+function thirddata.rst.do_rst_inclusion (iname, fname)
+ local rst_parser = parser
+ local raw_data = load_file(fname)
+ local processed = rst_parser:match(raw_data)
+ local setups = get_setups(true)
+
+ local incnr = #rst_incsetups + 1
+ local tmp_file = tex.jobname .. fmt("–rst_inclusion-%d.tex.tmp", incnr)
+
+ if processed then
+ processed = strip_comments:match(processed)
+ save_file(tmp_file, processed)
+ rst_inclusions[iname] = tmp_file
+ rst_incsetups[#rst_incsetups +1] = setups
+ end
+end
+
+function thirddata.rst.do_rst_setups ()
+ local out = table.concat(rst_incsetups)
+ --context(out) --- why doesn’t this work?
+ local tmp_file = tex.jobname .. "–rst_setups.tex.tmp"
+ save_file(tmp_file, out)
+ context.input(tmp_file)
+end
+
+function thirddata.rst.get_rst_inclusion (iname)
+ if rst_inclusions[iname] then
+ context.input(rst_inclusions[iname])
+ else
+ context(fmt("{\\bf File for inclusion “%s” not found.}\par ", iname))
+ end
+end
+
function thirddata.rst.do_rst_snippet(txt)
local processed = parser:match(txt)
local setups = get_setups(true)
@@ -1470,7 +1544,7 @@ function thirddata.rst.do_rst_snippet(txt)
if processed then
warn("·cs·",txt)
processed = strip_comments:match(setups..processed)
- save_file (tmp_file,processed)
+ save_file(tmp_file,processed)
context.input("./"..tmp_file)
else
warn("·cs·",txt)
@@ -1481,7 +1555,24 @@ function thirddata.rst.do_rst_snippet(txt)
end
end
+local usage_info = [[
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ rstConTeXt
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Functionality has been moved, the reST converter can now be
+accessed via mtxrun:
+
+ $mtxrun --script rst
+
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+]]
+
+local function main()
+ iowrite("\n"..usage_info.."\n")
+ return -1
+end
-if not context then
+if not (context or scripts) then
return main()
end
diff --git a/Master/texmf-dist/tex/context/third/rst/rst_setups.lua b/Master/texmf-dist/tex/context/third/rst/rst_setups.lua
index b7bda950976..08f21c526ec 100644
--- a/Master/texmf-dist/tex/context/third/rst/rst_setups.lua
+++ b/Master/texmf-dist/tex/context/third/rst/rst_setups.lua
@@ -4,19 +4,17 @@
-- USAGE: called by rst_parser.lua
-- DESCRIPTION: Complement to the reStructuredText parser
-- AUTHOR: Philipp Gesang (Phg), <megas.kapaneus@gmail.com>
--- CHANGED: 2011-05-08 17:55:37+0200
+-- CHANGED: 2011-08-28 13:47:24+0200
--------------------------------------------------------------------------------
--
---local rst_directives = context and thirddata.rst_directives or require "rst_directives"
local optional_setups = { }
-local rst_directives
-if context then
- thirddata.rst_setups = optional_setups
- rst_directives = thirddata.rst_directives
-else
- rst_directives = require "rst_directives"
-end
+thirddata.rst_setups = optional_setups
+local rst_directives = thirddata.rst_directives
+local rst_context = thirddata.rst
+
+local fmt = string.format
+local stringstrip = string.strip
function optional_setups.footnote_symbol ()
local setup = [[
@@ -45,13 +43,13 @@ function optional_setups.footnotes ()
]]
for nf, note in next, tf.numbered do
- fn = fn .. string.format(buffer, "Autonumbered footnote", "__footnote_number_"..nf, note)
+ fn = fn .. fmt(buffer, "Autonumbered footnote", "__footnote_number_"..nf, note)
end
for nf, note in next, tf.autolabel do
- fn = fn .. string.format(buffer, "Labeled footnote", "__footnote_label_"..nf, note)
+ fn = fn .. fmt(buffer, "Labeled footnote", "__footnote_label_"..nf, note)
end
for nf, note in next, tf.symbol do
- fn = fn .. string.format(buffer, "Symbol footnote", "__footnote_symbol_"..nf, note)
+ fn = fn .. fmt(buffer, "Symbol footnote", "__footnote_symbol_"..nf, note)
end
return fn
end
@@ -98,7 +96,7 @@ function optional_setups.references ()
if arefs[ref_text] then
ref_text = rst_context.anonymous_links[tonumber(arefs[ref_text])]
end
- references[#references+1] = string.format([[
+ references[#references+1] = fmt([[
\useURL[__target_%s] [%s] [] [%s] ]], rst_context.whitespace_to_underscore(ref), urlescape(target), ref_text)
end
end
@@ -128,7 +126,7 @@ function optional_setups.substitutions ()
local rs = rst_context.substitutions
for name, content in next, rs do
local directive, data = content.directive, content.data
- name, data = name:gsub("%s", ""), string.strip(data)
+ name, data = name:gsub("%s", ""), stringstrip(data)
if directives[directive] then
substitutions = substitutions .. directives[directive](name, data)
else
diff --git a/Master/texmf-dist/tex/context/third/rst/t-rst.mkiv b/Master/texmf-dist/tex/context/third/rst/t-rst.mkiv
index 0359335d1bd..35ba054de2a 100644
--- a/Master/texmf-dist/tex/context/third/rst/t-rst.mkiv
+++ b/Master/texmf-dist/tex/context/third/rst/t-rst.mkiv
@@ -112,9 +112,29 @@
%D Thus, the user should never supply any of these manually,
%D neither before nor after \type{\typesetRSTfile}.
%D
+%D We now handle rogue utf-8 byte order marks on demand, just set
+%D the optional parameter \type{stripBOM} to {\em true}.
+%D
+%D There also is an option \type{expandtab} to convert tabs
+%D (ascii 0x09) to indents prior to converting reST input. The
+%D expansion width defaults to {\em 4} and can be configured
+%D through the parameter \type{shiftwidth} (takes an integer).
+%D
%D \showsetup{typesetRSTfile}
-\def\typesetRSTfile#1{\ctxlua{thirddata.rst.do_rst_file("#1")}}
+\def\do_typeset_RST_file[#1]#2{%
+ \iffirstargument
+ \getparameters[RST][#1]%
+ \doifdefined{RSTstripBOM} {\ctxlua{thirddata.rst.strip_BOM = \RSTstripBOM}}%
+ \doifdefined{RSTexpandtab} {\ctxlua{thirddata.rst.expandtab = \RSTexpandtab}}%
+ \doifdefined{RSTshiftwidth}{\ctxlua{thirddata.rst.shiftwidth = \RSTshiftwidth}}%
+ \fi
+ \ctxlua{thirddata.rst.do_rst_file("#2")}%
+}
+
+\def\typesetRSTfile{%
+ \dosingleempty\do_typeset_RST_file%
+}
%D \subsection{Typesetting Inline Snippets}
%D
@@ -158,6 +178,64 @@
\ctxlua{thirddata.rst.do_rst_snippet(\!!bs#1\!!es)}%
}
+%D \subsection{Including multiple reST files}
+%D
+%D \macros
+%D {defineRSTinclusion,startRSTproject,RSTinclusion}
+%D
+%D When content is split among multiple files, these macros allow
+%D for including them in arbitrary order. Note that setups from
+%D previous includes, unless overwritten, will remain defined.
+%D \type{\defineRSTinclusion} takes three arguments: the first one
+%D will be the identifier that can be used to refer to the actual
+%D inclusion, which is specified via the second argument as a
+%D filename. The third optional argument receives the usual
+%D setups \type{stripBOM}, \type{expandtab} and
+%D \type{shiftwidth}.
+%D
+%D Defined inclusions can be typeset only within an the
+%D \type{\startRSTproject} environment using the macro
+%D \type{RSTinclusion}. Between those inclusion all kinds of
+%D \TEX\ code except for \type{\starttext} and \type{\stoptext}
+%D are permitted.
+
+\def\do_define_RST_inclusion[#1][#2][#3]{%
+ \ifthirdargument
+ \getparameters[RST][#3]%
+ \doifdefined{RSTstripBOM} {\ctxlua{thirddata.rst.strip_BOM = \RSTstripBOM}}%
+ \doifdefined{RSTexpandtab} {\ctxlua{thirddata.rst.expandtab = \RSTexpandtab}}%
+ \doifdefined{RSTshiftwidth}{\ctxlua{thirddata.rst.shiftwidth = \RSTshiftwidth}}%
+ \fi
+ \ifsecondargument
+ \ctxlua{thirddata.rst.do_rst_inclusion("#1", "#2")}%
+ \fi%
+}
+
+\def\defineRSTinclusion{%
+ \dotripleempty\do_define_RST_inclusion%
+}
+
+\def\do_RST_inclusion[#1]{%
+ \iffirstargument
+ \ctxlua{thirddata.rst.get_rst_inclusion("#1")}%
+ \fi%
+}
+
+\def\do_RST_setups{%
+ \ctxlua{thirddata.rst.do_rst_setups()}%
+}
+
+\def\startRSTproject{
+ \begingroup
+ \def\RSTinclusion{\dosingleempty\do_RST_inclusion}
+ \do_RST_setups
+ \starttext%
+}
+
+\def\stopRSTproject{
+ \stoptext \endgroup \endinput
+}
+
\protect \endinput
% vim:ft=context:sw=2:ts=2