local gsub, sub, find = string.gsub, string.sub, string.find local concat = table.concat local formatters = string.formatters local lpegmatch = lpeg.match local setmetatableindex = table.setmetatableindex local scite = scite or { } utilities.scite = scite local report = logs.reporter("scite") local lexerroot = file.dirname(resolvers.find_file("scite-context-lexer.lua")) local knownlexers = { tex = "tex", mkiv = "tex", mkvi = "tex", mkxi = "tex", mkix = "tex", mkii = "tex", cld = "tex", lua = "lua", lfg = "lua", lus = "lua", w = "web", ww = "web", c = "cpp", h = "cpp", cpp = "cpp", hpp = "cpp", cxx = "cpp", hxx = "cpp", xml = "xml", lmx = "xml", ctx = "xml", xsl = "xml", xsd = "xml", rlx = "xml", css = "xml", dtd = "xml", bib = "bibtex", rme = "txt", -- todo: pat/hyp ori } lexer = nil -- main lexer, global (for the moment needed for themes) local function loadscitelexer() if not lexer then dir.push(lexerroot) lexer = dofile("scite-context-lexer.lua") dofile("themes/scite-context-theme.lua") dir.pop() end return lexer end local loadedlexers = setmetatableindex(function(t,k) local l = knownlexers[k] or k dir.push(lexerroot) loadscitelexer() local v = lexer.load(formatters["scite-context-lexer-%s"](l)) dir.pop() t[l] = v t[k] = v return v end) scite.loadedlexers = loadedlexers scite.knownlexers = knownlexers scite.loadscitelexer = loadscitelexer local f_fore_bold = formatters['.%s { display: inline ; font-weight: bold ; color: #%s%s%s ; }'] local f_fore_none = formatters['.%s { display: inline ; font-weight: normal ; color: #%s%s%s ; }'] local f_none_bold = formatters['.%s { display: inline ; font-weight: bold ; }'] local f_none_none = formatters['.%s { display: inline ; font-weight: normal ; }'] local f_div_class = formatters['
" }, 1 linenumber = 1 local replacer = numbered and replacer_numbered or replacer_regular if numbered then b = b + 1 buffer[b] = f_linenumber(1) end local n = #result for i=1,n,2 do local ii = i + 1 local style = result[i] local position = result[ii] local txt = sub(text,start,position-1) if ii == n then txt = gsub(txt,"[%s]+$","") end txt = lpegmatch(replacer,txt) b = b + 1 if whites[style] then buffer[b] = txt else buffer[b] = f_div_class(style,txt) end start = position end buffer[b+1] = "" buffer = concat(buffer) return buffer end local function exportcsslinenumber() return f_div_number(#tostring(linenumber)/2+1) end local htmlfile = utilities.templates.replacer([[
%dirlist%]]) function scite.converttree(sourceroot,targetroot,numbered) if lfs.isdir(sourceroot) then statistics.starttiming() local skipped = { } local noffiles = 0 dir.makedirs(targetroot) local function scan(sourceroot,targetroot) local tree = { } for name in lfs.dir(sourceroot) do if name ~= "." and name ~= ".." then local sourcename = file.join(sourceroot,name) local targetname = file.join(targetroot,name) local mode = lfs.attributes(sourcename,'mode') if mode == 'file' then local filetype = file.suffix(sourcename) local basename = file.basename(name) local targetname = file.replacesuffix(targetname,"html") if knownlexers[filetype] then report("converting file %a to %a",sourcename,targetname) scite.filetohtml(sourcename,nil,targetname,numbered) noffiles = noffiles + 1 tree[#tree+1] = f_tree_entry(file.basename(targetname),basename) else skipped[filetype] = true report("no lexer for %a",sourcename) end else dir.makedirs(targetname) scan(sourcename,targetname) tree[#tree+1] = f_tree_entry(file.join(name,"files.html"),name) end end end report("saving tree in %a",treename) local htmldata = htmlfile { dirlist = concat(tree,"\n"), styles = "", } io.savedata(file.join(targetroot,"files.html"),htmldata) end scan(sourceroot,targetroot) if next(skipped) then report("skipped filetypes: %a",table.concat(table.sortedkeys(skipped)," ")) end statistics.stoptiming() report("conversion time for %s files: %s",noffiles,statistics.elapsedtime()) end end -- scite.filetohtml("strc-sec.mkiv",nil,"e:/tmp/util-sci.html",true) -- scite.filetohtml("syst-aux.mkiv",nil,"e:/tmp/util-sci.html",true) -- scite.converttree("t:/texmf/tex/context","e:/tmp/html/context",true) return scite