Warning: this is an htmlized version!
The original is here, and the conversion rules are here. |
-- anggdefs.lua: some "def"s from blogme3, ported to blogme4. -- This file: -- http://angg.twu.net/blogme4/anggdefs.lua.html -- http://angg.twu.net/blogme4/anggdefs.lua -- (find-blogme4file "anggdefs.lua") -- Author: Eduardo Ochs <[email protected]> -- Version: 2011feb17 -- License: GPL3 -- «.chars» (to "chars") -- «.Q» (to "Q") -- «.htmlize» (to "htmlize") -- «.htmlization_warning» (to "htmlization_warning") -- «.htmlizefile» (to "htmlizefile") require "common" -- (find-blogme4 "common.lua") require "def" -- (find-blogme4 "def.lua") require "elisp" -- (find-blogme4 "elisp.lua") require "angglisp" -- (find-blogme4 "angglisp.lua") -- Blogme words whose argparser is 1Q (or 2Q, 3Q...) quote their -- arguments - i.e., the [] blocks in it are not evaluated. -- (find-blogme4 "eval.lua" "qlongwords") -- (find-blogme4 "eval.lua" "readqword") -- (find-blogme4 "eval.lua" "_A") eval_statements = function (str) return assert(loadstring(str, str))() end eval_expr = function (str) return assert(loadstring("return "..str, str))() end def [[ ' 1Q body body ]] -- for lua-mode.el: ' def [[ lua: 1Q code eval_statements(code) ]] def [[ expr: 1Q code eval_expr(code) ]] def [[ # 0 _ "" ]] -- Remember that "def" & friends use "undollar", which expands all -- substrings of the form "$varname" in the body code. -- (find-blogme4 "def.lua" "undollar") -- (find-blogme3 "anggdefs.lua" "basic-words-for-html") def [[ J 1 text text ]] def [[ HREF 2 url,str "<a href=\"$url\">$str</a>" ]] def [[ H1 1 str "<h1>$str</h1>\n" ]] def [[ H2 1 str "<h2>$str</h2>\n" ]] def [[ H3 1 str "<h3>$str</h3>\n" ]] def [[ H4 1 str "<h4>$str</h4>\n" ]] def [[ H5 1 str "<h5>$str</h5>\n" ]] def [[ H6 1 str "<h6>$str</h6>\n" ]] def [[ BF 1 str "<strong>$str</strong>" ]] def [[ IT 1 str "<i>$str</i>" ]] def [[ RM 1 str "</i>$str<i>" ]] def [[ TT 1 str "<code>$str</code>" ]] def [[ EM 1 str "<em>$str</em>" ]] def [[ PRE 1 str "<pre>$str</pre>" ]] def [[ SMALL 1 body "<small>$body</small>" ]] def [[ NAME 2 tag,str "<a name=\"$tag\">$str</a>" ]] def [[ COLOR 2 color,str "<font color=\"$color\">$str</font>" ]] def [[ IMG 2 url,alt "<img src=\"$url\" alt=\"$alt\" border=0>\n" ]] def [[ IMAGE 2 url,alt HREF(url, "<br>"..IMG(url,alt)) ]] def [[ SCALEDIMAGE 2 perc,image "<a href=\"$image\">" .. "<img src=\"$image\" width=\"$perc\" height=\"$perc\" border=0>" .. "</a>" ]] def_ [[ P 1 str "\n\n<p>$str</p>" ]] -- (find-blogme3 "anggdefs.lua" "headers") def [[ TITLE 1 str "<title>$str</title>\n" ]] def [[ HEAD 1 str "<head>\n$str</head>\n" ]] def [[ BODY 1 str "<body>\n$str\n</body>\n" ]] def [[ HTML 1 str "<html>\n$str</html>\n" ]] html_dtd =[[ <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> ]] -- (find-wdg40w3m "html/doctype.html") html_style = "" -- (find-wdg40w3m "head/head.html" "STYLE") html_meta = "" -- (find-wdg40w3m "head/head.html" "META") html_favicon = "" -- http://www.favicon.cc/ html_speedbar = "" -- (find-TH "speedbar") -- (find-THfile "speedbar.blogme") def [[ TITLEDHTML 2 title,body html_dtd.. HTML(HEAD(TITLE(title)..html_meta..html_style).."\n".. BODY(body)) ]] -- «chars» (to ".chars") -- (find-blogme3 "charset.lua") -- (find-equailfile "sgml-input.el") latin1_pairs = [[ Æ AElig Á Aacute  Acirc À Agrave Å Aring à Atilde Ä Auml Ç Ccedil É Eacute Ê Ecirc È Egrave Ë Euml Í Iacute Ï Iuml Ó Oacute Ô Ocirc Ò Ograve Õ Otilde Ö Ouml Ú Uacute Û Ucirc Ù Ugrave Ü Uuml á aacute â acirc æ aelig à agrave å aring ã atilde ä auml ç ccedil é eacute ê ecirc è egrave ë euml í iacute î icirc ì igrave ï iuml ó oacute ô ocirc ò ograve õ otilde ö ouml ß szlig ú uacute û ucirc ù ugrave ü uuml ª ordf « laquo ° deg º ordm » raquo Ñ Ntilde ñ ntilde × times ]] -- «Q» (to ".Q") -- (find-blogme3 "anggdefs.lua" "Q") -- Q_re = "([&<>])" Q_re = "([\001-\008\011-\031&<>\127-\255])" Q_table = { ["&"]="&", ["<"]="<", [">"]=">" } Q_table["\15"] = "<font color=\"red\"><strong>*</strong></font>" Q_table["\171"] = "<font color=\"green\"><i>«</i></font>" Q_table["\187"] = "<font color=\"green\"><i>»</i></font>" for c,cname in each2(split(latin1_pairs)) do Q_table[c] = "&"..cname..";" end -- (find-angg "LUA/lua50init.lua" "translatechars") def [[ Q 1 text translatechars(text, Q_re, Q_table) ]] -- «htmlize» (to ".htmlize") -- (find-blogme4 "options.lua" "dooption_i") Def [[ htmlize 2 title,body blogme_output = TITLEDHTML(title, H2(title)..body) ]] -- «htmlization_warning» (to ".htmlization_warning") -- (find-blogme3 "options.lua" "htmlization_warning") def [=[ htmlization_head 1 fname [[ <head> <title>$[fname] (htmlized) </title> </head> ]] ]=] def [=[ htmlization_warning_ 2 original,htmlizer [[ <table><tr><td bgcolor="#CC0000"><font color="#FFCC00" size=-1> Warning: this is an htmlized version! <br>The original is across <a href="$[original]">this link</a>, <br>and the conversion rules are <a href="$[htmlizer]">here</a>. </font></td></tr></table> ]] ]=] def [[ htmlization_warning 1 fname htmlization_warning_( fnamenondirectory(fname), pathto "blogme3/escripts.lua.html" ) ]] -- (find-blogme3 "options.lua" "htmlization_head") -- htmlizeline = function (line) return htmlizeline_(Q, line) end -- htmlizelines = function (bigstr) -- -- local htmlizeline = function (line) htmlizeline_(Q, line) end -- -- return maplines(htmlizeline, bigstr) -- return bigstr:gsub("[^\n]*", htmlizeline) -- end --------[ htmlizefile ]-------- -- «htmlizefile» (to ".htmlizefile") -- (find-blogme4 "options.lua" "dooption_a2html") -- (find-blogme3 "options.lua" "htmlizefile") htmlizefile_ = function (fname, fcontents, htmlizer) htmlizer = htmlizer or htmlizelines local fnamestem = fnamenondirectory(fname) local warning = htmlization_warning(fname) local head = htmlization_head(fname) local body = BODY(warning .. PRE(htmlizer(fcontents))) return HTML(head .. body) end htmlizefile = function (fname, outfname, htmlizer) local fcontents = readfile(fname) outfname = outfname or fname..".html" writefile(outfname, htmlizefile_(fname, fcontents, htmlizer)) end -- The "new way" to define "htmlize" flexibly in blogme3 (allowing for -- a speedbar, a favicon, CSS, META, etc, with less headaches than in -- the "previous way") uses something like the messy chunk of code -- below... I am not using it in demo.lua at the moment (note that -- htmlize is redefined there, to something simpler). --[=[ def [[ html_head 1 title HEAD(TITLE(title)..html_meta.. html_favicon..html_style) ]] def [[ html_body_0 2 title,body H3(Q(title)).."\n"..body ]] def [[ html_body_1 2 title,body DIV(BORDERLESSBOX(html_body_0(title,body))) ]] def [[ html_body_2 2 title,body html_speedbar..html_body_1(title,body) ]] def [[ html_body 2 title,body html_body_0(title, body) ]] def [[ html_all 2 title,body html_dtd.. HTML(html_head(title).."\n".. BODY(html_body(title,body))) ]] def [[ htmlize 2 title,body set("blogme_output", html_all(title, body)) ]] def [[ htmlize 2 title,body set("blogme_output", sgmlify(html_all(title, body))) ]] -- sgmlify can be found here: (find-blogme3 "charset.lua") -- Example: [SETHEADSTYLE h3 { background-color: orange; }] def [[ HEADSTYLE 1 styles "<style type=\"text/css\"><!--\n$styles -->\n</style>\n" ]] Def [[ SETHEADSTYLE 1 styles html_style = HEADSTYLE(styles) ]] Def [[ SETFAVICON 1 url html_favicon = "<link rel=\"shortcut icon\" href=\"$url\" />\n" ]] --]=] -- dump-to: tests --[==[ * (eepitch-lua51) * (eepitch-kill) * (eepitch-lua51) require "anggdefs" = Q "foo&<>;" = Q "foo&<>\015\225" = htmlizefile_("Fname", [[foo\n bar (find-angg "hi")]]) -- (find-blogme4 "argparsers.lua") --]==] -- Local Variables: -- coding: raw-text-unix -- ee-anchor-format: "«%s»" -- End: