diff options
Diffstat (limited to 'Master/texmf-dist/scripts/context/lua/mtx-server-ctx-help.lua')
-rw-r--r-- | Master/texmf-dist/scripts/context/lua/mtx-server-ctx-help.lua | 1098 |
1 files changed, 554 insertions, 544 deletions
diff --git a/Master/texmf-dist/scripts/context/lua/mtx-server-ctx-help.lua b/Master/texmf-dist/scripts/context/lua/mtx-server-ctx-help.lua index d948c6e46d1..04217dab901 100644 --- a/Master/texmf-dist/scripts/context/lua/mtx-server-ctx-help.lua +++ b/Master/texmf-dist/scripts/context/lua/mtx-server-ctx-help.lua @@ -6,580 +6,561 @@ if not modules then modules = { } end modules ['mtx-server-ctx-help'] = { license = "see context related readme files" } --- todo in lua interface: noargument, oneargument, twoarguments, threearguments --- todo: pickup translations from mult file +local gsub, find, lower, match = string.gsub, string.find, string.lower, string.match +local concat, sort = table.concat, table.sort dofile(resolvers.findfile("trac-lmx.lua","tex")) +dofile(resolvers.findfile("util-sci.lua","tex")) +dofile(resolvers.findfile("char-def.lua","tex")) +dofile(resolvers.findfile("char-ini.lua","tex")) +dofile(resolvers.findfile("char-utf.lua","tex")) + +local scite = utilities.scite +local formatters = string.formatters +local sortedkeys = table.sortedkeys +local setmetatableindex = table.setmetatableindex +local lowercase = characters.lower +local uppercase = characters.upper +local interfaces = dofile(resolvers.findfile("mult-def.lua","tex")) +local i_setupstrings = interfaces.setupstrings +local i_commands = interfaces.commands +local i_variables = interfaces.variables +local i_constants = interfaces.constants +local i_elements = interfaces.elements +local report = logs.reporter("ctx-help") +local gettime = os.gettimeofday or os.clock + +local xmlcollected = xml.collected +local xmlfirst = xml.first +local xmltext = xml.text +local xmlload = xml.load + +document = document or { } +document.setups = document.setups or { } + +local usedsetupfile = resolvers.findfile("i-context.xml") or "" +local usedsetuproot = usedsetupfile ~= "" and xmlload(usedsetupfile) or false +local useddefinitions = { } + +if usedsetuproot then + report("main file loaded: %s",usedsetupfile) + xml.include(usedsetuproot,"cd:interfacefile","filename",true,function(s) + local fullname = resolvers.findfile(s) + if fullname and fullname ~= "" then + report("inclusion loaded: %s",fullname) + return io.loaddata(fullname) + end + end) +else + report("no main file") + return false, false +end --- problem ... serialize parent stack +local defaultinterface = "en" -local format, match, gsub, find = string.format, string.match, string.gsub, string.find -local concat = table.concat +-- todo: store mode|interface in field but then we need post -local report = logs.reporter("ctx-help") +for e in xmlcollected(usedsetuproot,"cd:define") do + useddefinitions[e.at.name] = e +end --- -- -- make this a module: cont-xx.lua +for e in xml.collected(usedsetuproot,"cd:interface/cd:interface") do + e.at.file = e.__f__ -- nicer +end -document = document or { } -document.setups = document.setups or { } +local f_divs_t = { + pe = formatters["<div dir='rtl' lang='arabic'>%s</div>"], +} -document.setups.div = { - pe = "<div dir='rtl' lang='arabic'>%s</div>" +local f_spans_t = { + pe = formatters["<span dir='rtl' lang='arabic'>%s</span>"] } -document.setups.span = { - pe = "<span dir='rtl' lang='arabic'>%s</span>" +local f_href_in_list_t = { + tex = formatters["<a class='setupmenuurl' href='mtx-server-ctx-help.lua?interface=%s&command=%s&mode=%s'>%s</a>"], + lua = formatters["<a class='setupmenuurl' href='mtx-server-ctx-help.lua?interface=%s&command=%s&mode=%s'>%s</a>"], } -document.setups.translations = document.setups.translations or { - - nl = { - ["title"] = "setup", - ["formula"] = "formule", - ["number"] = "getal", - ["list"] = "lijst", - ["dimension"] = "maat", - ["mark"] = "markering", - ["reference"] = "verwijzing", - ["command"] = "commando", - ["file"] = "file", - ["name"] = "naam", - ["identifier"] = "naam", - ["text"] = "tekst", - ["section"] = "sectie", - ["singular"] = "naam enkelvoud", - ["plural"] = "naam meervoud", - ["matrix"] = "n*m", - ["see"] = "zie", - ["inherits"] = "erft van", - ["optional"] = "optioneel", - ["displaymath"] = "formule", - ["index"] = "ingang", - ["math"] = "formule", - ["nothing"] = "leeg", - ["file"] = "file", - ["position"] = "positie", - ["reference"] = "verwijzing", - ["csname"] = "naam", - ["destination"] = "bestemming", - ["triplet"] = "triplet", - ["word"] = "woord", - ["content"] = "tekst", - }, - - en = { - ["title"] = "setup", - ["formula"] = "formula", - ["number"] = "number", - ["list"] = "list", - ["dimension"] = "dimension", - ["mark"] = "mark", - ["reference"] = "reference", - ["command"] = "command", - ["file"] = "file", - ["name"] = "name", - ["identifier"] = "identifier", - ["text"] = "text", - ["section"] = "section", - ["singular"] = "singular name", - ["plural"] = "plural name", - ["matrix"] = "n*m", - ["see"] = "see", - ["inherits"] = "inherits from", - ["optional"] = "optional", - ["displaymath"] = "formula", - ["index"] = "entry", - ["math"] = "formula", - ["nothing"] = "empty", - ["file"] = "file", - ["position"] = "position", - ["reference"] = "reference", - ["csname"] = "name", - ["destination"] = "destination", - ["triplet"] = "triplet", - ["word"] = "word", - ["content"] = "text", - - ["noargument"] = "\\cs", - ["oneargument"] = "\\cs#1{..}", - ["twoarguments"] = "\\cs#1#2{..}{..}", - ["threearguments"] = "\\cs#1#2#3{..}{..}{..}", - - }, - - de = { - ["title"] = "Setup", - ["formula"] = "Formel", - ["number"] = "Nummer", - ["list"] = "Liste", - ["dimension"] = "Dimension", - ["mark"] = "Beschriftung", - ["reference"] = "Referenz", - ["command"] = "Befehl", - ["file"] = "Datei", - ["name"] = "Name", - ["identifier"] = "Name", - ["text"] = "Text", - ["section"] = "Abschnitt", - ["singular"] = "singular", - ["plural"] = "plural", - ["matrix"] = "n*m", - ["see"] = "siehe", - ["inherits"] = "inherits from", - ["optional"] = "optioneel", - ["displaymath"] = "formula", - ["index"] = "entry", - ["math"] = "formula", - ["nothing"] = "empty", - ["file"] = "file", - ["position"] = "position", - ["reference"] = "reference", - ["csname"] = "name", - ["destination"] = "destination", - ["triplet"] = "triplet", - ["word"] = "word", - ["content"] = "text", - }, - - cz = { - ["title"] = "setup", - ["formula"] = "rovnice", - ["number"] = "cislo", - ["list"] = "seznam", - ["dimension"] = "dimenze", - ["mark"] = "znacka", - ["reference"] = "reference", - ["command"] = "prikaz", - ["file"] = "soubor", - ["name"] = "jmeno", - ["identifier"] = "jmeno", - ["text"] = "text", - ["section"] = "sekce", - ["singular"] = "jmeno v singularu", - ["plural"] = "jmeno v pluralu", - ["matrix"] = "n*m", - ["see"] = "viz", - ["inherits"] = "inherits from", - ["optional"] = "optioneel", - ["displaymath"] = "formula", - ["index"] = "entry", - ["math"] = "formula", - ["nothing"] = "empty", - ["file"] = "file", - ["position"] = "position", - ["reference"] = "reference", - ["csname"] = "name", - ["destination"] = "destination", - ["triplet"] = "triplet", - ["word"] = "word", - ["content"] = "text", - }, - - it = { - ["title"] = "setup", - ["formula"] = "formula", - ["number"] = "number", - ["list"] = "list", - ["dimension"] = "dimension", - ["mark"] = "mark", - ["reference"] = "reference", - ["command"] = "command", - ["file"] = "file", - ["name"] = "name", - ["identifier"] = "name", - ["text"] = "text", - ["section"] = "section", - ["singular"] = "singular name", - ["plural"] = "plural name", - ["matrix"] = "n*m", - ["see"] = "see", - ["inherits"] = "inherits from", - ["optional"] = "optioneel", - ["displaymath"] = "formula", - ["index"] = "entry", - ["math"] = "formula", - ["nothing"] = "empty", - ["file"] = "file", - ["position"] = "position", - ["reference"] = "reference", - ["csname"] = "name", - ["destination"] = "destination", - ["triplet"] = "triplet", - ["word"] = "word", - ["content"] = "text", - }, - - ro = { - ["title"] = "setari", - ["formula"] = "formula", - ["number"] = "numar", - ["list"] = "lista", - ["dimension"] = "dimensiune", - ["mark"] = "marcaj", - ["reference"] = "referinta", - ["command"] = "comanda", - ["file"] = "fisier", - ["name"] = "nume", - ["identifier"] = "nume", - ["text"] = "text", - ["section"] = "sectiune", - ["singular"] = "nume singular", - ["plural"] = "nume pluram", - ["matrix"] = "n*m", - ["see"] = "vezi", - ["inherits"] = "inherits from", - ["optional"] = "optioneel", - ["displaymath"] = "formula", - ["index"] = "entry", - ["math"] = "formula", - ["nothing"] = "empty", - ["file"] = "file", - ["position"] = "position", - ["reference"] = "reference", - ["csname"] = "name", - ["destination"] = "destination", - ["triplet"] = "triplet", - ["word"] = "word", - ["content"] = "text", - }, - - fr = { - ["title"] = "réglage", - ["formula"] = "formule", - ["number"] = "numéro", - ["list"] = "liste", - ["dimension"] = "dimension", - ["mark"] = "marquage", - ["reference"] = "reference", - ["command"] = "commande", - ["file"] = "fichier", - ["name"] = "nom", - ["identifier"] = "identificateur", - ["text"] = "texte", - ["section"] = "section", - ["singular"] = "nom singulier", - ["plural"] = "nom pluriel", - ["matrix"] = "n*m", - ["see"] = "vois", - ["inherits"] = "herite de", - ["optional"] = "optionel", - ["displaymath"] = "formule", - ["index"] = "entrée", - ["math"] = "formule", - ["nothing"] = "vide", - ["file"] = "fichier", - ["position"] = "position", - ["reference"] = "réference", - ["csname"] = "nom", - ["destination"] = "destination", - ["triplet"] = "triplet", - ["word"] = "mot", - ["content"] = "texte", - } +local f_href_in_list_i = { + tex = formatters["<a class='setupmenucmd' href='mtx-server-ctx-help.lua?interface=%s&command=%s&mode=%s' id='#current'>%s</a>"], + lua = formatters["<a class='setupmenucmd' href='mtx-server-ctx-help.lua?interface=%s&command=%s&mode=%s' id='#current'>%s</a>"], +} + +local f_href_as_command_t = { + tex = formatters["<a class='setuplisturl' href='mtx-server-ctx-help.lua?interface=%s&command=%s&mode=%s'>\\%s</a>"], + lua = formatters["<a class='setuplisturl' href='mtx-server-ctx-help.lua?interface=%s&command=%s&mode=%s'>context.%s</a>"], +} +local f_modes_t = { + tex = formatters["<a class='setupmodeurl' href='mtx-server-ctx-help.lua?interface=%s&mode=lua'>lua mode</a>"], + lua = formatters["<a class='setupmodeurl' href='mtx-server-ctx-help.lua?interface=%s&mode=tex'>tex mode</a>"], } -document.setups.formats = { - open_command = { - tex = [[\%s]], - lua = [[context.%s (]], - }, - close_command = { - tex = [[]], - lua = [[ )]], - }, - connector = { - tex = [[]], - lua = [[, ]], - }, - href_in_list = { - tex = [[<a href='mtx-server-ctx-help.lua?command=%s&mode=%s'>%s</a>]], - lua = [[<a href='mtx-server-ctx-help.lua?command=%s&mode=%s'>%s</a>]], - }, - href_as_command = { - tex = [[<a href='mtx-server-ctx-help.lua?command=%s&mode=%s'>\%s</a>]], - lua = [[<a href='mtx-server-ctx-help.lua?command=%s&mode=%s'>context.%s</a>]], - }, - modes = { - tex = [[<a href='mtx-server-ctx-help.lua?mode=lua'>lua mode</a>]], - lua = [[<a href='mtx-server-ctx-help.lua?mode=tex'>tex mode</a>]], - }, - optional_single = { - tex = "[optional string %s]", - lua = "{optional string %s}", - }, - optional_list = { - tex = "[optional list %s]", - lua = "{optional table %s}" , - } , - mandate_single = { - tex = "[mandate string %s]", - lua = "{mandate string %s}", - }, - mandate_list = { - tex = "[mandate list %s]", - lua = "{mandate list %s}", - }, - interface = [[<a href='mtx-server-ctx-help.lua?interface=%s&mode=%s'>%s</a>]], - source = [[<a href='mtx-server-ctx-help.lua?source=%s&mode=%s'>%s</a>]], - parameter = [[<tr><td width='15%%'>%s</td><td width='15%%'>%s</td><td width='70%%'>%s</td></tr>]], - parameters = [[<table width='100%%'>%s</table>]], - listing = [[<pre><t>%s</t></listing>]], - special = [[<i>%s</i>]], - default = [[<u>%s</u>]], +local f_views_t = { + groups = formatters["<a class='setupviewurl' href='mtx-server-ctx-help.lua?interface=%s&view=names'>names</a>"], + names = formatters["<a class='setupviewurl' href='mtx-server-ctx-help.lua?interface=%s&view=groups'>groups</a>"], } -local function translate(tag,int,noformat) - local t = document.setups.translations - local te = t["en"] - local ti = t[int] or te +local f_interface = formatters["<a href='mtx-server-ctx-help.lua?interface=%s&command=%s&mode=%s'>%s</a>"] +local f_source = formatters["<a href='mtx-server-ctx-help.lua?interface=%s&command=%s&source=%s&mode=%s'>%s</a>"] +local f_keyword = formatters[" <tr>\n <td width='15%%'>%s</td>\n <td width='85%%' colspan='2'>%s</td>\n </tr>\n"] +local f_parameter = formatters[" <tr>\n <td width='15%%'>%s</td>\n <td width='15%%'>%s</td>\n <td width='70%%'>%s</td>\n </tr>\n"] +local f_url = formatters[" <tr>\n <td width='15%%'>%s</td>\n <td width='85%%' colspan='2'><i>%s</i>: %s</td>\n </tr>\n"] +local f_parameters = formatters["\n<table width='100%%'>\n%s</table>\n"] +local f_instance = formatters["<tt>%s</tt>"] +local f_instances = formatters["\n<div class='setupinstances'><b>predefined instances</b>: %s</div>\n"] +local f_listing = formatters["<pre><t>%s</t></pre>"] +local f_special = formatters["<i>%s</i>"] +local f_default = formatters["<u>%s</u>"] +local f_group = formatters["<div class='setupmenugroup'>\n<div class='setupmenucategory'>%s</div>%s</div>"] + +-- replace('cd:string', 'value', i_commands, i_elements) +-- replace('cd:variable' , 'value', i_variables) +-- replace('cd:parameter', 'name', i_constants) +-- replace('cd:constant', 'type', i_variables) +-- replace('cd:constant', 'default', i_variables) +-- replace('cd:variable', 'type', i_variables) +-- replace('cd:inherit', 'name', i_commands, i_elements) + +local function translate(tag,interface,noformat) -- to be checked + local translation = i_setupstrings[tag] + local translated = translation and (translation[interface] or translation[interface]) or tag if noformat then - return ti[tag] or te[tag] or tag + return translated else - return format(document.setups.formats.special,ti[tag] or te[tag] or tag) + return f_special(translated) end end -local function translated(e,int) +local function translatedparameter(e,interface) local attributes = e.at local s = attributes.type or "?" - local tag = match(s,"^cd:(.*)$") - if attributes.default == "yes" then - return format(document.setups.formats.default,tag or "?") - elseif tag then - return translate(tag,int) + if find(s,"^cd:") then + local t = i_setupstrings[s] + local f = t and (t[interface] or t.en) or s + return f else - return s + local t = i_variables[s] + local f = t and (t[interface] or t.en) or s + return f end end -document.setups.loaded = document.setups.loaded or { } - -document.setups.current = { } -document.setups.showsources = true -document.setups.mode = "tex" - -function document.setups.load(filename) - filename = resolvers.findfile(filename) or "" - if filename ~= "" then - local current = document.setups.loaded[filename] - if not current then - local loaded = xml.load(filename) - if loaded then - -- xml.inject(document.setups.root,"/",loaded) - current = { - file = filename, - root = loaded, - names = { }, - used = { }, - } - document.setups.loaded[filename] = current - end +local function translatedkeyword(e,interface) + local attributes = e.at + local s = attributes.type or "?" + if find(s,"^cd:") then + local t = i_setupstrings[s] + local f = t and (t[interface] or t.en) or s + return f + else + local t = i_variables[s] + local f = t and (t[interface] or t.en) or s + if attributes.default == "yes" then + return f_default(f) + else + return f end - document.setups.current = current or { } end end -function document.setups.name(ek) - local at = ek.at +local function translatedvariable(s,interface) + local t = i_variables[s] + return t and (t[interface] or t.en) or s +end + +local function translatedconstant(s,interface) -- cache + local t = i_constants[s] + return t and (t[interface] or t.en) or s +end + +local function translatedelement(s,interface) -- cache + local t = i_elements[s] + return t and (t[interface] or t.en) or s +end + +local function translatedstring(s,interface) -- cache + local t = i_commands[s] + if t then + t = t[interface] or t.en + end + if t then + return t + end + t = i_elements[s] + return t and (t[interface] or t.en) or s +end + +local function translatedcommand(s,interface) -- cache + local t = i_commands[s] + return t and (t[interface] or t.en) or s +end + +local function makeidname(e) + local at = e.at local name = at.name if at.type == 'environment' then - name = "start" .. name + name = name .. ":environment" + end + if at.generated == "yes" then + name = name .. ":generated" end if at.variant then name = name .. ":" .. at.variant end - if at.generated == "yes" then - name = name .. "*" - end - return name:lower() + return lower(name) end -function document.setups.csname(ek,int) +local function makecsname(e,interface,prefix) -- stop ? local cs = "" - local at = ek.at or { } - if at.type == 'environment' then - cs = translate("start",int,true) .. cs + local at = e.at + local ok = false + local en = at.type == 'environment' + if prefix and en then + cs = translatedelement("start",interface) end - for e in xml.collected(ek,'cd:sequence/(cd:string|variable)') do - if e.tg == "string" then - cs = cs .. e.at.value + for f in xmlcollected(e,'cd:sequence/(cd:string|cd:variable)') do -- always at the start + local tag = f.tg + local val = f.at.value or "" + if tag == "string" then + cs = cs .. translatedstring(val,interface) + elseif tag == "variable" then + cs = cs .. f_special(translatedconstant("name",interface)) + else -- can't happen + cs = cs .. val + end + ok = true + end + if not ok then + if en then + cs = cs .. translatedstring(at.name,interface) else - cs = cs .. e.at.value -- to be translated + cs = cs .. translatedcommand(at.name,interface) end end return cs end -function document.setups.names() - local current = document.setups.current - local names = current.names - if not names or #names == 0 then - names = { } - local name = document.setups.name - local csname = document.setups.csname - for e in xml.collected(current.root,'cd:command') do - names[#names+1] = { e.at.name, csname(e,int) } +local function getnames(root,interface) + local found = { } + local names = { } + local groups = { } + for e in xmlcollected(root,'cd:interface/cd:interface') do + local category = match(e.at.file or "","^i%-(.*)%.xml$") + local list = { } + for e in xmlcollected(e,'cd:command') do + local idname = makeidname(e) + local csname = makecsname(e,interface,true) + if not found[idname] then + local t = { idname, csname } + names[#names+1] = t + list[#list+1] = t + found[idname] = e + else + -- variant + end + end + if #list > 0 then + sort(list, function(a,b) return lower(a[2]) < lower(b[2]) end) + groups[#groups+1] = { category, list } end - table.sort(names, function(a,b) return a[2]:lower() < b[2]:lower() end) - current.names = names - end - return names -end -function document.setups.show(name) - local current = document.setups.current - if current.root then - local name = gsub(name,"[<>]","") - local setup = xml.first(current.root,"cd:command[@name='" .. name .. "']") - current.used[#current.used+1] = setup - xml.sprint(setup) end + sort(names, function(a,b) return lower(a[2]) < lower(b[2]) end) + sort(groups, function(a,b) return lower(a[1]) < lower(b[1]) end) + return names, groups, found end -function document.setups.showused() - local current = document.setups.current - if current.root and next(current.used) then - local sorted = table.sortedkeys(current.used) - for i=1,#sorted do - xml.sprint(current.used[sorted[i]]) - end - end -end -function document.setups.showall() - local current = document.setups.current - if current.root then - local list = { } - for e in xml.collected(current.root,"cd:command") do - list[document.setups.name(e)] = e +local loaded = setmetatableindex(function(loaded,interface) + local names, groups, found = getnames(usedsetuproot,interface) + local current = { + interface = interface, + root = usedsetuproot, + definitions = useddefinitions, + names = names, + groups = groups, + found = found, + } + loaded[interface] = current + return current +end) + +local function collect(current,name,interface,lastmode) + local command = current.found[name] + if command then + local definitions = current.definitions + local attributes = command.at or { } + local generated = attributes.generated == "yes" + local environment = attributes.type == "environment" + local sequence = { } + local tags = { } + local arguments = { } + local parameters = { } + local instances = { } + local tag = "" + local category = attributes.category or "" + local source = attributes.file and f_source(lastinterface,lastcommand,attributes.file,lastmode,attributes.file) or "" + + -- first pass: construct the top line + + local start = environment and (attributes["begin"] or translatedelement("start",interface)) or "" + local stop = environment and (attributes["end"] or translatedelement("stop" ,interface)) or "" + local name = makecsname(command,interface) -- we can use the stored one + local valid = true + local texmode = lastmode == "tex" + + local function process(e) + for e in xmlcollected(e,"/*") do + if not e.special then + local tag = e.tg + local attributes = e.at + if tag == "resolve" then + local resolved = definitions[e.at.name or ""] + if resolved then + process(resolved) + end + else + -- we need a 'lua' tag i.e. we only support a subset of string/table + local delimiters = attributes.delimiters or "brackets" + local optional = attributes.optional == "yes" + local list = attributes.list == "yes" + if texmode then + local okay + if tag == "keywords" then + -- todo = optional + okay = i_setupstrings["cd:" .. delimiters .. (list and "-l" or "-s")] + elseif tag == "assignments" then + -- todo = optional + okay = i_setupstrings["cd:assignment" .. delimiters .. (list and "-l" or "-s")] + elseif tag == "delimiter" then + tag = "\\" .. attributes.name + elseif tag == "string" then + tag = translatedstring(attributes.value,interface) + else + -- todo = optional + okay = i_setupstrings["cd:" .. tag .. (list and "-l" or "-s")] + or i_setupstrings["cd:" .. tag] + end + if okay then + tag = okay.en or tag + end + else + local okay + if tag == "keywords" then + -- todo = optional + okay = i_setupstrings["cd:" .. delimiters .. (list and "-l" or "-s")] + elseif tag == "assignments" then + -- todo = optional + okay = i_setupstrings["cd:assignment" .. delimiters .. (list and "-l" or "-s")] + elseif tag == "delimiter" then + okay = false + elseif tag == "string" then + okay = false + else + -- todo = optional + okay = i_setupstrings["cd:" .. tag .. (list and "-l" or "-s")] + or i_setupstrings["cd:" .. tag] + end + if okay then + local luatag = okay.lua + if luatag then + tag = luatag + else + tag = "unsupported" + valid = false + end + else + tag = "unsupported" + valid = false + end + end + if tag then + sequence[#sequence+1] = tag + tags[#tags+1] = tag + end + end + end + end end - local sorted = table.sortedkeys(list) - for i=1,#sorted do - xml.sprint(list[sorted[i]]) + + if start and start ~= "" then + if texmode then + sequence[#sequence+1] = formatters["\\%s%s"](start,name) + else + sequence[#sequence+1] = formatters["context.%s%s("](start,name) + end + else + if texmode then + sequence[#sequence+1] = formatters["\\%s"](name) + else + sequence[#sequence+1] = formatters["context.%s("](name) + end end - end -end -function document.setups.resolve(name) - local current = document.setups.current - if current.root then - local e = xml.filter(current.root,format("cd:define[@name='%s']/text()",name)) - if e then - xml.sprint(e) + + for e in xmlcollected(command,"/cd:arguments") do + process(e) end - end -end -function document.setups.collect(name,int,lastmode) - local current = document.setups.current - local formats = document.setups.formats - local command = xml.filter(current.root,format("cd:command[@name='%s']/first()",name)) - if command then - local attributes = command.at or { } - local data = { - command = command, - category = attributes.category or "", - } - if document.setups.showsources then - data.source = (attributes.file and format(formats.source,attributes.file,lastmode,attributes.file)) or "" + if texmode then + if stop and stop ~= "" then + sequence[#sequence+1] = "\\" .. stop .. name + end else - data.source = attributes.file or "" - end - local n, sequence, tags = 0, { }, { } - sequence[#sequence+1] = format(formats.open_command[lastmode],document.setups.csname(command,int)) - local arguments, tag = { }, "" - for r, d, k in xml.elements(command,"(cd:keywords|cd:assignments)") do - n = n + 1 - local attributes = d[k].at - if #sequence > 1 then - local c = formats.connector[lastmode] - if c ~= "" then - sequence[#sequence+1] = c - end + for i=2,#sequence-1 do + sequence[i] = sequence[i] .. ", " end - if attributes.optional == 'yes' then - if attributes.list == 'yes' then - tag = format(formats.optional_list[lastmode],n) - else - tag = format(formats.optional_single[lastmode],n) - end + + if stop and stop ~= "" then + sequence[#sequence+1] = formatters[") context.%s%s()"](stop,name) else - if attributes.list == 'yes' then - tag = format(formats.mandate_list[lastmode],n) - else - tag = format(formats.mandate_single[lastmode],n) - end + sequence[#sequence+1] = ")" end - sequence[#sequence+1] = tag - tags[#tags+1] = tag end - sequence[#sequence+1] = formats.close_command[lastmode] - data.sequence = concat(sequence, " ") - local parameters, n = { }, 0 - for r, d, k in xml.elements(command,"(cd:keywords|cd:assignments)") do - n = n + 1 - if d[k].tg == "keywords" then - local left = tags[n] - local right = { } - for r, d, k in xml.elements(d[k],"(cd:constant|cd:resolve)") do - local tag = d[k].tg + + if valid then + + sequence = concat(sequence," ") + + -- second pass: construct the descriptions + + local n = 0 + + local function process(e) + for e in xmlcollected(e,"/*") do + local tag = e.tg + if tag == "resolve" then - local name = d[k].at.name or "" - if name ~= "" then - local resolved = xml.filter(current.root,format("cd:define[@name='%s']",name)) - for r, d, k in xml.elements(resolved,"cd:constant") do - right[#right+1] = translated(d[k],int) + + local resolved = definitions[e.at.name or ""] + if resolved then + process(resolved) + end + + elseif tag == "keywords" then + + n = n + 1 + local left = tags[n] + local right = { } + + local function processkeyword(e) + right[#right+1] = translatedkeyword(e,interface) + end + + for e in xmlcollected(e,"/*") do + if not e.special then + local tag = e.tg + if tag == "resolve" then + local resolved = definitions[e.at.name or ""] + if resolved then + processkeyword(resolved) + end + elseif tag == "constant" then + processkeyword(e) + else + right[#right+1] = "KEYWORD TODO" + end end end - else - right[#right+1] = translated(d[k],int) - end - end - parameters[#parameters+1] = format(formats.parameter,left,"",concat(right, ", ")) - else - local what = tags[n] - for r, d, k in xml.elements(d[k],"(cd:parameter|cd:inherit)") do - local tag = d[k].tg - local left, right = d[k].at.name or "?", { } - if tag == "inherit" then - local name = d[k].at.name or "?" - local url = format(document.setups.formats.href_as_command[lastmode],name,lastmode,name) - if #parameters > 0 and not find(parameters[#parameters],"<br/>") then - parameters[#parameters+1] = format(formats.parameter,"<br/>","","") + parameters[#parameters+1] = f_keyword(left,concat(right, ", ")) + + elseif tag == "assignments" then + + n = n + 1 + local what = tags[n] + local done = false + + local function processparameter(e,right) + for e in xmlcollected(e,"/*") do + if not e.special then + local tag = e.tg + if tag == "resolve" then + local resolved = definitions[e.at.name or ""] + if resolved then + processparameter(resolved,right) + end + elseif tag == "constant" then + right[#right+1] = translatedparameter(e,interface) + else + right[#right+1] = "PARAMETER TODO" + end + end + end end - parameters[#parameters+1] = format(formats.parameter,what,format(formats.special,translate("inherits",int)),url) - else - for r, d, k in xml.elements(d[k],"(cd:constant|cd:resolve)") do - local tag = d[k].tg - if tag == "resolve" then - local name = d[k].at.name or "" - if name ~= "" then - local resolved = xml.filter(current.root,format("cd:define[@name='%s']",name)) - for r, d, k in xml.elements(resolved,"cd:constant") do - right[#right+1] = translated(d[k],int) + + for e in xmlcollected(e,"/*") do + if not e.special then + local tag = e.tg + local left = translatedconstant(e.at.name,interface) + local right = { } + if tag == "resolve" then + local resolved = definitions[e.at.name or ""] + if resolved then + -- todo + process(resolved) end + elseif tag == "inherit" then + local name = e.at.name or "?" + local url = f_href_as_command_t[lastmode](lastinterface,name,lastmode,name) + parameters[#parameters+1] = f_url(what,translate("cd:inherits",interface),url) + elseif tag == "parameter" then + processparameter(e,right) + parameters[#parameters+1] = f_parameter(what,left,concat(right, ", ")) + else + parameters[#parameters+1] = "PARAMETER TODO" + end + if not done then + done = true + what = "" end - else - right[#right+1] = translated(d[k],int) end end - parameters[#parameters+1] = format(formats.parameter,what,left,concat(right, ", ")) + + what = "" + else + + n = n + 1 + local left = tags[n] + local right = i_setupstrings["cd:"..tag] + + if right then + right = uppercase(right[interface] or right.en or tag) + end + + parameters[#parameters+1] = f_keyword(left,right) + end - what = "" end end - parameters[#parameters+1] = format(formats.parameter,"<br/>","","") + + for e in xmlcollected(command,"/cd:arguments") do + process(e) + end + + else + if texmode then + sequence = formatters["unsupported command '%s%s'"](start or "",name) + else + sequence = formatters["unsupported function '%s%s'"](start or "",name) + end + parameters = { } end - data.parameters = parameters or { } - data.mode = formats.modes[lastmode or "tex"] - return data - else - return nil - end -end --- -- -- -tex = tex or { } + for e in xmlcollected(command,"/cd:instances/cd:constant") do + instances[#instances+1] = f_instance(translatedconstant(e.at.value or "?",interface)) + end + + return { + category = category, + source = source, + mode = f_modes_t[lastmode or "tex"](lastinterface), + view = f_views_t[lastview or "groups"](lastinterface), + sequence = sequence, + parameters = parameters, + instances = instances, + } + end +end -- -- -- @@ -594,8 +575,6 @@ local interfaces = { romanian = 'ro', } -local lastinterface, lastcommand, lastsource, lastmode = "en", "", "", "tex" - local variables = { ['color-background-main-left'] = '#3F3F3F', ['color-background-main-right'] = '#5F5F5F', @@ -604,66 +583,85 @@ local variables = { ['title'] = 'ConTeXt Help Information', } ---~ function lmx.loadedfile(filename) ---~ return io.loaddata(resolvers.findfile(filename)) -- return resolvers.texdatablob(filename) ---~ end +local what = { "environment", "category", "source", "mode", "view" } -local function doit(configuration,filename,hashed) +local function generate(configuration,filename,hashed) - local formats = document.setups.formats - - local start = os.clock() - local detail = hashed.queries or { } + local start = gettime() + local detail = hashed.queries or { } + local variables = setmetatableindex({},variables) if detail then + local lastinterface = detail.interface or defaultinterface or "en" + local lastcommand = detail.command or "" + local lastview = detail.view or "groups" + local lastsource = detail.source or "" + local lastmode = detail.mode or "tex" + + local current = loaded[lastinterface] - lastinterface = detail.interface or lastinterface - lastcommand = detail.command or lastcommand - lastsource = detail.source or lastsource - lastmode = detail.mode or lastmode or "tex" + local title = variables.title .. ": " .. lastinterface + variables.title = title lastcommand = gsub(lastcommand,"%s*^\\*(.+)%s*","%1") - if lastinterface then - report("checking interface: %s",lastinterface) - document.setups.load(format("cont-%s.xml",lastinterface)) + local f_div = f_divs_t[lastinterface] + ----- f_span = f_spans[lastinterface] + + local names = current.names + local groups = current.groups + local refs = { } + local ints = { } + + local function addnames(names) + local target = { } + for k=1,#names do + local namedata = names[k] + local command = namedata[1] + local text = namedata[2] + if command == lastcommand then + target[#target+1] = f_href_in_list_i[lastmode](lastinterface,command,lastmode,text) + else + target[#target+1] = f_href_in_list_t[lastmode](lastinterface,command,lastmode,text) + end + end + return concat(target,"<br/>\n") end - local div = document.setups.div [lastinterface] - local span = document.setups.span[lastinterface] - - local names, refs, ints = document.setups.names(lastinterface), { }, { } - for k=1,#names do - local v = names[k] - refs[k] = format(formats.href_in_list[lastmode],v[1],lastmode,v[2]) + if lastview == "groups" then + local target = { } + for i=1,#groups do + local group = groups[i] + target[#target+1] = f_group(group[1],addnames(group[2])) + end + refs = concat(target,"<br/>\n") + else + refs = addnames(names) end + if lastmode ~= "lua" then - local sorted = table.sortedkeys(interfaces) + local sorted = sortedkeys(interfaces) for k=1,#sorted do local v = sorted[k] - ints[k] = format(formats.interface,interfaces[v],lastmode,v) + ints[k] = f_interface(interfaces[v],lastcommand,lastmode,v) end end - local n = concat(refs,"<br/>") - local i = concat(ints,"<br/><br/>") + local n = refs + local i = concat(ints,"<br/><br/>\n") - if div then - variables.names = format(div,n) - variables.interfaces = format(div,i) + if f_div then + variables.names = f_div(n) + variables.interfaces = f_div(i) else variables.names = n variables.interfaces = i end - -- first we need to add information about mkii/mkiv + -- we only support mkiv - variables.maintitle = "no definition" - variables.maintext = "" - variables.extra = "" + if lastsource and lastsource ~= "" then - if document.setups.showsources and lastsource and lastsource ~= "" then - -- todo: mkii, mkiv, tex (can be different) local name = lastsource local full = resolvers.findfile(name) if full == "" and file.suffix(lastsource) == "tex" then @@ -676,16 +674,21 @@ local function doit(configuration,filename,hashed) end if full == "" then variables.maintitle = lastsource - variables.maintext = format(formats.listing,"no source found") + variables.maintext = f_listing("no source found") else + local data = io.loaddata(full) + data = scite.html(data,file.suffix(full),true) variables.maintitle = name - variables.maintext = format(formats.listing,io.loaddata(full)) + variables.maintext = f_listing(data) end - lastsource = "" + lastsource = "" + variables.extra = "mode: " .. f_modes_t.tex(lastinterface) .. " " .. f_modes_t.lua(lastinterface) + elseif lastcommand and lastcommand ~= "" then - local data = document.setups.collect(lastcommand,lastinterface,lastmode) + + local data = collect(current,lastcommand,lastinterface,lastmode) if data then - local what, extra = { "environment", "category", "source", "mode" }, { } + local extra = { } for k=1,#what do local v = what[k] if data[v] and data[v] ~= "" then @@ -693,12 +696,19 @@ local function doit(configuration,filename,hashed) extra[#extra+1] = v .. ": " .. data[v] end end + local instances = data.instances variables.maintitle = data.sequence - variables.maintext = format(formats.parameters,concat(data.parameters)) + variables.maintext = f_parameters(concat(data.parameters)) .. (#instances > 0 and f_instances(concat(instances,", ")) or "") variables.extra = concat(extra," ") else - variables.maintext = "select command" + variables.maintitle = "no definition" + variables.maintext = "" + variables.extra = "" end + else + variables.maintitle = "no definition" + variables.maintext = "" + variables.extra = "" end else @@ -711,9 +721,9 @@ local function doit(configuration,filename,hashed) local content = lmx.convert('context-help.lmx',false,variables) - report("time spent on page: %0.03f seconds",os.clock()-start) + report("time spent on building page: %0.03f seconds",gettime()-start) return { content = content } end -return doit, true +return generate, true |