# HG changeset patch # User Adam Chlipala # Date 1310764599 14400 # Node ID 9ef6dd0df7a0b88e17776d83aabbe0a1ddd171f6 # Parent 9cb923efea4deb785ac990e8e226f8f6411b03aa Beautified tutorial HTML diff -r 9cb923efea4d -r 9ef6dd0df7a0 doc/intro.ur --- a/doc/intro.ur Fri Jul 15 16:50:55 2011 -0400 +++ b/doc/intro.ur Fri Jul 15 17:16:39 2011 -0400 @@ -1,3 +1,5 @@ +(* Introduction *) + (* Test evaluation.... *) fun f [a] (x : a) : a = x diff -r 9cb923efea4d -r 9ef6dd0df7a0 src/tutorial.sml --- a/src/tutorial.sml Fri Jul 15 16:50:55 2011 -0400 +++ b/src/tutorial.sml Fri Jul 15 17:16:39 2011 -0400 @@ -27,7 +27,7 @@ structure Tutorial :> TUTORIAL = struct -fun readAll' inf = +fun readAll inf = let fun loop acc = case TextIO.inputLine inf of @@ -38,10 +38,87 @@ before TextIO.closeIn inf end -fun readAll fname = readAll' (TextIO.openIn fname) +val readAllFile = readAll o TextIO.openIn + +fun fixupFile (fname, title) = + let + val source = readAllFile "/tmp/final.html" + val outf = TextIO.openOut (OS.Path.mkAbsolute {relativeTo = OS.FileSys.getDir (), + path = OS.Path.joinBaseExt {base = OS.Path.base fname, ext = SOME "html"}}) + + val (befor, after) = Substring.position "" source + + fun loop source = + let + val (befor, after) = Substring.position "<span class=\"comment-delimiter\">(* </span><span class=\"comment\">" source + in + if Substring.isEmpty after then + TextIO.outputSubstr (outf, source) + else + let + val (befor', after) = Substring.position " </span><span class=\"comment-delimiter\">*)</span>" + (Substring.slice (after, 64, NONE)) + in + if Substring.isEmpty after then + TextIO.outputSubstr (outf, source) + else + (TextIO.outputSubstr (outf, befor); + TextIO.output (outf, "<div class=\"prose\">"); + TextIO.outputSubstr (outf, befor'); + TextIO.output (outf, "</div>"); + loop (Substring.slice (after, 49, NONE))) + end + end + in + if Substring.isEmpty after then + raise Fail ("Missing <title> for " ^ title) + else + (TextIO.outputSubstr (outf, befor); + TextIO.output (outf, "<style type=\"text/css\">\n"); + TextIO.output (outf, "<!--\n"); + TextIO.output (outf, "\tdiv.prose {\n"); + TextIO.output (outf, "\t\tfont-family: Arial;\n"); + TextIO.output (outf, "\t\tbackground-color: #CCFFCC;\n"); + TextIO.output (outf, "\t\tborder-style: solid;\n"); + TextIO.output (outf, "\t\tpadding: 5px;\n"); + TextIO.output (outf, "\t\tfont-size: larger;\n"); + TextIO.output (outf, "\t}\n"); + TextIO.output (outf, "-->\n"); + TextIO.output (outf, "</style>\n"); + TextIO.output (outf, "<title>"); + TextIO.output (outf, title); + let + val (befor, after) = Substring.position "" after + in + if Substring.isEmpty after then + raise Fail ("Missing for " ^ title) + else + let + val (befor, after) = Substring.position "" after + in + if Substring.isEmpty after then + raise Fail ("Missing for " ^ title) + else + (TextIO.outputSubstr (outf, befor); + TextIO.output (outf, "

"); + TextIO.output (outf, title); + TextIO.output (outf, "

"); + loop (Substring.slice (after, 6, NONE))) + end + end; + TextIO.closeOut outf) + end fun doUr fname = let + val inf = TextIO.openIn fname + + val title = case TextIO.inputLine inf of + NONE => raise Fail ("No title comment at start of " ^ fname) + | SOME title => title + + val title = String.substring (title, 3, size title - 7) + val eval = TextIO.openOut "/tmp/eval.ur" val gen = TextIO.openOut "/tmp/gen.ur" @@ -115,11 +192,11 @@ end end in - doDirectives (0, readAll fname); + doDirectives (0, readAll inf); TextIO.closeOut gen; TextIO.output (eval, "\n\nfun main () : transaction page =\nreturn "); - TextIO.outputSubstr (eval, readAll "/tmp/gen.ur"); + TextIO.outputSubstr (eval, readAllFile "/tmp/gen.ur"); TextIO.output (eval, ""); TextIO.closeOut eval; @@ -127,7 +204,7 @@ let val proc = Unix.execute ("/bin/sh", ["-c", "/tmp/eval.exe /main"]) val inf = Unix.textInstreamOf proc - val s = readAll' inf + val s = readAll inf val _ = Unix.reap proc val (befor, after) = Substring.position "" s @@ -165,15 +242,13 @@ ^ "(urweb-mode) " ^ "(find-file \\\"/tmp/final.ur\\\") " ^ "(switch-to-buffer (htmlize-buffer)) " - ^ "(write-file \\\"" - ^ OS.Path.mkAbsolute {relativeTo = OS.FileSys.getDir (), - path = OS.Path.joinBaseExt {base = OS.Path.base fname, ext = SOME "html"}} - ^ "\\\") " + ^ "(write-file \\\"/tmp/final.html\\\") " ^ "(kill-emacs))\"" in eatNls befor; TextIO.closeOut outf; - ignore (OS.Process.system cmd) + ignore (OS.Process.system cmd); + fixupFile (fname, title) end end end