Warning: this is an htmlized version!
The original is here, and the conversion rules are here. |
-- eevintros.lua - htmlize things like (find-eev-quick-intro) -- This is part of blogme3. -- Author: Eduardo Ochs <[email protected]> -- Version: 2021jan13 -- License: GPL. -- (defun e () (interactive) (find-fline "~/blogme3/eevintros.lua")) -- «.add-new-intro» (to "add-new-intro") -- «.listofintros» (to "listofintros") -- «.whats» (to "whats") -- «.htmlizeeevintro» (to "htmlizeeevintro") -- «listofintros» (to ".listofintros") -- «add-new-intro» (to ".add-new-intro") -- -- This is a list of places that need to be -- changed when a new intro is added: -- -- (find-blogme3 "anggmake.lua" "eev_intros") -- (find-blogme3 "angglisp.lua" "find_xxx_intros") -- (find-blogme3 "sexp.lua" "find-xxx-intros" "ee_intro_stems =") -- (find-blogme3 "sandwiches-defs.lua" "code_intros") -- (find-fline "~/eev-intros/README") -- (find-fline "~/eev-intros/README" "list of intros") -- (find-fline "~/eev-intros/README" "list of intros" "end of the progn") -- (find-eev "eev-intro.el" "find-eev-intro") -- (find-eev-intro) -- -- Then run this: -- (find-eev2-links) -- (find-anggfile "eev-intros/README" ";; end of the progn\n") -- makeL -- makeL-anew -- (find-fline "~/TH/L/eev-intros/") -- (find-fline "~/TH/L/eev-intros/" "find-eev-intro.html") -- (brg "~/TH/L/eev-intros/find-eev-intro.html") -- listofintros = function () -- (find-fline "~/eev-intros/README") local list = {} local lines = splitlines(ee_readfile("~/eev-intros/README")) for _,li in ipairs(lines) do local intro = li:match("^ %((find-.*-intro)%)$") if intro then table.insert(list, intro) end end return list end readintro0 = function (name) return ee_readfile("~/eev-intros/"..name) end readintro = function (name) return splitlines(readintro0(name)) end -- «whats» (to ".whats") -- We start with an array "lines" containing the lines of the intro -- file and we create an array "whats" from it. If the array "lines" -- has a title in its lines 42 and 43 like this, -- -- [42]="1.2. About Foo" -- [43]="==============" -- -- then "whats" will have this: -- -- [42]="title =" -- [43]="bar" -- -- and we will have: -- -- introlinetohtml("title =", "1.2. About Foo") = -- H1(NAME("1.2", "1.2")..htmlizeline(". About Foo")) -- introlinetohtml("bar", "==============") = -- nil -- introlinewhat = function (lines, i) local what local tit = lines[i] local bar = lines[i+1] if bar:match"^%-%-+$" then what = "title -" end if bar:match"^==+$" then what = "title =" end if not what then return end if #tit ~= #bar then print("Warning: on line "..i..","); print(tit); print(bar) end return i, what, tit, bar end introlinestowhats = function (lines) local whats = {} for i=1,#lines-1 do local j,what,tit,bar = introlinewhat(lines, i) if what then whats[i] = what; whats[i+1] = "bar" end end return whats end introlinetohtml = function (what, li) if what == nil then return htmlizeline(li).."\n" end if what == "bar" then return "" end -- local H = (what == "title =") and H1 or H2 local n,rest = li:match"^(%d[%.%d]*)(%. .*)$" if n then return H(NAME(n, n)..htmlizeline(rest)) else return H(htmlizeline(li)) end end introlinestohtml = function (lines) local whats = introlinestowhats(lines) local out = {} for i=1,#lines do table.insert(out, introlinetohtml(whats[i], lines[i])) end return table.concat(out, "") end introtohtml = function (bigstr) return introlinestohtml(splitlines(bigstr)) end -- «htmlizeeevintro» (to ".htmlizeeevintro") -- (find-blogme3 "options.lua" "htmlization_head") mdef [=[ eevintro_head 1 introname <head> <title>([$ introname]) </title> </head> ]=] -- (find-blogme3 "options.lua" "basic-options") -- (find-blogme3 "options.lua" "basic-options" "dooption_a2html =") -- (find-blogme3 "options.lua" "htmlizefile") -- (find-blogme3 "blogme3.lua" "pathto") -- (find-angg "LUA/lua50init.lua" "u8c_to_l1") htmlizeeevintro = function (fname, outfname) local introcontents = ee_readfile(fname) local introname = fnamenondirectory(fname) local head = eevintro_head(introname) local body = BODY(PRE(introtohtml(u8_to_l1(introcontents)))) writefile(outfname, sgmlify(HTML(head .. body))) end --[[ * (eepitch-lua51) * (eepitch-kill) * (eepitch-lua51) dofile "eevintros.lua" -- PPV(listofintros()) listoi = sorted(listofintros()) PPV(listoi) for _,name in ipairs(listoi) do print(name..": ") local lines = readintro(name) local whats = introlinestowhats(lines) PPV(whats) end loadblogme3() = introlinetohtml("title =", "1.2. Foo") = introlinetohtml("title -", "1.2. Foo") = introlinetohtml("bar", "1.2. Foo") = introlinetohtml(nil, "1.2. Foo") * (eepitch-lua51) * (eepitch-kill) * (eepitch-lua51) loadblogme3() dofile "eevintros.lua" htmlizeeevintro("~/eev-intros/find-eev-quick-intro", "/tmp/o.html") -- file:///tmp/o.html * (eepitch-shell) * (eepitch-kill) * (eepitch-shell) cd rm -v /tmp/o.html # lua51 blogme3/blogme3.lua -o e/lua5.e.html -a2html e/lua5.e lua51 blogme3/blogme3.lua -o /tmp/o.html -ei2html ~/eev-intros/find-eev-quick-intro lua51 blogme3/blogme3.lua -o /tmp/o.html -ei2html eev-intros/find-eev-quick-intro -- file:///tmp/o.html --]]