From af128c93d64e2a4e49cb7e6a7eca569cf122d0da Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Sun, 28 Aug 2011 13:09:10 +0200 Subject: moved external parser to mtx script --- mod/scripts/context/lua/mtx-rst.lua | 64 ++++++++++++++++++++++++++++ mod/tex/context/third/rst/rst_context.lua | 4 +- mod/tex/context/third/rst/rst_directives.lua | 6 +-- mod/tex/context/third/rst/rst_helpers.lua | 2 - mod/tex/context/third/rst/rst_parser.lua | 60 +++++++++++++++----------- mod/tex/context/third/rst/rst_setups.lua | 11 ++--- 6 files changed, 105 insertions(+), 42 deletions(-) create mode 100644 mod/scripts/context/lua/mtx-rst.lua (limited to 'mod') diff --git a/mod/scripts/context/lua/mtx-rst.lua b/mod/scripts/context/lua/mtx-rst.lua new file mode 100644 index 0000000..2b3841a --- /dev/null +++ b/mod/scripts/context/lua/mtx-rst.lua @@ -0,0 +1,64 @@ +#!/usr/bin/env texlua +-------------------------------------------------------------------------------- +-- FILE: mtx-rst.lua +-- USAGE: mtxrun --script rst --if=input.rst --of=output.tex +-- DESCRIPTION: context script interface for the reStructuredText module +-- REQUIREMENTS: latest ConTeXt MkIV +-- AUTHOR: Philipp Gesang (Phg), +-- CREATED: 2011-08-28 12:43:49+0200 +-------------------------------------------------------------------------------- +-- + +scripts = scripts or { } +scripts.rst = { } + +environment.loadluafile("rst_parser") + +local ea = environment.argument + +local helpinfo = [[ +=============================================================== + The reStructuredText module, command line interface. + © 2010--2011 Philipp Gesang. License: 2-clause BSD. + Home: +=============================================================== + +USAGE: + + mtxrun --script rst --if=input.rst --of=output.tex + +Mandatory arguments: + + “infile.rst” is your input file containing reST markup. + “outfile.tex” is the target file that the TeX-code will be + written to. + +Optional arguments: + --et=bool “expandtab”, should tab chars (“\t”, “\v”) be + converted to spaces? + --sw=int “shiftwidth”, tab stop modulo factor. + +=============================================================== +]] + +local application = logs.application { + name = "mtx-rst", + banner = "The reStructuredText module for ConTeXt, hg-rev 125+", + helpinfo = helpinfo, +} + +scripts.rst.input = ea("if") +scripts.rst.output = ea("of") + +if scripts.rst.input and scripts.rst.output then + local expandtab = ea("et") == "true" and true + local shiftwidth = ea("sw") + local debug = ea("debug") == "true" and true or false + if expandtab then thirddata.rst.expandtab = true end + if shiftwdith then thirddata.rst.shiftwidth = tonumber(shiftwidth) end + if debug then thirddata.rst_helpers.rst_debug = debug end + thirddata.rst.standalone(scripts.rst.input, scripts.rst.output) +else + application.help() +end + diff --git a/mod/tex/context/third/rst/rst_context.lua b/mod/tex/context/third/rst/rst_context.lua index 86f4177..c742815 100644 --- a/mod/tex/context/third/rst/rst_context.lua +++ b/mod/tex/context/third/rst/rst_context.lua @@ -44,7 +44,7 @@ local err = function(str) end end -rst_context = {} +local rst_context = thirddata.rst rst_context.collected_adornments = {} rst_context.last_section_level = 0 @@ -1229,5 +1229,3 @@ function rst_context.directive(directive, ...) end return result end - -return rst_context diff --git a/mod/tex/context/third/rst/rst_directives.lua b/mod/tex/context/third/rst/rst_directives.lua index a8a5eb7..7515a66 100644 --- a/mod/tex/context/third/rst/rst_directives.lua +++ b/mod/tex/context/third/rst/rst_directives.lua @@ -15,9 +15,8 @@ local helpers = helpers or thirddata and thirddata.rst_helpers -------------------------------------------------------------------------------- local rst_directives = { } -if context then - thirddata.rst_directives = rst_directives -end +thirddata.rst_directives = rst_directives +local rst_context = thirddata.rst rst_directives.anonymous = 0 rst_directives.images = {} @@ -258,4 +257,3 @@ rst_directives.replace = function(name, data) ]], name, data) end -return rst_directives diff --git a/mod/tex/context/third/rst/rst_helpers.lua b/mod/tex/context/third/rst/rst_helpers.lua index 73420d0..55c470c 100644 --- a/mod/tex/context/third/rst/rst_helpers.lua +++ b/mod/tex/context/third/rst/rst_helpers.lua @@ -625,5 +625,3 @@ do end end -return helpers - diff --git a/mod/tex/context/third/rst/rst_parser.lua b/mod/tex/context/third/rst/rst_parser.lua index 045d322..283ebf2 100644 --- a/mod/tex/context/third/rst/rst_parser.lua +++ b/mod/tex/context/third/rst/rst_parser.lua @@ -4,35 +4,24 @@ -- USAGE: refer to doc/documentation.rst -- DESCRIPTION: https://bitbucket.org/phg/context-rst/overview -- AUTHOR: Philipp Gesang (Phg), --- VERSION: 0.3 --- CHANGED: 2011-05-08 17:55:54+0200 +-- VERSION: 0.6 +-- CHANGED: 2011-08-28 12:44:03+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 @@ -53,7 +42,7 @@ local warn = function(str, ...) end str = str .. string.format(" |%6s", string.strip(tostring(j))) end - io.write(str .. " |\n") + iowrite(str .. " |\n") return 0 end @@ -65,6 +54,8 @@ local P, R, S, V, match local utf = unicode.utf8 +local iowrite = io.write + local eol = P"\n" state = {} @@ -1465,8 +1456,8 @@ local function get_setups (inline) 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) @@ -1486,7 +1477,7 @@ local function main() ]] if processeddata then - save_file(arg[2], processeddata) + save_file(outfile, processeddata) else return 1 end @@ -1534,7 +1525,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/mod/tex/context/third/rst/rst_setups.lua b/mod/tex/context/third/rst/rst_setups.lua index b7bda95..ee5b5a3 100644 --- a/mod/tex/context/third/rst/rst_setups.lua +++ b/mod/tex/context/third/rst/rst_setups.lua @@ -10,13 +10,10 @@ --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 + --rst_directives = require "rst_directives" function optional_setups.footnote_symbol () local setup = [[ -- cgit v1.2.3