diff options
author | Philipp Gesang <pgesang@ix.urz.uni-heidelberg.de> | 2010-12-30 16:05:45 +0100 |
---|---|---|
committer | Philipp Gesang <pgesang@ix.urz.uni-heidelberg.de> | 2010-12-30 16:05:45 +0100 |
commit | 6dae96e6a7bb0dba0a43fc08ecf3b4614f80006c (patch) | |
tree | ac9e9dad8b326d6b39b76148d88cafba3c52fe5c | |
parent | 1af3e6e47b9072c481aa2d40cedd3b9b99220817 (diff) | |
download | context-rst-6dae96e6a7bb0dba0a43fc08ecf3b4614f80006c.tar.gz |
module code
-rw-r--r-- | doc/manual.tex | 1 | ||||
-rw-r--r-- | doc/moduletest.tex | 9 | ||||
-rw-r--r-- | mod/tex/context/third/rst/rst_context.lua (renamed from rst_context.lua) | 13 | ||||
-rw-r--r-- | mod/tex/context/third/rst/rst_directives.lua (renamed from rst_directives.lua) | 0 | ||||
-rw-r--r-- | mod/tex/context/third/rst/rst_helpers.lua (renamed from rst_helpers.lua) | 2 | ||||
-rw-r--r-- | mod/tex/context/third/rst/rst_parser.lua (renamed from rst_parser.lua) | 51 | ||||
-rw-r--r-- | mod/tex/context/third/rst/rst_setups.lua (renamed from rst_setups.lua) | 8 |
7 files changed, 69 insertions, 15 deletions
diff --git a/doc/manual.tex b/doc/manual.tex index c95e5ca..127a9cb 100644 --- a/doc/manual.tex +++ b/doc/manual.tex @@ -79,6 +79,7 @@ jobvariables.tobesaved = jobvariables.tobesaved or {} %\prependtoks \getbuffer[pubs] \to \everystoptext \setupwhitespace[none] +\setupindentation[yes,medium,next] \setuplayout[grid=verystrict] \setuptolerance[tolerant] \language[en] diff --git a/doc/moduletest.tex b/doc/moduletest.tex new file mode 100644 index 0000000..76994e7 --- /dev/null +++ b/doc/moduletest.tex @@ -0,0 +1,9 @@ +%% Usage example +% 1. load the module +\usemodule[rst] +% 2. add your setups +\setuphead[chapter][page=no] +\setupindenting[yes,medium,next] +% 3. run the converter +\typesetRSTfile{README.rst} + diff --git a/rst_context.lua b/mod/tex/context/third/rst/rst_context.lua index 1ea681f..1b6e5e3 100644 --- a/rst_context.lua +++ b/mod/tex/context/third/rst/rst_context.lua @@ -15,13 +15,18 @@ -- good. -require "lpeg" -help = require "rst_helpers" -rst_directives = require "rst_directives" +--local helpers +if not context then + require "lpeg" + helpers = require "rst_helpers" + rst_directives = require "rst_directives" +end + +if not helpers.string then print("Scheiße") os.exit() end local utf = unicode.utf8 -local dbg_write = help.dbg_writef +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 diff --git a/rst_directives.lua b/mod/tex/context/third/rst/rst_directives.lua index 0d4b4e9..0d4b4e9 100644 --- a/rst_directives.lua +++ b/mod/tex/context/third/rst/rst_directives.lua diff --git a/rst_helpers.lua b/mod/tex/context/third/rst/rst_helpers.lua index 869b4d9..f081559 100644 --- a/rst_helpers.lua +++ b/mod/tex/context/third/rst/rst_helpers.lua @@ -16,7 +16,7 @@ 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 -local helpers = {} +helpers = helpers or {} helpers.table = {} helpers.cell = {} diff --git a/rst_parser.lua b/mod/tex/context/third/rst/rst_parser.lua index c42b53e..580204c 100644 --- a/rst_parser.lua +++ b/mod/tex/context/third/rst/rst_parser.lua @@ -11,10 +11,22 @@ -------------------------------------------------------------------------------- -- ---require "lpeg" -rst = require "rst_context" -helpers = require "rst_helpers" -optional_setups = require "rst_setups" +rst = {} +helpers = {} +optional_setups = {} + +if context then + environment.loadluafile("rst_helpers") + environment.loadluafile("rst_setups" ) + environment.loadluafile("rst_context") + rst = rst_context + helpers = helpers + optional_setups = optional_setups +else + rst = require "rst_context" + helpers = require "rst_helpers" + optional_setups = require "rst_setups" +end local rst_debug = true @@ -1350,6 +1362,7 @@ local function save_file (name, data) end local function get_setups () + local optional_setups = optional_setups -- might expect lots of calls local setups = [[ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~% @@ -1376,7 +1389,7 @@ local function get_setups () for item, _ in next, state.addme do local f = optional_setups[item] - setups = setups .. f() + setups = f and setups .. f() or setups end return setups .. [[ @@ -1396,8 +1409,6 @@ local function main() if testdata == 1 then return 1 end local processeddata = parser:match(testdata) - - local setups = get_setups() processeddata = setups .. processeddata .. [[ @@ -1421,5 +1432,29 @@ local function main() return 0 end +do + local Cs, P = lpeg.Cs, lpeg.P + local percent = P"\%" + local eol = P"\n" + local comment = percent * (1 - eol)^0 * eol / "\n" + strip_comments = Cs((comment + 1)^0) +end + +function do_rst_file(fname) + local rst_parser = parser + local raw_data = load_file(fname) + local processed = rst_parser:match(raw_data) + local setups = get_setups() + local tmp_file = tex.jobname .. "–rst_temporary.tex.tmp" + + if processed then + processed = strip_comments:match(setups..processed.."\n\\stoptext\n") + save_file (tmp_file,processed) + context.input("./"..tmp_file) + end +end -return main() + +if not context then + return main() +end diff --git a/rst_setups.lua b/mod/tex/context/third/rst/rst_setups.lua index 917eebb..74a9650 100644 --- a/rst_setups.lua +++ b/mod/tex/context/third/rst/rst_setups.lua @@ -11,9 +11,13 @@ -------------------------------------------------------------------------------- -- -rst_directives = require "rst_directives" +if context then + environment.loadluafile("rst_directives") +else + rst_directives = require "rst_directives" +end -local optional_setups = {} +optional_setups = {} function optional_setups.footnote_symbol () local setup = [[ |