| author | wenzelm | 
| Sat, 16 Sep 2017 15:35:56 +0200 | |
| changeset 66668 | 6019cfb8256c | 
| parent 66044 | bd7516709051 | 
| child 67306 | 897344e33c26 | 
| permissions | -rw-r--r-- | 
| 24584 | 1 | (* Title: Pure/Thy/html.ML | 
| 9415 | 2 | Author: Markus Wenzel and Stefan Berghofer, TU Muenchen | 
| 6324 | 3 | |
| 9415 | 4 | HTML presentation elements. | 
| 6324 | 5 | *) | 
| 6 | ||
| 7 | signature HTML = | |
| 8 | sig | |
| 61381 | 9 | type symbols | 
| 10 | val make_symbols: (string * int) list -> symbols | |
| 11 | val no_symbols: symbols | |
| 12 | val present_span: symbols -> Keyword.keywords -> Command_Span.span -> Output.output | |
| 23622 | 13 | type text = string | 
| 61381 | 14 | val begin_document: symbols -> string -> text | 
| 23724 | 15 | val end_document: text | 
| 61381 | 16 | val begin_session_index: symbols -> string -> Url.T -> (Url.T * string) list -> text | 
| 17 | val theory_entry: symbols -> Url.T * string -> text | |
| 18 | val theory: symbols -> string -> (Url.T option * string) list -> text -> text | |
| 6324 | 19 | end; | 
| 20 | ||
| 21 | structure HTML: HTML = | |
| 22 | struct | |
| 23 | ||
| 24 | ||
| 33985 | 25 | (* common markup *) | 
| 26 | ||
| 27 | fun span class = ("<span class=" ^ quote (XML.text class) ^ ">", "</span>");
 | |
| 66044 | 28 | val enclose_span = uncurry enclose o span; | 
| 33985 | 29 | |
| 66044 | 30 | val hidden = enclose_span Markup.hiddenN; | 
| 33985 | 31 | |
| 32 | ||
| 6324 | 33 | (* symbol output *) | 
| 34 | ||
| 61381 | 35 | abstype symbols = Symbols of string Symtab.table | 
| 36 | with | |
| 37 | ||
| 38 | fun make_symbols codes = | |
| 39 | let | |
| 40 | val mapping = | |
| 63806 | 41 | map (apsnd (fn c => "&#" ^ Value.print_int c ^ ";")) codes @ | 
| 61381 | 42 |        [("'", "'"),
 | 
| 62529 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
61381diff
changeset | 43 |         ("\<^bsub>", hidden "⇘" ^ "<sub>"),
 | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
61381diff
changeset | 44 |         ("\<^esub>", hidden "⇙" ^ "</sub>"),
 | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
61381diff
changeset | 45 |         ("\<^bsup>", hidden "⇗" ^ "<sup>"),
 | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
61381diff
changeset | 46 |         ("\<^esup>", hidden "⇖" ^ "</sup>")];
 | 
| 61381 | 47 | in Symbols (fold Symtab.update mapping Symtab.empty) end; | 
| 48 | ||
| 49 | val no_symbols = make_symbols []; | |
| 50 | ||
| 51 | fun output_sym (Symbols tab) s = | |
| 63934 | 52 | (case Symtab.lookup tab s of | 
| 53 | SOME x => x | |
| 54 | | NONE => XML.text s); | |
| 61381 | 55 | |
| 56 | end; | |
| 57 | ||
| 6338 | 58 | local | 
| 61376 
93224745477f
output HTML text according to Isabelle/Scala Symbol.Interpretation;
 wenzelm parents: 
61374diff
changeset | 59 | |
| 61381 | 60 | fun output_markup (bg, en) symbols s1 s2 = | 
| 61 | hidden s1 ^ enclose bg en (output_sym symbols s2); | |
| 61376 
93224745477f
output HTML text according to Isabelle/Scala Symbol.Interpretation;
 wenzelm parents: 
61374diff
changeset | 62 | |
| 
93224745477f
output HTML text according to Isabelle/Scala Symbol.Interpretation;
 wenzelm parents: 
61374diff
changeset | 63 | val output_sub = output_markup ("<sub>", "</sub>");
 | 
| 
93224745477f
output HTML text according to Isabelle/Scala Symbol.Interpretation;
 wenzelm parents: 
61374diff
changeset | 64 | val output_sup = output_markup ("<sup>", "</sup>");
 | 
| 
93224745477f
output HTML text according to Isabelle/Scala Symbol.Interpretation;
 wenzelm parents: 
61374diff
changeset | 65 | val output_bold = output_markup (span "bold"); | 
| 17178 | 66 | |
| 61381 | 67 | fun output_syms _ [] result = implode (rev result) | 
| 68 | | output_syms symbols (s1 :: rest) result = | |
| 61376 
93224745477f
output HTML text according to Isabelle/Scala Symbol.Interpretation;
 wenzelm parents: 
61374diff
changeset | 69 | let | 
| 
93224745477f
output HTML text according to Isabelle/Scala Symbol.Interpretation;
 wenzelm parents: 
61374diff
changeset | 70 |         val (s2, ss) = (case rest of [] => ("", []) | s2 :: ss => (s2, ss));
 | 
| 61381 | 71 | val (s, r) = | 
| 62529 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
61381diff
changeset | 72 | if s1 = "\<^sub>" then (output_sub symbols "⇩" s2, ss) | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
61381diff
changeset | 73 | else if s1 = "\<^sup>" then (output_sup symbols "⇧" s2, ss) | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
61381diff
changeset | 74 | else if s1 = "\<^bold>" then (output_bold symbols "❙" s2, ss) | 
| 61381 | 75 | else (output_sym symbols s1, rest); | 
| 76 | in output_syms symbols r (s :: result) end; | |
| 14534 | 77 | |
| 6338 | 78 | in | 
| 6324 | 79 | |
| 61381 | 80 | fun output symbols str = output_syms symbols (Symbol.explode str) []; | 
| 61376 
93224745477f
output HTML text according to Isabelle/Scala Symbol.Interpretation;
 wenzelm parents: 
61374diff
changeset | 81 | |
| 6338 | 82 | end; | 
| 83 | ||
| 6324 | 84 | |
| 61379 
c57820ceead3
more direct HTML presentation, without print mode;
 wenzelm parents: 
61376diff
changeset | 85 | (* presentation *) | 
| 
c57820ceead3
more direct HTML presentation, without print mode;
 wenzelm parents: 
61376diff
changeset | 86 | |
| 61381 | 87 | fun present_span symbols keywords = | 
| 88 | let | |
| 66044 | 89 | fun present_markup (name, props) = | 
| 90 | (case Properties.get props Markup.kindN of | |
| 91 | SOME kind => | |
| 92 | if kind = Markup.commandN orelse kind = Markup.keywordN then enclose_span kind else I | |
| 93 | | NONE => I) #> enclose_span name; | |
| 61381 | 94 | fun present_token tok = | 
| 66044 | 95 | fold_rev present_markup (Token.markups keywords tok) | 
| 96 | (output symbols (Token.unparse tok)); | |
| 61381 | 97 | in implode o map present_token o Command_Span.content end; | 
| 61379 
c57820ceead3
more direct HTML presentation, without print mode;
 wenzelm parents: 
61376diff
changeset | 98 | |
| 
c57820ceead3
more direct HTML presentation, without print mode;
 wenzelm parents: 
61376diff
changeset | 99 | |
| 6324 | 100 | |
| 101 | (** HTML markup **) | |
| 102 | ||
| 103 | type text = string; | |
| 104 | ||
| 105 | ||
| 106 | (* atoms *) | |
| 107 | ||
| 61381 | 108 | val name = enclose "<span class=\"name\">" "</span>" oo output; | 
| 109 | val keyword = enclose "<span class=\"keyword\">" "</span>" oo output; | |
| 110 | val command = enclose "<span class=\"command\">" "</span>" oo output; | |
| 6324 | 111 | |
| 112 | ||
| 113 | (* misc *) | |
| 114 | ||
| 28840 | 115 | fun href_name s txt = "<a href=" ^ quote s ^ ">" ^ txt ^ "</a>"; | 
| 21858 
05f57309170c
avoid conflict with Alice keywords: renamed pack -> implode, unpack -> explode, any -> many, avoided assert;
 wenzelm parents: 
20742diff
changeset | 116 | fun href_path path txt = href_name (Url.implode path) txt; | 
| 6376 | 117 | |
| 15531 | 118 | fun href_opt_path NONE txt = txt | 
| 119 | | href_opt_path (SOME p) txt = href_path p txt; | |
| 6376 | 120 | |
| 12413 | 121 | fun para txt = "\n<p>" ^ txt ^ "</p>\n"; | 
| 6324 | 122 | |
| 123 | ||
| 124 | (* document *) | |
| 125 | ||
| 61381 | 126 | fun begin_document symbols title = | 
| 62529 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
61381diff
changeset | 127 | "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n" ^ | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
61381diff
changeset | 128 | "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" " ^ | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
61381diff
changeset | 129 | "\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n" ^ | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
61381diff
changeset | 130 | "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n" ^ | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
61381diff
changeset | 131 | "<head>\n" ^ | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
61381diff
changeset | 132 | "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/>\n" ^ | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
61381diff
changeset | 133 |   "<title>" ^ output symbols (title ^ " (" ^ Distribution.version ^ ")") ^ "</title>\n" ^
 | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
61381diff
changeset | 134 | "<link media=\"all\" rel=\"stylesheet\" type=\"text/css\" href=\"isabelle.css\"/>\n" ^ | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
61381diff
changeset | 135 | "</head>\n" ^ | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
61381diff
changeset | 136 | "\n" ^ | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
61381diff
changeset | 137 | "<body>\n" ^ | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
61381diff
changeset | 138 | "<div class=\"head\">" ^ | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
61381diff
changeset | 139 | "<h1>" ^ output symbols title ^ "</h1>\n"; | 
| 6324 | 140 | |
| 14541 | 141 | val end_document = "\n</div>\n</body>\n</html>\n"; | 
| 6324 | 142 | |
| 6338 | 143 | |
| 144 | (* session index *) | |
| 145 | ||
| 61381 | 146 | fun begin_session_index symbols session graph docs = | 
| 147 |   begin_document symbols ("Session " ^ output symbols session) ^
 | |
| 6754 | 148 |   para ("View " ^ href_path graph "theory dependencies" ^
 | 
| 27829 | 149 | implode (map (fn (p, name) => "<br/>\nView " ^ href_path p name) docs)) ^ | 
| 37941 
1d812ff95a14
refrain from generating <hr/> and from "hiding" it in isabelle.css -- the latter might be used in other situations as well;
 wenzelm parents: 
37940diff
changeset | 150 | "\n</div>\n<div class=\"theories\">\n<h2>Theories</h2>\n<ul>\n"; | 
| 6338 | 151 | |
| 61381 | 152 | fun theory_entry symbols (p, s) = "<li>" ^ href_path p (output symbols s) ^ "</li>\n"; | 
| 6324 | 153 | |
| 154 | ||
| 155 | (* theory *) | |
| 156 | ||
| 61381 | 157 | fun theory symbols A Bs txt = | 
| 158 |   begin_document symbols ("Theory " ^ A) ^ "\n" ^
 | |
| 159 | command symbols "theory" ^ " " ^ name symbols A ^ "<br/>\n" ^ | |
| 160 | keyword symbols "imports" ^ " " ^ | |
| 161 | space_implode " " (map (uncurry href_opt_path o apsnd (name symbols)) Bs) ^ | |
| 54456 | 162 | "<br/>\n" ^ | 
| 61374 | 163 | enclose "\n</div>\n<div class=\"source\">\n<pre class=\"source\">" "</pre>\n" txt ^ | 
| 54456 | 164 | end_document; | 
| 16267 
0773b17922d8
present new-style theory header, with 'imports' and 'uses';
 wenzelm parents: 
16196diff
changeset | 165 | |
| 6324 | 166 | end; |