summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mod/tex/context/third/rst/rst_context.lua13
-rw-r--r--mod/tex/context/third/rst/rst_directives.lua13
-rw-r--r--mod/tex/context/third/rst/rst_helpers.lua42
-rw-r--r--mod/tex/context/third/rst/rst_parser.lua44
-rw-r--r--mod/tex/context/third/rst/rst_setups.lua15
-rw-r--r--mod/tex/context/third/rst/t-rst.mkiv102
6 files changed, 132 insertions, 97 deletions
diff --git a/mod/tex/context/third/rst/rst_context.lua b/mod/tex/context/third/rst/rst_context.lua
index 846b507..5d35906 100644
--- a/mod/tex/context/third/rst/rst_context.lua
+++ b/mod/tex/context/third/rst/rst_context.lua
@@ -1,10 +1,9 @@
#!/usr/bin/env texlua
--------------------------------------------------------------------------------
-- FILE: rst_context.lua
--- USAGE: ./rst_context.lua
+-- USAGE: called by rst_parser.lua
-- AUTHOR: Philipp Gesang (Phg), <megas.kapaneus@gmail.com>
--- VERSION: 1.0
--- CREATED: 31/08/10 19:35:15 CEST
+-- CREATED: 2011-05-04 17:42:04+0200
--------------------------------------------------------------------------------
--
--- TODO
@@ -15,12 +14,8 @@
-- good.
---local helpers
-if not context then
- require "lpeg"
- helpers = require "rst_helpers"
- rst_directives = require "rst_directives"
-end
+local helpers = helpers or thirddata and thirddata.rst_helpers
+local rst_directives = rst_directives or thirddata and thirddata.rst_directives
local utf = unicode.utf8
diff --git a/mod/tex/context/third/rst/rst_directives.lua b/mod/tex/context/third/rst/rst_directives.lua
index 0d4b4e9..6af0ce4 100644
--- a/mod/tex/context/third/rst/rst_directives.lua
+++ b/mod/tex/context/third/rst/rst_directives.lua
@@ -1,18 +1,23 @@
#!/usr/bin/env texlua
--------------------------------------------------------------------------------
-- FILE: rst_directives.lua
--- USAGE: ./rst_directives.lua
+-- USAGE: called by rst_parser.lua
-- AUTHOR: Philipp Gesang (Phg), <megas.kapaneus@gmail.com>
--- VERSION: 1.0
--- CREATED: 22/09/10 20:26:40 CEST
+-- CREATED: 2011-05-04 17:43:02+0200
--------------------------------------------------------------------------------
--
+local helpers = helpers or thirddata and thirddata.rst_helpers
+
--------------------------------------------------------------------------------
-- Directives for use with |substitutions|
--------------------------------------------------------------------------------
-rst_directives = {}
+local rst_directives = { }
+if context then
+ thirddata.rst_directives = rst_directives
+end
+
rst_directives.anonymous = 0
rst_directives.images = {}
rst_directives.images.done = {}
diff --git a/mod/tex/context/third/rst/rst_helpers.lua b/mod/tex/context/third/rst/rst_helpers.lua
index f081559..e6a886b 100644
--- a/mod/tex/context/third/rst/rst_helpers.lua
+++ b/mod/tex/context/third/rst/rst_helpers.lua
@@ -1,11 +1,10 @@
#!/usr/bin/env texlua
--------------------------------------------------------------------------------
-- FILE: rst_helpers.lua
--- USAGE: ./rst_helpers.lua
+-- USAGE: called by rst_parser.lua
-- DESCRIPTION: Complement to the reStructuredText parser
-- AUTHOR: Philipp Gesang (Phg), <megas.kapaneus@gmail.com>
--- VERSION: 1.0
--- CREATED: 07/09/10 01:03:08 CEST
+-- CREATED: 2011-05-04 17:41:59+0200
--------------------------------------------------------------------------------
--
@@ -16,17 +15,21 @@ local P, R, S, V, match
local C, Carg, Cb, Cc, Cg, Cmt, Cp, Cs, Ct
= lpeg.C, lpeg.Carg, lpeg.Cb, lpeg.Cc, lpeg.Cg, lpeg.Cmt, lpeg.Cp, lpeg.Cs, lpeg.Ct
-helpers = helpers or {}
+local helpers
+if not context then
+ helpers = helpers or {}
+else
+ helpers = thirddata.rst_helpers
+end
helpers.table = {}
helpers.cell = {}
function helpers.dbg_writef(...)
- if helpers_debug == true then
+ if helpers.rst_debug then
io.write(string.format(...))
end
end
---helpers.dbg_write = dbg_write
local dbg_write = helpers.dbg_writef
helpers.patterns = {}
@@ -160,7 +163,6 @@ local function set_layout (line)
return layout
end
-helpers_debug = true
function helpers.table.create(raw)
local newtab = {}
newtab.rows = {}
@@ -295,18 +297,18 @@ 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, 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
return newtab
end
@@ -628,5 +630,5 @@ do
end
end
-return helpers
+--return helpers
diff --git a/mod/tex/context/third/rst/rst_parser.lua b/mod/tex/context/third/rst/rst_parser.lua
index b0a02e6..ec9366e 100644
--- a/mod/tex/context/third/rst/rst_parser.lua
+++ b/mod/tex/context/third/rst/rst_parser.lua
@@ -1,38 +1,42 @@
#!/usr/bin/env texlua
--------------------------------------------------------------------------------
-- FILE: rst-parser.lua
--- USAGE: ./rst-parser.lua
--- DESCRIPTION:
--- OPTIONS: ---
--- REQUIREMENTS: ---
+-- USAGE: refer to doc/documentation.rst
+-- DESCRIPTION: https://bitbucket.org/phg/context-rst/overview
-- AUTHOR: Philipp Gesang (Phg), <megas.kapaneus@gmail.com>
--- VERSION: 1.0
--- CREATED: 31/08/10 11:53:49 CEST
+-- VERSION: 0.3
+-- CREATED: 2011-05-04 17:41:15+0200
--------------------------------------------------------------------------------
--
-rst = {}
-helpers = {}
-optional_setups = {}
+local rst
+local helpers = {}
+local optional_setups
if context then
+ thirddata = thirddata or { }
+ thirddata.rst = { }
+ thirddata.rst_helpers = helpers
+ --thirddata.rst_setups = optional_setups
+
environment.loadluafile("rst_helpers")
+ environment.loadluafile("rst_directives")
environment.loadluafile("rst_setups" )
environment.loadluafile("rst_context")
- rst = rst_context
- helpers = helpers
- optional_setups = optional_setups
+
+ rst = rst_context
+ optional_setups = thirddata.rst_setups
else
- rst = require "rst_context"
- helpers = require "rst_helpers"
+ rst = require "rst_context"
+ helpers = require "rst_helpers"
optional_setups = require "rst_setups"
+ rst_directives = require "rst_directives"
end
-
-local rst_debug = true
+helpers.rst_debug = false
local warn = function(str, ...)
- if not rst_debug then return false end
+ if not helpers.rst_debug then return false end
local slen = #str + 3
str = "*["..str.."]"
for i,j in ipairs({...}) do
@@ -1374,7 +1378,7 @@ local function get_setups (inline)
\setupcolors[state=start]
\setupinteraction[state=start,focus=standard,color=darkgreen,contrastcolor=darkgreen]
-\setupbodyfontenvironment [default] [em=italic]
+%\setupbodyfontenvironment [default] [em=italic]
\sethyphenatedurlnormal{:=?&}
\sethyphenatedurlbefore{?&}
\sethyphenatedurlafter {:=/-}
@@ -1443,7 +1447,7 @@ do
strip_comments = Cs((comment + 1)^0)
end
-function rst.do_rst_file(fname)
+function thirddata.rst.do_rst_file(fname)
local rst_parser = parser
local raw_data = load_file(fname)
local processed = rst_parser:match(raw_data)
@@ -1457,7 +1461,7 @@ function rst.do_rst_file(fname)
end
end
-function rst.do_rst_snippet(txt)
+function thirddata.rst.do_rst_snippet(txt)
local processed = parser:match(txt)
local setups = get_setups(true)
local tmp_file = tex.jobname .. "–rst_temporary.tex.tmp"
diff --git a/mod/tex/context/third/rst/rst_setups.lua b/mod/tex/context/third/rst/rst_setups.lua
index 74a9650..c10a914 100644
--- a/mod/tex/context/third/rst/rst_setups.lua
+++ b/mod/tex/context/third/rst/rst_setups.lua
@@ -1,24 +1,23 @@
#!/usr/bin/env texlua
--------------------------------------------------------------------------------
-- FILE: rst_setups.lua
--- USAGE: ./rst_setups.lua
+-- USAGE: called by rst_parser.lua
-- DESCRIPTION: Setups for rstcontext
--- OPTIONS: ---
--- REQUIREMENTS: ---
-- AUTHOR: Philipp Gesang (Phg), <megas.kapaneus@gmail.com>
--- VERSION: 1.0
--- CREATED: 22/09/10 20:21:01 CEST
+-- CREATED: 2011-05-04 17:42:55+0200
--------------------------------------------------------------------------------
--
+--local rst_directives = context and thirddata.rst_directives or require "rst_directives"
+local optional_setups = { }
+local rst_directives
if context then
- environment.loadluafile("rst_directives")
+ thirddata.rst_setups = optional_setups
+ rst_directives = thirddata.rst_directives
else
rst_directives = require "rst_directives"
end
-optional_setups = {}
-
function optional_setups.footnote_symbol ()
local setup = [[
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
diff --git a/mod/tex/context/third/rst/t-rst.mkiv b/mod/tex/context/third/rst/t-rst.mkiv
index 015aa4a..d54af02 100644
--- a/mod/tex/context/third/rst/t-rst.mkiv
+++ b/mod/tex/context/third/rst/t-rst.mkiv
@@ -23,7 +23,7 @@
type=module,
comment=reStructuredText module,
version=0.2,
- name=reST,
+ name=RST,
style=no,
command=yes,
setup=list,
@@ -31,63 +31,93 @@
]
%D Loading the reStructuredText parser.
-\ctxlua{environment.loadluafile("rst_parser")}
+\ctxloadluafile{rst_parser}
+
+\def\RST_enable_verbose{%
+ \doif{\RSTparameter{debug}}\v!yes\ctxlua{thirddata.rst_helpers.rst_debug = true}%
+}
+\appendtoks \RST_enable_verbose \to \everysetupRST
%D Setting some globals.
-\setupreST [ ]
+\setupRST [debug=no]
%D This command loads and processes the \type{*.rst} file.
-\def\typesetRSTfile#1{\ctxlua{rst.do_rst_file("#1")}}
+\def\typesetRSTfile#1{\ctxlua{thirddata.rst.do_rst_file("#1")}}
%D To process inline reST markup we’ll have to reset all catcodes
%D except for grouping, escaping and cs arguments.
-\ifdefined\RSTcatcodes \else
- \newcatcodetable \RSTcatcodes
- \startcatcodetable \RSTcatcodes
- \catcode`\^^I = 12 % ascii tab is a blank space
- \catcode`\^^M = 12 % ascii return is end-line
- \catcode`\^^L = 12 % ascii form-feed
- \catcode`\ = 12
- \catcode`\^^Z = 12
- \catcode`\\ = 0
- \catcode`\% = 12
- \catcode`\# = 6
- \catcode`\_ = 12
- \catcode`\^ = 12
- \catcode`\& = 12
- \catcode`\| = 12
- \catcode`\{ = 1
- \catcode`\} = 2
- \catcode`\~ = 12
- \catcode`\$ = 12
- \stopcatcodetable
-\fi
+\newcatcodetable \RST_catcodes
+\startcatcodetable \RST_catcodes
+ \catcode`\^^I = 12 % ascii tab is a blank space
+ \catcode`\^^M = 12 % ascii return is end-line
+ \catcode`\^^L = 12 % ascii form-feed
+ \catcode`\ = 12
+ \catcode`\^^Z = 12
+ \catcode`\\ = 0
+ \catcode`\% = 12
+ \catcode`\# = 6
+ \catcode`\_ = 12
+ \catcode`\^ = 12
+ \catcode`\& = 12
+ \catcode`\| = 12
+ \catcode`\{ = 1
+ \catcode`\} = 2
+ \catcode`\~ = 12
+ \catcode`\$ = 12
+\stopcatcodetable
%D The environment \type{\[start|stop]RST} and the macro
%D \type{\RST} allow access to reST-parser from inside a
%D \CONTEXT-document when the module is loaded.
-\unexpanded\def\startRST{
- \setcatcodetable \RSTcatcodes%
- \dostartRST%
+\unexpanded\def\startRST{%
+ \setcatcodetable \RST_catcodes%
+ \do_start_RST%
}
\let\stopRST\relax
-\def\dostartRST#1\stopRST{%
- \edef\RSTdata{#1}%
+\def\do_start_RST#1\stopRST{%
+ \edef\RST_data{#1}%
\setcatcodetable \ctxcatcodes%
- \ctxlua{rst.do_rst_snippet([[\RSTdata]])}%
+ \ctxlua{thirddata.rst.do_rst_snippet([[\RST_data]])}%
}
\def\RST{%
- \setcatcodetable \RSTcatcodes%
- \doRST%
+ \setcatcodetable \RST_catcodes%
+ \do_RST%
}
-\def\doRST#1{%
- \def\RSTdata{#1}%
+\def\do_RST#1{%
+ \def\RST_data{#1}%
\setcatcodetable \ctxcatcodes%
- \ctxlua{rst.do_rst_snippet([[\RSTdata]])}%
+ \ctxlua{thirddata.rst.do_rst_snippet([[\RST_data]])}%
}
+%%% Wolfgang’s code below; needs testing
+%\unexpanded\def\startRST{%
+ %\begingroup
+ %\setcatcodetable \RSTcatcodes
+ %\dostartRST%
+%}
+
+%\let\stopRST\relax
+
+%\def\dostartRST#1\stopRST{%
+ %\ctxlua{thirddata.rst.do_rst_snippet(\!!bs#1\!!es)}%
+ %\endgroup%
+%}
+
+%\def\RST{%
+ %\begingroup
+ %\setcatcodetable \RSTcatcodes
+ %\doRST%
+%}
+
+%\def\doRST#1{%
+ %\ctxlua{thirddata.rst.do_rst_snippet(\!!bs#1\!!es)}%
+ %\endgroup%
+%}
+
\protect \endinput
+
+% vim:ft=context:sw=2:ts=2