summaryrefslogtreecommitdiff
path: root/mod/scripts/context/lua/third/rst/mtx-t-rst.lua
blob: fc3b8e91243fc6a2ac7ccbc5967d9d1305f727ba (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
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), <megas.kapaneus@gmail.com>
--      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: <https://bitbucket.org/phg/context-rst/>
===============================================================

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"
    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