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 | 207 |
1 files changed, 112 insertions, 95 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 c53d9f6e0f2..2f072f97747 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,8 +6,10 @@ if not modules then modules = { } end modules ['mtx-server-ctx-help'] = { license = "see context related readme files" } ---~ dofile(resolvers.find_file("l-xml.lua","tex")) -dofile(resolvers.find_file("l-aux.lua","tex")) +-- todo in lua interface: noargument, oneargument, twoarguments, threearguments + +--~ dofile(resolvers.find_file("l-aux.lua","tex")) +--~ dofile(resolvers.find_file("l-url.lua","tex")) dofile(resolvers.find_file("trac-lmx.lua","tex")) -- problem ... serialize parent stack @@ -277,18 +279,23 @@ document.setups.translations = document.setups.translations or { } document.setups.formats = { - interface = [[<a href='mtx-server-ctx-help.lua?interface=%s'>%s</a>]], - href = [[<a href='mtx-server-ctx-help.lua?command=%s'>%s</a>]], - source = [[<a href='mtx-server-ctx-help.lua?source=%s'>%s</a>]], - optional_single = "[optional string %s]", - optional_list = "[optional list %s]", - mandate_single = "[mandate string %s]", - mandate_list = "[mandate list %s]", - 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>", + open_command = { [[\%s]], [[context.%s (]] }, + close_command = { [[]], [[ )]] }, + connector = { [[]], [[, ]] }, + href_in_list = { [[<a href='mtx-server-ctx-help.lua?command=%s&mode=%s'>%s</a>]], [[<a href='mtx-server-ctx-help.lua?command=%s&mode=%s'>%s</a>]] }, + href_as_command = { [[<a href='mtx-server-ctx-help.lua?command=%s&mode=%s'>\%s</a>]], [[<a href='mtx-server-ctx-help.lua?command=%s&mode=%s'>context.%s</a>]] }, + 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>]], + modes = { [[<a href='mtx-server-ctx-help.lua?mode=2'>lua mode</a>]], [[<a href='mtx-server-ctx-help.lua?mode=1'>tex mode</a>]] }, + optional_single = { "[optional string %s]", "{optional string %s}" }, + optional_list = { "[optional list %s]", "{optional table %s}" } , + mandate_single = { "[mandate string %s]", "{mandate string %s}" }, + mandate_list = { "[mandate list %s]", "{mandate list %s}" }, + 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 function translate(tag,int,noformat) @@ -298,7 +305,7 @@ local function translate(tag,int,noformat) if noformat then return ti[tag] or te[tag] or tag else - return document.setups.formats.special:format(ti[tag] or te[tag] or tag) + return format(document.setups.formats.special,ti[tag] or te[tag] or tag) end end @@ -307,7 +314,7 @@ local function translated(e,int) local s = attributes.type or "?" local tag = s:match("^cd:(.*)$") if attributes.default == "yes" then - return document.setups.formats.default:format(tag) + return format(document.setups.formats.default,tag or "?") elseif tag then return translate(tag,int) else @@ -318,7 +325,8 @@ end document.setups.loaded = document.setups.loaded or { } document.setups.current = { } -document.setups.showsources = false +document.setups.showsources = true +document.setups.mode = 1 function document.setups.load(filename) filename = resolvers.find_file(filename) or "" @@ -358,16 +366,15 @@ end function document.setups.csname(ek,int) local cs = "" - local at = ek.at + local at = ek.at or { } if at.type == 'environment' then cs = translate("start",int,true) .. cs end - for r, d, k in xml.elements(ek,'cd:sequence/(cd:string|variable)') do - local dk = d[k] - if dk.tg == "string" then - cs = cs .. dk.at.value + for e in xml.collected(ek,'cd:sequence/(cd:string|variable)') do + if e.tg == "string" then + cs = cs .. e.at.value else - cs = cs .. dk.at.value -- to be translated + cs = cs .. e.at.value -- to be translated end end return cs @@ -380,9 +387,8 @@ function document.setups.names() names = { } local name = document.setups.name local csname = document.setups.csname - for r, d, k in xml.elements(current.root,'cd:command') do - local dk = d[k] - names[#names+1] = { dk.at.name, csname(dk,int) } + for e in xml.collected(current.root,'cd:command') do + names[#names+1] = { e.at.name, csname(e,int) } end table.sort(names, function(a,b) return a[2]:lower() < b[2]:lower() end) current.names = names @@ -403,8 +409,9 @@ end function document.setups.showused() local current = document.setups.current if current.root and next(current.used) then - for k,v in ipairs(table.sortedkeys(current.used)) do - xml.sprint(current.used[v]) + local sorted = table.sortedkeys(current.used) + for i=1,#sorted do + xml.sprint(current.used[sorted[i]]) end end end @@ -412,12 +419,12 @@ function document.setups.showall() local current = document.setups.current if current.root then local list = { } - xml.each_element(current.root,"cd:command", function(r,d,t) - local ek = d[t] - list[document.setups.name(ek)] = ek - end ) - for k,v in ipairs(table.sortedkeys(list)) do - xml.sprint(list[v]) + for e in xml.collected(current.root,"cd:command") do + list[document.setups.name(e)] = e + end + local sorted = table.sortedkeys(list) + for i=1,#sorted do + xml.sprint(list[sorted[i]]) end end end @@ -431,46 +438,56 @@ function document.setups.resolve(name) end end -function document.setups.collect(name,int) +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']",name)) + local command = xml.filter(current.root,format("cd:command[@name='%s']/first()",name)) if command then - local attributes = command.at + local attributes = command.at or { } local data = { command = command, category = attributes.category or "", } if document.setups.showsources then - data.source = (attributes.file and formats.source:format(attributes.file,attributes.file)) or "" + data.source = (attributes.file and formats.source:format(attributes.file,lastmode,attributes.file)) or "" else data.source = attributes.file or "" end - local sequence, n = { "\\" .. document.setups.csname(command,int) }, 0 - local arguments = { } + local n, sequence, tags = 0, { }, { } + sequence[#sequence+1] = formats.open_command[lastmode]:format(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 + end if attributes.optional == 'yes' then if attributes.list == 'yes' then - sequence[#sequence+1] = formats.optional_list:format(n) + tag = formats.optional_list[lastmode]:format(n) else - sequence[#sequence+1] = formats.optional_single:format(n) + tag = formats.optional_single[lastmode]:format(n) end else if attributes.list == 'yes' then - sequence[#sequence+1] = formats.mandate_list:format(n) + tag = formats.mandate_list[lastmode]:format(n) else - sequence[#sequence+1] = formats.mandate_single:format(n) + tag = formats.mandate_single[lastmode]:format(n) end 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 = sequence[n+1] + 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 @@ -488,13 +505,13 @@ function document.setups.collect(name,int) end parameters[#parameters+1] = formats.parameter:format(left,"",concat(right, ", ")) else - local what = sequence[n+1] + 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 goto = document.setups.formats.href:format(name,"\\"..name) + local goto = document.setups.formats.href_as_command[lastmode]:format(name,lastmode,name) if #parameters > 0 and not parameters[#parameters]:find("<br/>") then parameters[#parameters+1] = formats.parameter:format("<br/>","","") end @@ -521,7 +538,8 @@ function document.setups.collect(name,int) end parameters[#parameters+1] = formats.parameter:format("<br/>","","") end - data.parameters = parameters + data.parameters = parameters or { } + data.mode = formats.modes[lastmode or 1] return data else return nil @@ -532,25 +550,6 @@ end tex = tex or { } -lmx.variables['color-background-green'] = '#4F6F6F' -lmx.variables['color-background-blue'] = '#6F6F8F' -lmx.variables['color-background-yellow'] = '#8F8F6F' -lmx.variables['color-background-purple'] = '#8F6F8F' - -lmx.variables['color-background-body'] = '#808080' -lmx.variables['color-background-main'] = '#3F3F3F' -lmx.variables['color-background-main-left'] = '#3F3F3F' -lmx.variables['color-background-main-right'] = '#5F5F5F' -lmx.variables['color-background-one'] = lmx.variables['color-background-green'] -lmx.variables['color-background-two'] = lmx.variables['color-background-blue'] - -lmx.variables['title-default'] = 'ConTeXt Help Information' -lmx.variables['title'] = lmx.variables['title-default'] - -function lmx.loadedfile(filename) - return io.loaddata(resolvers.find_file(filename)) -- return resolvers.texdatablob(filename) -end - -- -- -- local interfaces = { @@ -564,7 +563,19 @@ local interfaces = { romanian = 'ro', } -local lastinterface, lastcommand, lastsource = "en", "", "" +local lastinterface, lastcommand, lastsource, lastmode = "en", "", "", 1 + +local variables = { + ['color-background-main-left'] = '#3F3F3F', + ['color-background-main-right'] = '#5F5F5F', + ['color-background-one'] = lmx.get('color-background-green'), + ['color-background-two'] = lmx.get('color-background-blue'), + ['title'] = 'ConTeXt Help Information', +} + +--~ function lmx.loadedfile(filename) +--~ return io.loaddata(resolvers.find_file(filename)) -- return resolvers.texdatablob(filename) +--~ end local function doit(configuration,filename,hashed) @@ -572,9 +583,12 @@ local function doit(configuration,filename,hashed) local start = os.clock() - local detail = aux.settings_to_hash(hashed.query or "") + local detail = url.query(hashed.query or "") - lastinterface, lastcommand, lastsource = detail.interface or lastinterface, detail.command or lastcommand, detail.source or lastsource + lastinterface = detail.interface or lastinterface + lastcommand = detail.command or lastcommand + lastsource = detail.source or lastsource + lastmode = tonumber(detail.mode or lastmode) or 1 if lastinterface then logs.simple("checking interface: %s",lastinterface) @@ -587,58 +601,61 @@ local function doit(configuration,filename,hashed) local result = { content = "error" } local names, refs, ints = document.setups.names(lastinterface), { }, { } - for k,v in ipairs(names) do - refs[k] = document.setups.formats.href:format(v[1],v[2]) + for k=1,#names do + local v = names[k] + refs[k] = formats.href_in_list[lastmode]:format(v[1],lastmode,v[2]) end - for k,v in ipairs(table.sortedkeys(interfaces)) do - ints[k] = document.setups.formats.interface:format(interfaces[v],v) + if lastmode ~= 2 then + local sorted = table.sortedkeys(interfaces) + for k=1,#sorted do + local v = sorted[k] + ints[k] = formats.interface:format(interfaces[v],lastmode,v) + end end - lmx.restore() - lmx.set('title', 'ConTeXt Help Information') - lmx.set('color-background-one', lmx.get('color-background-green')) - lmx.set('color-background-two', lmx.get('color-background-blue')) - local n = concat(refs,"<br/>") local i = concat(ints,"<br/><br/>") if div then - lmx.set('names',div:format(n)) - lmx.set('interfaces',div:format(i)) + variables.names = div:format(n) + variables.interfaces = div:format(i) else - lmx.set('names', n) - lmx.set('interfaces', i) + variables.names = n + variables.interfaces = i end -- first we need to add information about mkii/mkiv + variables.maintitle = "no definition" + variables.maintext = "" + variables.extra = "" + if document.setups.showsources and lastsource and lastsource ~= "" then -- todo: mkii, mkiv, tex (can be different) local data = io.loaddata(resolvers.find_file(lastsource)) - lmx.set('maintitle', lastsource) - lmx.set('maintext', formats.listing:format(data)) + variables.maintitle = lastsource + variables.maintext = formats.listing:format(data) lastsource = "" elseif lastcommand and lastcommand ~= "" then - local data = document.setups.collect(lastcommand,lastinterface) + local data = document.setups.collect(lastcommand,lastinterface,lastmode) if data then - lmx.set('maintitle', data.sequence) - local extra = { } - for k, v in ipairs { "environment", "category", "source" } do + local what, extra = { "environment", "category", "source", "mode" }, { } + for k=1,#what do + local v = what[k] if data[v] and data[v] ~= "" then lmx.set(v, data[v]) extra[#extra+1] = v .. ": " .. data[v] end end - lmx.set('extra', concat(extra,", ")) - lmx.set('maintext', formats.parameters:format(concat(data.parameters))) + variables.maintitle = data.sequence + variables.maintext = formats.parameters:format(concat(data.parameters)) + variables.extra = concat(extra," ") else - lmx.set('maintext', "select command") + variables.maintext = "select command" end - else - lmx.set('maintext', "no definition") end - local content = lmx.convert('context-help.lmx') + local content = lmx.convert('context-help.lmx',false,variables) logs.simple("time spent on page: %0.03f seconds",os.clock()-start) |