# HG changeset patch # User Adam Chlipala # Date 1310765109 14400 # Node ID af0d4d11c5d70575dd1a1ef2824c1db5d14814b7 # Parent 9ef6dd0df7a0b88e17776d83aabbe0a1ddd171f6 Allow HTML in tutorial comments diff -r 9ef6dd0df7a0 -r af0d4d11c5d7 doc/intro.ur --- a/doc/intro.ur Fri Jul 15 17:16:39 2011 -0400 +++ b/doc/intro.ur Fri Jul 15 17:25:09 2011 -0400 @@ -1,5 +1,7 @@ (* Introduction *) +(* This work is licensed under a Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 Unported License. *) + (* Test evaluation.... *) fun f [a] (x : a) : a = x diff -r 9ef6dd0df7a0 -r af0d4d11c5d7 src/tutorial.sml --- a/src/tutorial.sml Fri Jul 15 17:16:39 2011 -0400 +++ b/src/tutorial.sml Fri Jul 15 17:25:09 2011 -0400 @@ -48,6 +48,28 @@ val (befor, after) = Substring.position "" source + fun proseLoop source = + let + val (befor, after) = Substring.splitl (fn ch => ch <> #"&") source + in + if Substring.isEmpty after then + TextIO.outputSubstr (outf, source) + else if Substring.size after >= 8 andalso Substring.string (Substring.slice (after, 1, SOME 7)) = "amp;lt;" then + (TextIO.outputSubstr (outf, befor); + TextIO.output (outf, "<"); + proseLoop (Substring.slice (after, 8, NONE))) + else if Substring.size after >= 4 andalso Substring.string (Substring.slice (after, 1, SOME 3)) = "gt;" then + (TextIO.outputSubstr (outf, befor); + TextIO.output (outf, ">"); + proseLoop (Substring.slice (after, 4, NONE))) + else if Substring.size after >= 5 andalso Substring.string (Substring.slice (after, 1, SOME 4)) = "amp;" then + (TextIO.outputSubstr (outf, befor); + TextIO.output (outf, "&"); + proseLoop (Substring.slice (after, 5, NONE))) + else + raise Fail "Unsupported HTML escape" + end + fun loop source = let val (befor, after) = Substring.position "<span class=\"comment-delimiter\">(* </span><span class=\"comment\">" source @@ -64,7 +86,7 @@ else (TextIO.outputSubstr (outf, befor); TextIO.output (outf, "<div class=\"prose\">"); - TextIO.outputSubstr (outf, befor'); + proseLoop befor'; TextIO.output (outf, "</div>"); loop (Substring.slice (after, 49, NONE))) end