From ab58cc28266fe58eb6293cca6bf08262eb103719 Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Sun, 31 Mar 2013 23:44:06 +0000 Subject: context-rst (30mar13) git-svn-id: svn://tug.org/texlive/trunk@29575 c570f23f-e606-0410-a88d-b1316a301751 --- Master/texmf-dist/doc/context/third/rst/COPYING | 2 +- Master/texmf-dist/doc/context/third/rst/README.rst | 96 +++++---- .../doc/context/third/rst/documentation.rst | 79 ++++++-- Master/texmf-dist/doc/context/third/rst/manual.pdf | Bin 120193 -> 122205 bytes Master/texmf-dist/doc/context/third/rst/manual.tex | 2 +- .../scripts/context/lua/third/rst/mtx-t-rst.lua | 6 +- .../tex/context/interface/third/t-rst.xml | 2 +- .../tex/context/third/rst/rst_context.lua | 204 ++++++++++++-------- .../tex/context/third/rst/rst_directives.lua | 214 ++++++++++++--------- .../tex/context/third/rst/rst_helpers.lua | 101 ++++++---- .../tex/context/third/rst/rst_parser.lua | 85 ++++---- .../tex/context/third/rst/rst_setups.lua | 84 ++++---- Master/texmf-dist/tex/context/third/rst/t-rst.mkiv | 4 +- 13 files changed, 524 insertions(+), 355 deletions(-) (limited to 'Master') diff --git a/Master/texmf-dist/doc/context/third/rst/COPYING b/Master/texmf-dist/doc/context/third/rst/COPYING index 6d4166538b7..ac0eb7c9fc6 100644 --- a/Master/texmf-dist/doc/context/third/rst/COPYING +++ b/Master/texmf-dist/doc/context/third/rst/COPYING @@ -1,4 +1,4 @@ -Copyright 2010-2012 Philipp Gesang. All rights reserved. +Copyright 2010-2013 Philipp Gesang. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: diff --git a/Master/texmf-dist/doc/context/third/rst/README.rst b/Master/texmf-dist/doc/context/third/rst/README.rst index 8c0e6fd75db..571b8aec104 100644 --- a/Master/texmf-dist/doc/context/third/rst/README.rst +++ b/Master/texmf-dist/doc/context/third/rst/README.rst @@ -1,20 +1,32 @@ -============== -General Advice -============== +======================================================================= + General Advice +======================================================================= Read the section *Features Not Implemented* in the manual first. -*Note*: if you happen to read this on BitBucket_, the error messages some lines -below just mean that *their* implementation doesn’t understand |TeX| directives. -Don’t worry, |rstcontext| does. - -============ -Installation -============ - -In order to install |rstcontext|, copy everything under the ``mod/`` -subdirectory into your local |CONTEXT| tree and update the filename database, -i.e.: :: +*Note*: if you happen to read this on BitBucket_, the error messages +some lines below just mean that *their* implementation doesn’t +understand |TeX| directives. Don’t worry, |rstcontext| does. + +======================================================================= + Installation +======================================================================= +With ConTeXt Standalone +*********************** +An up to date version of the module is installed along with the ConTeXt +distribution (*Standalone*, formerly known as *The Minimals*). +The module should be working out of the box if you installed from the +official source_ and provided the parameter ``--modules=all``. + +.. _source: http://wiki.contextgarden.net/ConTeXt_Standalone#Installing_third_party_modules + +Manually +******** +Firstly, get the module source from BitBucket_ (see the *downloads* +section). +In order to install |rstcontext|, copy everything in the ``mod/`` +subdirectory into your local |CONTEXT| tree and update the filename +database, i.e. :: cp -r mod/* ~/context/tex/texmf-local/ context --generate @@ -22,48 +34,50 @@ i.e.: :: if the |CONTEXT| minimal distribution happens to be installed at ``~/context/``. -===== -Usage -===== +======================================================================= + Usage +======================================================================= -As rstConTeXt was developed on *texlua*, you may expect it to run best with this -interpreter. For now the script accepts two command line arguments: the input -file and the output file. The following will demonstrate the main usage in a -separate directory: :: +As rstConTeXt was developed on *texlua*, you may expect it to run best +with this interpreter. For now the script accepts two command line +arguments: the input file and the output file. The following will +demonstrate the main usage in a separate directory: :: mkdir tmp; cd tmp mtxrun --script rst --if=../mod/doc/context/third/rst/documentation.rst --of=doc.tex context ../mod/doc/context/third/rst/manual.tex -This should have gotten you the manual converted to a file ``doc.tex`` which was -subsequently run through |CONTEXT| to generate the final ``manual.pdf``. You -will find extended instructions on how to build the manual with some cosmetic -improvements in the section *Usage* of the manual itself. +This should have gotten you the manual converted to a file ``doc.tex`` +which was subsequently run through |CONTEXT| to generate the final +``manual.pdf``. You will find extended instructions on how to build the +manual with some cosmetic improvements in the section *Usage* of the +manual itself. -There is also a small module ``t-rst.mkiv`` which permits direct typesetting of -reST markup with |CONTEXT| MkIV. For usage examples see the files -``hybridtest.tex`` and ``moduletest.tex`` in the ``doc`` subdirectory. +There is also a small module ``t-rst.mkiv`` which permits direct +typesetting of reST markup with |CONTEXT| MkIV. For usage examples see +the files ``hybridtest.tex`` and ``moduletest.tex`` in the ``doc`` +subdirectory. -======= -License -======= +======================================================================= + License +======================================================================= -|rstcontext| is free software and may be redistributed under the terms of the -2-clause BSD license. You should have recieved a copy of this license in a file -named “COPYING” in the source tree. If there is no such file then please contact -the maintainer_ (Contact_). +|rstcontext| is free software and may be redistributed under the terms +of the 2-clause BSD license. You should have recieved a copy of this +license in a file named “COPYING” in the source tree. If there is no +such file then please contact the maintainer_ (Contact_). -======= -Contact -======= +======================================================================= + Contact +======================================================================= -|rstcontext| was written by Philipp Gesang, ``phg42.2a`` at ``gmail`` dot -``com`` (find me on BitBucket_). +|rstcontext| was written by Philipp Gesang, ``phg42.2a`` at ``gmail`` +dot ``com``. .. |rstcontext| ctx:: {{\em rst}\kern.5pt\CONTEXT} .. |TeX| ctx:: {\TEX} .. |CONTEXT| ctx:: {\CONTEXT} .. _Contact: phg42.2a@gmail.com -.. _BitBucket: http://bitbucket.org/phg +.. _BitBucket: http://bitbucket.org/phg/context-rst .. _maintainer: Contact_ diff --git a/Master/texmf-dist/doc/context/third/rst/documentation.rst b/Master/texmf-dist/doc/context/third/rst/documentation.rst index 90168a3fa1a..621528de7d7 100644 --- a/Master/texmf-dist/doc/context/third/rst/documentation.rst +++ b/Master/texmf-dist/doc/context/third/rst/documentation.rst @@ -114,20 +114,20 @@ rendering of |rst| input initially, but certain objections diverted me from this path. - *Typography*. It’s all about the details. No matter how good your - converter is, it still won’t reach |TEX|’s omnipotence and - flexibility. |rstcontext| is a tool to generate raw material - for your typesetting job, not a typesetting system in itself. + converter is, auto-generated code will not reach |TEX|’s + omnipotence and flexibility. |rstcontext| is a tool to + generate raw material for your typesetting job, not a + typesetting system in itself. - *Testing*. Never underestimate the insights gained from reading the resulting |CONTEXT| file. Quite some effort has been undertaken to make it human-readable, especially the setups. -- *MkII*. I’m not an MkII user at all save for rapid testing and - the occasional check for the sanity of |CONTEXT|’s behaviour. - Slow hardware forces me to run |PDFTEX| instead of |LUATEX| - whenvever I need some result as quick as possible, so I wanted - to keep the code MkII clean. Do not expect Unicode (as in - this document) to work without precautions. +- *MkII*. I’m not an MkII user at all, and compatibility with + it is not a primary objective for |rstcontext|. + However, an effort has been made to keep the output essentially + MkII clean. Do not expect Unicode to work without + precautions. During the development readability of the generated code was alway one of the main goals of |rstcontext|. Quite some computing @@ -388,6 +388,7 @@ defined it. (The placement parameter to ``placefigure`` will be set to ``here`` by default.) .. image:: cow + cow.pdf width: hsize alt: A generic Dutch cow (*bos primigenius taurus*). @@ -405,14 +406,68 @@ caption text of the image. .. |TEX| ctx:: \TeX .. |PDFTEX| ctx:: \PDFTEX .. |LUATEX| ctx:: \LUATEX -.. |rstcontext| ctx:: {\em rst}\kern.5pt\CONTEXT -.. |rst| ctx:: {\rm re}{\ss Structured}{\rm Text} +.. |rstcontext| ctx:: \bgroup\em rst\egroup\kern.5pt\CONTEXT +.. |rst| ctx:: \bgroup\rm re\egroup\bgroup\ss Structured\egroup\bgroup\rm Text\egroup .. |LATEX| ctx:: \LATEX .. _outline: http://docutils.sourceforge.net/docs/ref/rst/restructuredtext.html .. _docutils: http://docutils.sourceforge.net/ .. _Pandoc: http://johnmacfarlane.net/pandoc/ +Containers +********** + +Upon request |rstcontext| now supports another kind of +directive, namely containers_. +Due to their being defined explicitly in terms of HTML, +*containers* lack a corresponding construct in |CONTEXT| (or +|TEX| for that matter). +Some parts of |CONTEXT| (e. g. ``\\framed``) come quite close with +respect to functionality as well as generality. +However, none of the candidates alone covers the entire spectrum +of functionality that containers_ are supposed to. +For that reason the implementation leaves them essentially +undefined. + +If an explicit name is specified, then the ``container`` +directive maps to the environment of that name. +Anonymous containers are interpreted as a |TEX| group. +Any text block inside the element is treated as ordinary +paragraph. +In below example the content will be handled as if between +``\\startxyzzy`` and ``\\stopxyzzy``, where it is up to the user to +define the *xyzzy* environment:: + + This is a paragraph. + + .. container:: xyzzy + + whatever + + foo **bar** baz + + This is another paragraph. + +The middle part translates to |CONTEXT| as follows:: + + \start[xyzzy]% + whatever + + foo {\sc bar} baz + \stop + +Note that the ``\\start[foo]``/``\\stop``-environment is equivalent +to ``\\startfoo``/``\\stopfoo``, except that the environment +doesn’t actually need to be defined. + +.. caution:: + Support for the *container* directive is considered + experimental. + Suggestions for improving or extending the current + implementation are always welcome. + +.. _containers: http://docutils.sourceforge.net/docs/ref/rst/directives.html#container + ======================= Substitution Directives ======================= @@ -603,7 +658,7 @@ License :: - Copyright 2010-2011 Philipp Gesang. All rights reserved. + Copyright 2010-2013 Philipp Gesang. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the diff --git a/Master/texmf-dist/doc/context/third/rst/manual.pdf b/Master/texmf-dist/doc/context/third/rst/manual.pdf index 60e26dd060b..4150a13def1 100644 Binary files a/Master/texmf-dist/doc/context/third/rst/manual.pdf and b/Master/texmf-dist/doc/context/third/rst/manual.pdf differ diff --git a/Master/texmf-dist/doc/context/third/rst/manual.tex b/Master/texmf-dist/doc/context/third/rst/manual.tex index cbb0382d968..b3d63db6989 100644 --- a/Master/texmf-dist/doc/context/third/rst/manual.tex +++ b/Master/texmf-dist/doc/context/third/rst/manual.tex @@ -53,7 +53,7 @@ \vfill \framed [align=right,frame=off,topframe=on] {% \tfxx\ss\setupinterlinespace[small]\noindentation -Copyright 2010--2012 by Philipp Gesang, Heidelberg.\par +Copyright 2010--2013 Philipp Gesang, Radebeul.\par Mail any bug reports, patches or suggestions to\par \type{string.format("%s@%s.com", "phg42.2a", "gmail")}\par or pay a visit to \goto{my BitBucket home}[url(http://bitbucket.org/phg/)].\par diff --git a/Master/texmf-dist/scripts/context/lua/third/rst/mtx-t-rst.lua b/Master/texmf-dist/scripts/context/lua/third/rst/mtx-t-rst.lua index 08782a9a8d3..6735b1dd7b4 100644 --- a/Master/texmf-dist/scripts/context/lua/third/rst/mtx-t-rst.lua +++ b/Master/texmf-dist/scripts/context/lua/third/rst/mtx-t-rst.lua @@ -5,7 +5,7 @@ -- DESCRIPTION: context script interface for the reStructuredText module -- REQUIREMENTS: latest ConTeXt MkIV -- AUTHOR: Philipp Gesang (Phg), --- CREATED: 2011-08-28 12:43:49+0200 +-- CHANGED: 2013-03-27 00:25:32+0100 -------------------------------------------------------------------------------- -- @@ -14,12 +14,12 @@ scripts.rst = { } environment.loadluafile("rst_parser") -local ea = environment.argument +local ea = environment.argument local helpinfo = [[ =============================================================== The reStructuredText module, command line interface. - © 2010--2011 Philipp Gesang. License: 2-clause BSD. + © 2010--2013 Philipp Gesang. License: 2-clause BSD. Home: =============================================================== 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 40015e26586..68dcc1baf93 100644 --- a/Master/texmf-dist/tex/context/interface/third/t-rst.xml +++ b/Master/texmf-dist/tex/context/interface/third/t-rst.xml @@ -3,7 +3,7 @@ + version="0.6; 2013-03-27 00:26:22+0100"> 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 e7637b3bf52..7d0f2b86ace 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), --- CHANGED: 2012-06-05 22:18:11+0200 +-- CHANGED: 2013-03-26 22:46:17+0100 -------------------------------------------------------------------------------- -- --- TODO @@ -18,16 +18,21 @@ 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 utflen = utf.len -local utflower = utf.lower -local utfupper = utf.upper -local iowrite = io.write +local utf = unicode.utf8 +local utflen = utf.len +local utflower = utf.lower +local utfupper = utf.upper +local iowrite = io.write +local tableconcat = table.concat + +local stringmatch = string.match +local stringgmatch = string.gmatch +local stringgsub = string.gsub local dbg_write = helpers.dbg_writef local C, Cb, Cc, Cg, Cmt, Cp, - Cs, Ct, P, R, S, V, match + Cs, Ct, P, R, S, V, lpegmatch = 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 @@ -41,7 +46,7 @@ do escaped = P"\\" * V"space" } function string.strip(str) - return stripper:match(str) or "" + return lpegmatch(stripper, str) or "" end end local stringstrip = string.strip @@ -72,13 +77,14 @@ rst_context.current_footnote_number = 0 rst_context.current_symbolnote_number = 0 function rst_context.addsetups(item) + local state = thirddata.rst.state state.addme[item] = state.addme[item] or true return 0 end function rst_context.footnote_reference (label) - local tf = state.footnotes - if label:match("^%d+$") then -- all digits + local tf = thirddata.rst.state.footnotes + if stringmatch(label, "^%d+$") then -- all digits local c = tonumber(label) return [[\\footnote{\\getbuffer[__footnote_number_]].. c .."]}" elseif label == "#" then --autonumber @@ -86,8 +92,8 @@ function rst_context.footnote_reference (label) rc = rc + 1 rst_context.current_footnote_number = rc return [[\\footnote{\\getbuffer[__footnote_number_]].. rc .."]}" - elseif label:match("^#.+$") then - local thelabel = label:match("^#(.+)$") + elseif stringmatch(label, "^#.+$") then + local thelabel = stringmatch(label, "^#(.+)$") return [[\\footnote{\\getbuffer[__footnote_label_]].. thelabel .."]}" elseif label == "*" then local rc = rst_context.current_symbolnote_number @@ -104,7 +110,7 @@ do local w = S" \v\t\n" / "_" local wp = Cs((w + 1)^1) function rst_context.whitespace_to_underscore(str) - return str and wp:match(str) or "" + return str and lpegmatch(wp, str) or "" end end @@ -163,9 +169,9 @@ end rst_context.roles.color = function(color, str) local p = helpers.patterns - local definition = color:match("^color_(.+)$") - if definition:match("^rgb_") then -- assume rgb - local rgb = p.rgbvalues:match(definition) + local definition = stringmatch(color, "^color_(.+)$") + if stringmatch(definition, "^rgb_") then -- assume rgb + local rgb = lpegmatch(p.rgbvalues, definition) definition = stringformat([[r=%s,g=%s,b=%s]], rgb[1], rgb[2], rgb[3]) end return stringformat([[\\colored[%s]{%s}]], definition, str) @@ -254,14 +260,14 @@ end function rst_context.interpreted_text (...) local tab = { ... } local role, str - role = tab[1]:match("^:(.*):$") or tab[3]:match("^:(.*):$") + role = stringmatch(tab[1], "^:(.*):$") or stringmatch(tab[3], "^:(.*):$") str = tab[2] if not role then -- implicit role role = "emphasis" end - if role:match("^color_") then + if stringmatch(role, "^color_") then return rst_context.roles.color(role, str) end @@ -275,14 +281,14 @@ end function rst_context.reference (str) rst_context.addsetups("references") - str = str:match("^`?([^`]+)`?_$") -- LPEG could render this gibberish legible but not time + str = stringmatch(str, "^`?([^`]+)`?_$") return [[\\RSTchoosegoto{__target_]] .. rst_context.whitespace_to_underscore(str) .. "}{" .. str .. "}" end function rst_context.anon_reference (str) rst_context.addsetups("references") - str = str:match("^`?([^`]+)`?__$") + str = stringmatch(str, "^`?([^`]+)`?__$") rst_context.anonymous_links[#rst_context.anonymous_links+1] = str link = "__target_anon_" .. #rst_context.anonymous_links return stringformat([[\\RSTchoosegoto{%s}{%s}]], link, str) @@ -318,7 +324,11 @@ function rst_context.target (tab) local anon = create_anonymous() id, arefs[anon[1]] = anon[1], anon[2] else - id = tab[i]:gsub("\\:",":"):match("`?([^`]+)`?") -- deescaping + local tmp = tab[i] + tmp = stringgsub(tmp, "\\:",":") + tmp = stringmatch(tmp, "`?([^`]+)`?") + id = tmp + --id = tab[i]:gsub("\\:",":"):match("`?([^`]+)`?") -- deescaping end if id then refs[id] = refs[id] or target @@ -374,13 +384,13 @@ do } function rst_context.escape (str) - str = str:gsub("\\(.)", "%1") - return p_escape:match(str) + str = stringgsub(str, "\\(.)", "%1") + return lpegmatch(p_escape, str) end end function rst_context.joinindented (tab) - return table.concat (tab, "") + return tableconcat (tab, "") end local corresponding = { @@ -639,8 +649,15 @@ function rst_context.paragraph (data) if not data then return "" elseif type(data) == "table" then - str = #data > 1 and helpers.string.wrapat(inline_parser:match(table.concat(data, " ")), 65) - or inline_parser:match(data[1]) +-- str = #data > 1 and helpers.string.wrapat(lpegmatch(inline_parser, tableconcat(data, " ")), 65) +-- or inline_parser:match(data[1]) + if #data > 1 then + str = helpers.string.wrapat( + lpegmatch(inline_parser, tableconcat(data, " ")) + , 65) + else + str = lpegmatch(inline_parser, data[1]) + end else str = data end @@ -672,12 +689,10 @@ function rst_context.section (...) -- TODO general cleanup; move validity 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 = stringstrip(tab[2]) else -- no overline adornchar = tab[2]:sub(1,1) section = ulen(tab[1]) <= ulen(tab[2]) - --section = get_line_pattern(adornchar):match(tab[2]) ~= nil and section str = tab[1] end @@ -723,7 +738,7 @@ do nospace = V"escaped" + (1 - V"space"), } function stringstrip(str) - return stripper:match(str) or "" + return lpegmatch(stripper, str) or "" end end @@ -751,26 +766,25 @@ local itemstripper = stripme^0 * C(dontstrip^1) * stripme^0 local function parse_itemstring(str) local offset = nil local setup = ",fit][itemalign=flushright," - -- string.match is slightly faster than string.find - if str:match("^%(") then + if stringmatch(str, "^%(") then setup = setup .. [[left=(,]] end - if str:match("%)$") then + if stringmatch(str, "%)$") then setup = setup .. [[right=)]] end - if str:match("%.$") then + if stringmatch(str, "%.$") then setup = setup .. [[stopper={.\\space}]] end - local num = str:match("^%d") + local num = stringmatch(str, "^%d") if num then -- http://thread.gmane.org/gmane.comp.tex.context/61728/focus=61729 setup = setup .. ",start=" .. num str = "n" end - str = itemstripper:match(str) + str = lpegmatch(itemstripper, str) str = enumeration_types[str] or str - return {setup = setup, str = str} + return { setup = setup, str = str } end function rst_context.startitemize(str) @@ -826,7 +840,7 @@ function rst_context.bullet_item (tab) return result .. [[ -\\item ]] .. inline_parser:match(content) .. [[ +\\item ]] .. lpegmatch(inline_parser, content) .. [[ ]] end @@ -842,7 +856,8 @@ function rst_context.deflist (list) local deflist = [[ \\startRSTdefinitionlist ]] - for nd, item in ipairs(list) do + for nd=1, #list do + local item = list[nd] local term = item[1] local nc = 2 local tmp = [[ @@ -860,10 +875,12 @@ function rst_context.deflist (list) \\RSTdeflistdefinition{% ]] - for np, par in ipairs(item[#item]) do -- definitions, multi-paragraph + local final = item[#item] + for np=1, #final do + local par = final[np] tmp = tmp .. [[ \\RSTdeflistparagraph{% -]] .. inline_parser:match(par) .. "}\n" +]] .. lpegmatch(inline_parser, par) .. "}\n" end tmp = tmp .. " }" deflist = deflist .. tmp @@ -895,7 +912,7 @@ function rst_context.field_name (str) end function rst_context.field_body (str) - return [[\\fieldbody{]] .. inline_parser:match(str) .. [[}]] + return [[\\fieldbody{]] .. lpegmatch(inline_parser, str) .. [[}]] end function rst_context.field (tab) @@ -904,7 +921,7 @@ function rst_context.field (tab) \\RSTfieldname{%s} \\RSTfieldbody{%s} -]], name, inline_parser:match(body)) +]], name, lpegmatch(inline_parser, body)) end function rst_context.line_comment (str) @@ -932,7 +949,7 @@ function rst_context.option_list (str) \\eTR \\eTABLEhead \\bTABLEbody -]] .. inline_parser:match(str) .. [[ +]] .. lpegmatch(inline_parser, str) .. [[ \\eTABLEbody \\eTABLE @@ -950,11 +967,10 @@ end function rst_context.literal_block (str, included) local indent = P" "^1 - --local stripme = indent:match(str) or 0 local stripme = #str - for line in str:gmatch("[^\n]+") do + for line in stringgmatch(str, "[^\n]+") do -- setting to the lowest indend of all lines - local idt = indent:match(line) + local idt = lpegmatch(indent, line) if line and idt then stripme = idt < stripme and idt or stripme end @@ -971,7 +987,7 @@ function rst_context.literal_block (str, included) end, } - str = strip:match(str) + str = lpegmatch(strip, str) str = [[ \starttyping[lines=hyphenated] @@ -994,7 +1010,7 @@ function rst_context.line_block (str) return [[ \\startlines -]] .. inline_parser:match(str) .. [[\\stoplines +]] .. lpegmatch(inline_parser, str) .. [[\\stoplines ]] end @@ -1013,7 +1029,7 @@ function rst_context.block_quote (tab) \\startlinecorrection \\blank[small] \\startblockquote -]] .. inline_parser:match(tab[1]) .. [[ +]] .. lpegmatch(inline_parser, tab[1]) .. [[ \\stopblockquote ]] @@ -1021,7 +1037,7 @@ function rst_context.block_quote (tab) return tab[2] and str .. [[ \\blank[small] \\startattribution -]] .. inline_parser:match(tab[2]) .. [[ +]] .. lpegmatch(inline_parser, tab[2]) .. [[ \\stopattribution \\blank[small] \\stoplinecorrection @@ -1054,9 +1070,9 @@ function rst_context.grid_table (tab) ]] while nr <= tab.head_end do local r = tab.rows[nr] - --for i,r in ipairs(tab.rows) do local isempty = true - for n, cell in ipairs(r) do + for n=1, #r do + local cell = r[n] if cell.variant == "normal" then isempty = false break @@ -1065,10 +1081,11 @@ function rst_context.grid_table (tab) if not isempty then local row = [[\\bTR]] - for n,c in ipairs(r) do + for n=1, #r do + local c = r[n] if not (c.parent or c.variant == "separator") then - local celltext = inline_parser:match(c.stripped) + local celltext = lpegmatch(inline_parser, c.stripped) if c.span.x or c.span.y then local span_exp = "[" if c.span.x then @@ -1103,9 +1120,9 @@ function rst_context.grid_table (tab) end while nr <= #tab.rows do local r = tab.rows[nr] - --for i,r in ipairs(tab.rows) do local isempty = true - for n, cell in ipairs(r) do + for n=1, #r do + local cell = r[n] if cell.variant == "normal" then isempty = false break @@ -1114,10 +1131,11 @@ function rst_context.grid_table (tab) if not isempty then local row = [[\\bTR]] - for n,c in ipairs(r) do + for n=1, #r do + local c = r[n] if not (c.parent or c.variant == "separator") then - local celltext = inline_parser:match(c.stripped) + local celltext = lpegmatch(inline_parser, c.stripped) if c.span.x or c.span.y then local span_exp = "[" if c.span.x then @@ -1162,9 +1180,10 @@ function rst_context.simple_table(tab) if not row.ignore then dbg_write(">hr>" .. #row) head = head .. [[\\bTR]] - for nc,cell in ipairs(row) do + for nc=1, #row do + local cell = row[nc] dbg_write("%7s | ", cell.content) - local celltext = inline_parser:match(cell.content) + local celltext = lpegmatch(inline_parser, cell.content) if cell.span then head = head .. stringformat([=[\\bTH[nc=%s]%s\\eTH]=], cell.span.x, celltext or "") else @@ -1201,9 +1220,10 @@ function rst_context.simple_table(tab) if not row.ignore then dbg_write(">tr>" .. #row) body = body .. [[\\bTR]] - for nc,cell in ipairs(row) do + for nc=1, #row do + local cell = row[nc] dbg_write("%7s | ", cell.content) - local celltext = inline_parser:match(cell.content) + local celltext = lpegmatch(inline_parser, cell.content) if cell.span then body = body .. stringformat([=[\\bTC[nc=%s]%s\\eTC]=], cell.span.x, celltext or "") else @@ -1219,45 +1239,65 @@ function rst_context.simple_table(tab) end function rst_context.footnote (label, content) - local tf = state.footnotes + local tf = thirddata.rst.state.footnotes rst_context.addsetups("footnotes") - if label:match("^%d+$") then -- all digits - tf.numbered[tonumber(label)] = rst_context.escape(inline_parser:match(content)) + if stringmatch(label, "^%d+$") then -- all digits + tf.numbered[tonumber(label)] = + rst_context.escape(lpegmatch(inline_parser, content)) elseif label == "#" then --autonumber repeat -- until next unrequested number tf.autonumber = tf.autonumber + 1 until tf.numbered[tf.autonumber] == nil - tf.numbered[tf.autonumber] = rst_context.escape(inline_parser:match(content)) - elseif label:match("^#.+$") then - local thelabel = label:match("^#(.+)$") - tf.autolabel[thelabel] = rst_context.escape(inline_parser:match(content)) + tf.numbered[tf.autonumber] = + rst_context.escape(lpegmatch(inline_parser, content)) + elseif stringmatch(label, "^#.+$") then + local thelabel = stringmatch(label, "^#(.+)$") + tf.autolabel[thelabel] = + rst_context.escape(lpegmatch(inline_parser, content)) elseif label == "*" then rst_context.addsetups("footnote_symbol") - tf.symbol[#tf.symbol+1] = rst_context.escape(inline_parser:match(content)) + tf.symbol[#tf.symbol+1] = + rst_context.escape(lpegmatch(inline_parser, content)) else -- “citation reference” treated like ordinary footnote repeat -- until next unrequested number tf.autonumber = tf.autonumber + 1 until tf.numbered[tf.autonumber] == nil - tf.numbered[tf.autonumber] = rst_context.escape(inline_parser:match(content)) + tf.numbered[tf.autonumber] = + rst_context.escape(lpegmatch(inline_parser, content)) end return "" end function rst_context.substitution_definition (subtext, directive, data) - data = table.concat(data, "\n") - local rs = rst_context.substitutions - rs[subtext] = { directive = directive, data = data } + local tmp + if data.first ~= "" then + tmp = { data.first } + else + tmp = { } + end + data.first = nil + for i=1, #data do -- paragraphs + local current = tableconcat(data[i], "\n") + --current = lpegmatch(inline_parser, current) + --current = rst_context.escape(current) + tmp[#tmp+1] = current + end + data = tableconcat(tmp, "\n\n") + rst_context.substitutions[subtext] = { directive = directive, + data = data } return "" end -- not to be confused with the directive definition table rst_directives -function rst_context.directive(directive, ...) - local rd = rst_directives - rst_context.addsetups("directive") - local data = {...} - local result = "" - if rd[directive] then - result = rd[directive](data) +function rst_context.directive(directive, data) + local fun = rst_directives[directive] + if fun then + rst_context.addsetups("directive") + local result = "" + result = fun(data) + return result end - return result + return "" end + +-- vim:ft=lua:sw=4:ts=4:expandtab 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 78b184c91a4..374f942c0b1 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), --- CHANGED: 2012-06-05 22:17:51+0200 +-- CHANGED: 2013-03-26 22:45:45+0100 -------------------------------------------------------------------------------- -- @@ -18,10 +18,14 @@ local rst_directives = { } thirddata.rst_directives = rst_directives local rst_context = thirddata.rst -local stringstrip = string.strip -local stringformat = string.format +local lpegmatch = lpeg.match +local stringformat = string.format +local stringstrip = string.strip +local tableconcat = table.concat +local tableflattened = table.flattened +local type = type -rst_directives.anonymous = 0 +--rst_directives.anonymous = 0 rst_directives.images = {} rst_directives.images.done = {} rst_directives.images.values = {} @@ -50,13 +54,14 @@ rst_directives.images.values.width = { } -- we won't allow passing arbitrary setups to context -rst_directives.images.permitted_setups = { - "width", "scale" +local permitted_setups = { + "width", + "scale" } local function img_setup (properties) local result = "" - for _, prop in next, rst_directives.images.permitted_setups do + for _, prop in next, permitted_setups do if properties[prop] then result = result .. prop .. "=" .. properties[prop] .. "," end @@ -67,120 +72,108 @@ local function img_setup (properties) return result end -rst_directives.image = function(name, data) +rst_directives.image = function(data) local inline_parser = rst_context.inline_parser - local properties = {} - local anon = false - local rd = rst_directives - if not data then -- this makes the “name” argument optional - data = name - rd.anonymous = rd.anonymous + 1 - anon = true -- indicates a nameless picture - name = "anonymous" .. rd.anonymous - end + local properties = {} + local anon = false + local rdi = rst_directives.images + local hp = helpers.patterns + + local name = stringstrip(data.name) + + --rd.anonymous = rd.anonymous + 1 + --anon = true -- indicates a nameless picture + --name = "anonymous" .. rd.anonymous + properties.caption = name - --properties.width = "\\local" - - local processed = "" -- stub; TODO do something useful with optional dimension specifications - if type(data) == "table" then -- should always be true - local p = helpers.patterns - for _, str in ipairs(data) do - local key, val - key, val = p.colon_keyval:match(str) - local rdi = rst_directives.images - if key and val then - key = rdi.keys[key] -- sanitize key expression - if type(rdi.values[key]) == "table" then - val = rdi.values[key][val] - elseif type(rdi.values[key]) == "function" then - val = rdi.values[key](val) - end - properties[key] = val - else - processed = processed .. (str and str ~= "" and stringstrip(str)) + data = tableflattened(data) + + for i=1, #data do + local str = data[i] + local key, val = lpegmatch(hp.colon_keyval, str) + if key and val then + key = rdi.keys[key] -- sanitize key expression + local valtype = type(rdi.values[key]) + if valtype == "table" then + val = rdi.values[key][val] + elseif valtype == "function" then + val = rdi.values[key](val) end + properties[key] = val end end properties.setup = img_setup(properties) or "" - data = processed - processed = nil local img = "" - local images_done = rd.images.done - if not anon then - if not images_done[name] then - img = img .. stringformat([[ - -\useexternalfigure[%s][%s][] -]], name, data) - images_done[name] = true - end - img = img .. stringformat([[ -\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 .. stringformat([[ +-- local images_done = rdi.done +-- if not anon then -- TODO: implement? +-- if not images_done[name] then +-- img = img .. stringformat([[ +-- +--\useexternalfigure[%s][%s][]%% +--]], name, data) +-- images_done[name] = true +-- end +-- img = img .. stringformat([[ +--\def\RSTsubstitution%s{%% +-- \placefigure[here]{%s}{\externalfigure[%s]%s}%% +--} +--]], name, rst_context.escape(lpegmatch(inline_parser, properties.caption)), name, properties.setup) +-- else -- image won't be referenced but used instantly + img = stringformat([[ \placefigure[here]{%s}{\externalfigure[%s]%s} -]], rst_context.escape(inline_parser:match(properties.caption)), data, properties.setup) - end +]], rst_context.escape(lpegmatch(inline_parser, properties.caption)), + name, + properties.setup) +-- end return img end -rst_directives.caution = function(raw) +rst_directives.caution = function(data) local inline_parser = rst_context.inline_parser rst_context.addsetups("dbend") rst_context.addsetups("caution") - local text - local first = true - for _, line in ipairs(raw) do - if not helpers.patterns.spacesonly:match(line) then - if first then - text = line - first = false - else - text = text .. " " .. line - end - end + local text = { } + for i=1, #data do -- paragraphs + local current = tableconcat(data[i], "\n") + current = lpegmatch(inline_parser, current) + current = rst_context.escape(current) + text[i] = current end - text = rst_context.escape(helpers.string.wrapat(inline_parser:match(text))) return stringformat([[ \startRSTcaution %s \stopRSTcaution -]], text) +]], tableconcat(text, "\n\n")) end -rst_directives.danger = function(raw) +rst_directives.danger = function(data) local inline_parser = rst_context.inline_parser rst_context.addsetups("dbend") rst_context.addsetups("danger") - local text - local first = true - for _, line in ipairs(raw) do - if not helpers.patterns.spacesonly:match(line) then - if first then - text = line - first = false - else - text = text .. " " .. line - end - end + local text = { } + for i=1, #data do -- paragraphs + local current = tableconcat(data[i], "\n") + current = lpegmatch(inline_parser, current) + current = rst_context.escape(current) + text[i] = current end - text = rst_context.escape(helpers.string.wrapat(inline_parser:match(text))) return stringformat([[ \startRSTdanger %s \stopRSTdanger -]], text) +]], tableconcat(text, "\n\n")) end -- http://docutils.sourceforge.net/docs/ref/rst/directives.html -rst_directives.DANGER = function(addendum) - local result = "" - for _,str in ipairs(addendum) do - result = result .. (stringstrip(str)) +rst_directives.DANGER = function(data) + local inline_parser = rst_context.inline_parser + local text = { } + for i=1, #data do -- paragraphs + local current = tableconcat(data[i], "\n") + current = lpegmatch(inline_parser, current) + current = rst_context.escape(current) + text[i] = current end return stringformat([[ @@ -209,7 +202,7 @@ rst_directives.DANGER = function(addendum) } \blank[force,big] \stoplinecorrection -]], result) +]], tableconcat(text, "\n\n")) end rst_directives.mp = function(name, data) @@ -232,7 +225,7 @@ end rst_directives.ctx = function(name, data) local ctx = stringformat([[ -\startbuffer[%s]%% +\startbuffer[%s] %s\stopbuffer \def\RSTsubstitution%s{%% \getbuffer[%s]\removeunwantedspaces%% @@ -244,7 +237,7 @@ end rst_directives.lua = function(name, data) local luacode = stringformat([[ -\startbuffer[%s]%% +\startbuffer[%s] \startluacode %s \stopluacode @@ -264,7 +257,7 @@ rst_directives.math = function (name, data) data = data or name local formula if type(data) == "table" then - local last, i = table.maxn(data), 1 + local last, i = #data, 1 while i <= last do local line = stringstrip(data[i]) if line and line ~= "" then @@ -291,3 +284,40 @@ rst_directives.replace = function(name, data) ]], name, data) end +-------------------------------------------------------------------------------- +--- Containers. +-------------------------------------------------------------------------------- + +--- *data*: +--- { [1] -> directive name, +--- [>1] -> paragraphs } + +rst_directives.container = function(data) + local inline_parser = rst_context.inline_parser + local tmp = { } + for i=1, #data do -- paragraphs + local current = tableconcat(data[i], "\n") + current = lpegmatch(inline_parser, current) + current = rst_context.escape(current) + tmp[i] = current + end + local content = tableconcat(tmp, "\n\n") + local name = data.name + if name and name ~= "" then + name = stringstrip(data.name) + return stringformat([[ +\start[%s]%% +%s%% +\stop +]], name, content) + else + return stringformat([[ +\begingroup%% +%s%% +\endgroup +]], content) + end +end + +-- vim:ft=lua:sw=4:ts=4:expandtab + 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 e90a55a857a..97d4dd78ae9 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,11 @@ -- USAGE: called by rst_parser.lua -- DESCRIPTION: Complement to the reStructuredText parser -- AUTHOR: Philipp Gesang (Phg), --- CHANGED: 2012-06-05 22:17:31+0200 +-- CHANGED: 2013-03-26 23:55:04+0100 -------------------------------------------------------------------------------- -- -local P, R, S, V, match +local P, R, S, V, lpegmatch = lpeg.P, lpeg.R, lpeg.S, lpeg.V, lpeg.match local C, Carg, Cb, Cc, Cg, @@ -58,8 +58,8 @@ do p.col_start = Cp() * p.dash_or_equals^1 p.col_stop = p.dash_or_equals^1 * Cp() - p.column_starts = p.col_start * ( p.space^1 * p.col_start)^1 - p.column_stops = p.col_stop * ( p.space^1 * p.col_stop)^1 + p.column_starts = Ct(p.col_start * ( p.space^1 * p.col_start)^1) + p.column_stops = Ct(p.col_stop * ( p.space^1 * p.col_stop)^1) p.st_headsep = p.equals^1 * (p.space^1 * p.equals^1)^1 p.st_colspan = p.dash^1 * (p.space^1 * p.dash^1)^0 * p.space^0 * p.last @@ -159,7 +159,9 @@ local function set_layout (line) layout.widths = {} layout.slices = {} - for n, elm in ipairs(slice:match(line)) do + local elms = lpegmatch(slice, line) + for n=1, #elms do + local elm = elms[n] layout.widths[n] = #elm layout.slices[n] = elm end @@ -187,7 +189,8 @@ function helpers.table.create(raw) local hc = helpers.cell local rowcount = 0 local newtablayout = newtab.layout - for nr, row in ipairs(raw) do + for nr=1, #raw do + local row = raw[nr] newtab.rows[nr] = {} local this_row = newtab.rows[nr] this_row.sepline = p.sep_line:match(row) @@ -244,11 +247,13 @@ function helpers.table.create(raw) local oldrows = newtab.rows local newrows = oldrows - for nc, width in ipairs(newtablayout.widths) do + for nc=1, #newtablayout.widths do + local width = newtablayout.widths[nc] -- this is gonna be extremely slow but at least it's readable local newrow local currentrow = 1 - for nr, row in ipairs(newrows) do + for nr=1, #newrows do + local row = newrows[nr] local cell = row[nc] dbg_write("nc: %s, nr:%2s | %9s | ", nc, nr,cell.variant) if row.sepline or row.sephead @@ -300,18 +305,22 @@ function helpers.table.create(raw) newtab.__init() - --newtab.__draw_debug = function() - --for nr, row in ipairs(newtab.rows) do - --for nc, cell in ipairs(row) do - --local field = cell.variant:sub(1,7) - --if cell.parent then - --field = field .. string.format(" %s,%2s",cell.parent.x, cell.parent.y) - --end - --dbg_write("%12s | ", field) - --end - --dbg_write("\n") - --end - --end +--[[ + newtab.__draw_debug = function() + for nr=1, #newtab.rows do + local row = newtab.rows[nr] + for nc=1, #row do + local cell = row[nc] + local field = cell.variant:sub(1,7) + if cell.parent then + field = field .. string.format(" %s,%2s",cell.parent.x, cell.parent.y) + end + dbg_write("%12s | ", field) + end + dbg_write("\n") + end + end +--]] return newtab end @@ -330,13 +339,20 @@ end -- Check the column boundaries of a simple table. function helpers.get_st_boundaries (str) - local p = helpers.patterns - local starts, stops, slices = {}, {}, {} - for n, elm in ipairs({ p.column_starts:match(str) }) do + local p_column_starts = helpers.patterns.column_starts + local p_column_stops = helpers.patterns.column_stops + local starts, stops, slices, elms = { }, { }, { }, nil + + elms = lpegmatch(p_column_starts, str) + for n=1, #elms do + local elm = elms[n] slices[n] = { start = elm } starts[elm] = true end - for n, elm in ipairs({ p.column_stops :match(str) }) do + + elms = lpegmatch(p_column_stops, str) + for n=1, #elms do + local elm = elms[n] slices[n]["stop"] = elm stops[elm] = true end @@ -349,9 +365,9 @@ function helpers.table.simple(raw) local bounds = helpers.get_st_boundaries(raw[1]) local p = helpers.patterns - for nr, row in ipairs(raw) do + for nr=1, #raw do + local row = raw[nr] local newrow = {} - local nc = 1 if not p.st_headsep:match(row) and not p.st_colspan:match(row) then local starts, stops = {}, {} @@ -361,13 +377,15 @@ function helpers.table.simple(raw) stops = p.st_span_stops :match(raw[nr+1]) check_span = true else - for colnr, slice in ipairs(bounds.slices) do - starts[colnr] = slice.start - stops [colnr] = slice.stop + for ncol=1, #bounds.slices do + local slice = bounds.slices[ncol] + starts[ncol] = slice.start + stops [ncol] = slice.stop end end - for nc, start in ipairs(starts) do + for nc=1, #starts do + local start = starts[nc] -- last column can exceed layout width local stop = nc ~= #starts and stops[nc] or #row local cell = { @@ -377,18 +395,19 @@ function helpers.table.simple(raw) cell.content = stringstrip(row:sub(start, stop)) if check_span then local start_at, stop_at - for colnr, slice in ipairs(bounds.slices) do + for ncol=1, #bounds.slices do + local slice = bounds.slices[ncol] if slice.start == start then - start_at = colnr + start_at = ncol end if start_at and - not (colnr == #bounds.slices) then + not (ncol == #bounds.slices) then if slice.stop == stop then - stop_at = colnr + stop_at = ncol break end else -- last column, width doesn't matter - stop_at = colnr + stop_at = ncol end end cell.span.x = 1 + stop_at - start_at @@ -408,10 +427,12 @@ function helpers.table.simple(raw) rows[nr] = newrow end - for nr, row in ipairs(rows) do + for nr=1, #rows do + local row = rows[nr] if not row.ignore and row[1].content == "" then row.ignore = true - for nc, cell in ipairs(row) do + for nc=1, #row do + local cell = row[nc] local par_row, par_col = helpers.table.resolve_parent(nr - 1, nc, rows) parent = rows[par_row][par_col] parent.content = parent.content .. " " .. cell.content @@ -515,7 +536,7 @@ do return false end - local trc = state.roman_cache + local trc = thirddata.rst.state.roman_cache n_str = trc[str] or nil n_old = trc[old] or nil if not n_str then @@ -549,7 +570,7 @@ do end - local trc = state.roman_cache + local trc = thirddata.rst.state.roman_cache n_str = trc[str] or nil n_old = trc[old] or nil if not n_str then @@ -578,7 +599,7 @@ do return false end - local trc = state.roman_cache + local trc = thirddata.rst.state.roman_cache n_str = trc[str] or nil if not n_str then n_str = roman_to_arab(str:lower()) 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 4e6db410d1d..a397f5537b2 100644 --- a/Master/texmf-dist/tex/context/third/rst/rst_parser.lua +++ b/Master/texmf-dist/tex/context/third/rst/rst_parser.lua @@ -4,8 +4,8 @@ -- USAGE: refer to doc/documentation.rst -- DESCRIPTION: https://bitbucket.org/phg/context-rst/overview -- AUTHOR: Philipp Gesang (Phg), --- VERSION: 0.5 --- CHANGED: 2012-06-05 22:17:18+0200 +-- VERSION: 0.6 +-- CHANGED: 2013-03-26 22:45:59+0100 -------------------------------------------------------------------------------- -- @@ -30,6 +30,7 @@ rst.crlf = true helpers.rst_debug = false local iowrite = io.write +local ioopen = io.open local stringformat = string.format local stringlen = string.len local stringstrip = string.strip @@ -45,7 +46,9 @@ do local slen = #str + 3 --str = "*["..str.."]" str = stringformat("*[%4d][%s]", ndebug, str) - for i,j in ipairs({...}) do + local arglst = { ... } + for i=1, #arglst do + local current = arglst[i] if 80 - i * 8 - slen < 0 then local indent = "" for i=1, slen do @@ -53,7 +56,7 @@ do end str = str .. "\n" .. indent end - str = str .. stringformat(" |%6s", stringstrip(tostring(j))) + str = str .. stringformat(" |%6s", stringstrip(tostring(current))) end iowrite(str .. " |\n") return 0 @@ -70,7 +73,9 @@ local P, R, S, V, match local utf = unicode.utf8 -state = {} +local state = {} +thirddata.rst.state = state + state.depth = 0 state.bullets = {} -- mapping bullet forms to depth state.bullets.max = 0 @@ -179,17 +184,20 @@ local parser = P{ , directive = V"explicit_markup_start" - * C(((V"escaped_colon" + (1 - V"colon" - V"eol")) - V"substitution_text")^1) + * C(((V"escaped_colon" + (1 - V"colon" - V"eol")) + - V"substitution_text")^1) --> directive name * V"double_colon" - * (V"directive_block_multi" + V"directive_block_single") + * Ct(V"directive_block_multi" + V"directive_block_single") --> content / rst.directive , - directive_block_multi = C((1 - V"eol")^0) * V"eol" + directive_block_multi = Cg((1 - V"eol")^0, "name") -- name + * V"eol" + * V"blank_line"^0 -- how many empty lines are permitted? * V"directive_indented_lines" , - directive_block_single = C((1 - V"eol")^1) * V"eol", + directive_block_single = Ct(C((1 - V"eol")^1)) * V"eol", -------------------------------------------------------------------------------- -- Substitution definition block @@ -210,17 +218,18 @@ local parser = P{ * V"bar" , - data_directive_block = V"data_directive_block_long" - + V"data_directive_block_short" + data_directive_block = V"data_directive_block_multi" + + V"data_directive_block_single" , - data_directive_block_short = C((1 - V"eol")^0) * V"eol", + data_directive_block_single = Ct(C((1 - V"eol")^0)) * V"eol", - data_directive_block_long = C((1 - V"eol")^0) * V"eol" - * V"directive_indented_lines" - , + data_directive_block_multi = Cg((1 - V"eol")^0, "first") * V"eol" + * V"directive_indented_lines" + , - directive_indented_lines = V"directive_indented_first" - * V"directive_indented_other"^0 + directive_indented_lines = Ct(V"directive_indented_first" + * V"directive_indented_other"^0) + * (V"blank_line"^1 * Ct(V"directive_indented_other"^1))^0 , @@ -233,7 +242,11 @@ local parser = P{ , directive_indented_other = Cmt(V"space"^1, function(s,i,indent) - warn("sub-m", #state.currentindent <= #indent, #indent, #state.currentindent, i) + warn("sub-m", + #state.currentindent <= #indent, + #indent, + #state.currentindent, + i) return #state.currentindent <= #indent end) * C((1 - V"eol")^1) * V"eol" @@ -1376,7 +1389,7 @@ function file_helpers.crlf (raw) end local function load_file (name) - f = assert(io.open(name, "r"), "Not a file!") + f = assert(ioopen(name, "r"), "Not a file!") if not f then return 1 end local tmp = f:read("*all") f:close() @@ -1395,7 +1408,7 @@ local function load_file (name) end local function save_file (name, data) - f = assert(io.open(name, "w"), "Could not open file "..name.." for writing! Check its permissions") + f = assert(ioopen(name, "w"), "Could not open file "..name.." for writing! Check its permissions") if not f then return 1 end f:write(data) f:close() @@ -1403,17 +1416,15 @@ local function save_file (name, data) end local function get_setups (inline) - local optional_setups = optional_setups -- might expect lots of calls + local optional_setups = optional_setups local setups = "" if not inline then setups = setups .. [[ -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~% -%{ Setups }% -%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%+-------------------------------------------------------------+% +%| Setups |% +%+-------------------------------------------------------------+% % General % -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%---------------------------------------------------------------% ]] end @@ -1442,11 +1453,9 @@ local function get_setups (inline) setups = setups .. [[ -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~% -%{ Main }% -%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%+-------------------------------------------------------------+% +%| Main |% +%+-------------------------------------------------------------+% \starttext ]] @@ -1465,11 +1474,9 @@ function thirddata.rst.standalone (infile, outfile) \stoptext -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~% -%{ End of Document }% -%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%+-------------------------------------------------------------+% +%| End of Document |% +%+-------------------------------------------------------------+% % vim:ft=context:tw=65:shiftwidth=2:tabstop=2:set expandtab ]] @@ -1484,7 +1491,7 @@ end do local Cs, P = lpeg.Cs, lpeg.P - local percent = P"\%" + local percent = P"%" local eol = P"\n" local comment = percent * (1 - eol)^0 * eol / "\n" strip_comments = Cs((comment + 1)^0) @@ -1535,7 +1542,7 @@ function thirddata.rst.get_rst_inclusion (iname) if rst_inclusions[iname] then context.input(rst_inclusions[iname]) else - context(stringformat("{\\bf File for inclusion “%s” not found.}\par ", iname)) + context(stringformat([[{\bf File for inclusion “%s” not found.}\par ]], iname)) end 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 ccf3967b216..de70d4bc270 100644 --- a/Master/texmf-dist/tex/context/third/rst/rst_setups.lua +++ b/Master/texmf-dist/tex/context/third/rst/rst_setups.lua @@ -4,7 +4,7 @@ -- USAGE: called by rst_parser.lua -- DESCRIPTION: Complement to the reStructuredText parser -- AUTHOR: Philipp Gesang (Phg), --- CHANGED: 2012-06-05 22:17:10+0200 +-- CHANGED: 2013-03-26 23:55:20+0100 -------------------------------------------------------------------------------- -- @@ -12,15 +12,16 @@ local optional_setups = { } thirddata.rst_setups = optional_setups local rst_directives = thirddata.rst_directives local rst_context = thirddata.rst +local state = rst_context.state -local fmt = string.format -local stringstrip = string.strip +local stringformat = string.format +local stringstrip = string.strip function optional_setups.footnote_symbol () local setup = [[ -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%---------------------------------------------------------------% % Footnotes with symbol conversion % -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%---------------------------------------------------------------% \definenote[symbolnote][footnote] \setupnote [symbolnote][way=bypage,numberconversion=set 2] ]] @@ -31,9 +32,9 @@ function optional_setups.footnotes () local tf = state.footnotes local fn = [[ -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%---------------------------------------------------------------% % Footnotes % -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%---------------------------------------------------------------% ]] local buffer = [[ @@ -43,13 +44,13 @@ function optional_setups.footnotes () ]] for nf, note in next, tf.numbered do - fn = fn .. fmt(buffer, "Autonumbered footnote", "__footnote_number_"..nf, note) + fn = fn .. stringformat(buffer, "Autonumbered footnote", "__footnote_number_"..nf, note) end for nf, note in next, tf.autolabel do - fn = fn .. fmt(buffer, "Labeled footnote", "__footnote_label_"..nf, note) + fn = fn .. stringformat(buffer, "Labeled footnote", "__footnote_label_"..nf, note) end for nf, note in next, tf.symbol do - fn = fn .. fmt(buffer, "Symbol footnote", "__footnote_symbol_"..nf, note) + fn = fn .. stringformat(buffer, "Symbol footnote", "__footnote_symbol_"..nf, note) end return fn end @@ -81,9 +82,9 @@ function optional_setups.references () local refsection = [[ -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%---------------------------------------------------------------% % References % -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%---------------------------------------------------------------% ]] local references = {} @@ -96,7 +97,7 @@ function optional_setups.references () if arefs[ref_text] then ref_text = rst_context.anonymous_links[tonumber(arefs[ref_text])] end - references[#references+1] = fmt([[ + references[#references+1] = stringformat([[ \useURL[__target_%s] [%s] [] [%s] ]], rst_context.whitespace_to_underscore(ref), urlescape(target), ref_text) end end @@ -119,18 +120,19 @@ function optional_setups.substitutions () local directives = rst_directives local substitutions = [[ -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%---------------------------------------------------------------% % Substitutions % -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%---------------------------------------------------------------% ]] local rs = rst_context.substitutions for name, content in next, rs do - local directive, data = content.directive, content.data + local id, data = content.directive, content.data name, data = name:gsub("%s", ""), stringstrip(data) - if directives[directive] then - substitutions = substitutions .. directives[directive](name, data) + local directive = directives[id] + if directive then + substitutions = substitutions .. directive(name, data) else - err(directive .. " does not exist.") + err(id .. " does not exist.") end end return substitutions @@ -139,9 +141,9 @@ end function optional_setups.directive () --local dirstr = [[ ---%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +--%---------------------------------------------------------------% --% Directives % ---%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +--%---------------------------------------------------------------% --]] --return dirstr return "" @@ -150,9 +152,9 @@ end function optional_setups.blockquote () return [[ -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%---------------------------------------------------------------% % Blockquotes % -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%---------------------------------------------------------------% \setupdelimitedtext [blockquote][style={\tfx}] % awful placeholder \definedelimitedtext[attribution][blockquote] \setupdelimitedtext [attribution][style={\tfx\it}] @@ -162,9 +164,9 @@ end function optional_setups.deflist () return [[ -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%---------------------------------------------------------------% % Definitionlist % -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%---------------------------------------------------------------% \def\startRSTdefinitionlist{ \bgroup \def \RSTdeflistterm##1{{\bf ##1}} @@ -187,9 +189,9 @@ end function optional_setups.lines () return [[ -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%---------------------------------------------------------------% % Lines environment (line blocks) % -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%---------------------------------------------------------------% \setuplines[% space=on,% @@ -202,9 +204,9 @@ end function optional_setups.breaks () return [[ -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%---------------------------------------------------------------% % Fancy transitions % -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%---------------------------------------------------------------% % Get Wolfgang’s module at . \usemodule[fancybreak] @@ -215,9 +217,9 @@ end function optional_setups.fieldlist () return [[ -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%---------------------------------------------------------------% % Fieldlists % -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%---------------------------------------------------------------% \def\startRSTfieldlist{% \bgroup% @@ -250,9 +252,9 @@ function optional_setups.dbend () -- There's just no reason for not providing this. optional_setups.dbend_done = true return [[ -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%---------------------------------------------------------------% % Dangerous bend % -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%---------------------------------------------------------------% \loadmapfile [manfnt.map] \definefontsynonym [bends] [manfnt] @@ -276,9 +278,9 @@ function optional_setups.caution () --result = result .. optional_setups.dbend() --end return result .. [[ -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%---------------------------------------------------------------% % Caution directive % -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%---------------------------------------------------------------% \usemodule[lettrine] @@ -308,9 +310,9 @@ function optional_setups.danger () --result = result .. optional_setups.dbend() --end return result .. [[ -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%---------------------------------------------------------------% % Danger directive % -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%---------------------------------------------------------------% \usemodule[lettrine] @@ -327,9 +329,9 @@ end function optional_setups.citations () local cit = [[ -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%---------------------------------------------------------------% % Citations % -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%---------------------------------------------------------------% \setupbibtex[database=\jobname] ]] @@ -339,9 +341,9 @@ end function optional_setups.citator () local cit = [[ -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%---------------------------------------------------------------% % Citator Options % -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%---------------------------------------------------------------% \usemodule[citator] \loadbibdb{\jobname.bib} \setupcitator[sortmode=authoryear] 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 35ba054de2a..48801b57a04 100644 --- a/Master/texmf-dist/tex/context/third/rst/t-rst.mkiv +++ b/Master/texmf-dist/tex/context/third/rst/t-rst.mkiv @@ -1,6 +1,6 @@ %D \module [ %D file=t-rst, -%D version=0.4 ‘Owl-stretching time’ +%D version=0.6 ‘It’s the Arts’, %D title=\CONTEXT\ User Module, %D subtitle=reStructuredText, %D author=Philipp Gesang, @@ -56,7 +56,7 @@ \definenamespace [\v!RST] [ type=module, comment=reStructuredText module, - version=0.4, + version=0.6, name=\v!RST, style=\v!no, command=\v!yes, -- cgit v1.2.3