--- a/src/Pure/Thy/html.ML Fri Oct 09 17:15:53 2015 +0200
+++ b/src/Pure/Thy/html.ML Fri Oct 09 19:25:13 2015 +0200
@@ -7,6 +7,8 @@
signature HTML =
sig
val html_mode: ('a -> 'b) -> 'a -> 'b
+ val reset_symbols: unit -> unit
+ val init_symbols: (string * int) list -> unit
type text = string
val plain: string -> text
val name: string -> text
@@ -45,179 +47,41 @@
(* symbol output *)
local
- val hidden = span Markup.hiddenN |-> enclose;
+
+val hidden = span Markup.hiddenN |-> enclose;
+
+val symbols =
+ Synchronized.var "HTML.symbols" (NONE: (int * string) Symtab.table option);
+
+fun output_sym s =
+ if Symbol.is_raw s then (1, Symbol.decode_raw s)
+ else
+ (case Synchronized.value symbols of
+ SOME tab =>
+ (case Symtab.lookup tab s of
+ SOME x => x
+ | NONE => (size s, XML.text s))
+ | NONE => raise Fail "Missing HTML.init_symbols: cannot output symbols");
- (* FIXME proper unicode -- produced on Scala side *)
- val html_syms = Symtab.make
- [("", (0, "")),
- ("'", (1, "'")),
- ("\\<exclamdown>", (1, "¡")),
- ("\\<cent>", (1, "¢")),
- ("\\<pounds>", (1, "£")),
- ("\\<currency>", (1, "¤")),
- ("\\<yen>", (1, "¥")),
- ("\\<bar>", (1, "¦")),
- ("\\<section>", (1, "§")),
- ("\\<dieresis>", (1, "¨")),
- ("\\<copyright>", (1, "©")),
- ("\\<ordfeminine>", (1, "ª")),
- ("\\<guillemotleft>", (1, "«")),
- ("\\<not>", (1, "¬")),
- ("\\<hyphen>", (1, "­")),
- ("\\<registered>", (1, "®")),
- ("\\<inverse>", (1, "¯")),
- ("\\<degree>", (1, "°")),
- ("\\<plusminus>", (1, "±")),
- ("\\<acute>", (1, "´")),
- ("\\<paragraph>", (1, "¶")),
- ("\\<cdot>", (1, "·")),
- ("\\<cedilla>", (1, "¸")),
- ("\\<ordmasculine>", (1, "º")),
- ("\\<guillemotright>", (1, "»")),
- ("\\<onequarter>", (1, "¼")),
- ("\\<onehalf>", (1, "½")),
- ("\\<threequarters>", (1, "¾")),
- ("\\<questiondown>", (1, "¿")),
- ("\\<times>", (1, "×")),
- ("\\<div>", (1, "÷")),
- ("\\<circ>", (1, "o")),
- ("\\<Alpha>", (1, "Α")),
- ("\\<Beta>", (1, "Β")),
- ("\\<Gamma>", (1, "Γ")),
- ("\\<Delta>", (1, "Δ")),
- ("\\<Epsilon>", (1, "Ε")),
- ("\\<Zeta>", (1, "Ζ")),
- ("\\<Eta>", (1, "Η")),
- ("\\<Theta>", (1, "Θ")),
- ("\\<Iota>", (1, "Ι")),
- ("\\<Kappa>", (1, "Κ")),
- ("\\<Lambda>", (1, "Λ")),
- ("\\<Mu>", (1, "Μ")),
- ("\\<Nu>", (1, "Ν")),
- ("\\<Xi>", (1, "Ξ")),
- ("\\<Omicron>", (1, "Ο")),
- ("\\<Pi>", (1, "Π")),
- ("\\<Rho>", (1, "Ρ")),
- ("\\<Sigma>", (1, "Σ")),
- ("\\<Tau>", (1, "Τ")),
- ("\\<Upsilon>", (1, "Υ")),
- ("\\<Phi>", (1, "Φ")),
- ("\\<Chi>", (1, "Χ")),
- ("\\<Psi>", (1, "Ψ")),
- ("\\<Omega>", (1, "Ω")),
- ("\\<alpha>", (1, "α")),
- ("\\<beta>", (1, "β")),
- ("\\<gamma>", (1, "γ")),
- ("\\<delta>", (1, "δ")),
- ("\\<epsilon>", (1, "ε")),
- ("\\<zeta>", (1, "ζ")),
- ("\\<eta>", (1, "η")),
- ("\\<theta>", (1, "ϑ")),
- ("\\<iota>", (1, "ι")),
- ("\\<kappa>", (1, "κ")),
- ("\\<lambda>", (1, "λ")),
- ("\\<mu>", (1, "μ")),
- ("\\<nu>", (1, "ν")),
- ("\\<xi>", (1, "ξ")),
- ("\\<omicron>", (1, "ο")),
- ("\\<pi>", (1, "π")),
- ("\\<rho>", (1, "ρ")),
- ("\\<sigma>", (1, "σ")),
- ("\\<tau>", (1, "τ")),
- ("\\<upsilon>", (1, "υ")),
- ("\\<phi>", (1, "φ")),
- ("\\<chi>", (1, "χ")),
- ("\\<psi>", (1, "ψ")),
- ("\\<omega>", (1, "ω")),
- ("\\<bullet>", (1, "•")),
- ("\\<dots>", (1, "…")),
- ("\\<wp>", (1, "℘")),
- ("\\<forall>", (1, "∀")),
- ("\\<partial>", (1, "∂")),
- ("\\<exists>", (1, "∃")),
- ("\\<emptyset>", (1, "∅")),
- ("\\<nabla>", (1, "∇")),
- ("\\<in>", (1, "∈")),
- ("\\<notin>", (1, "∉")),
- ("\\<Prod>", (1, "∏")),
- ("\\<Sum>", (1, "∑")),
- ("\\<star>", (1, "∗")),
- ("\\<propto>", (1, "∝")),
- ("\\<infinity>", (1, "∞")),
- ("\\<angle>", (1, "∠")),
- ("\\<and>", (1, "∧")),
- ("\\<or>", (1, "∨")),
- ("\\<inter>", (1, "∩")),
- ("\\<union>", (1, "∪")),
- ("\\<sim>", (1, "∼")),
- ("\\<cong>", (1, "≅")),
- ("\\<approx>", (1, "≈")),
- ("\\<noteq>", (1, "≠")),
- ("\\<equiv>", (1, "≡")),
- ("\\<le>", (1, "≤")),
- ("\\<ge>", (1, "≥")),
- ("\\<subset>", (1, "⊂")),
- ("\\<supset>", (1, "⊃")),
- ("\\<subseteq>", (1, "⊆")),
- ("\\<supseteq>", (1, "⊇")),
- ("\\<oplus>", (1, "⊕")),
- ("\\<otimes>", (1, "⊗")),
- ("\\<bottom>", (1, "⊥")),
- ("\\<lceil>", (1, "⌈")),
- ("\\<rceil>", (1, "⌉")),
- ("\\<lfloor>", (1, "⌊")),
- ("\\<rfloor>", (1, "⌋")),
- ("\\<langle>", (1, "⟨")),
- ("\\<rangle>", (1, "⟩")),
- ("\\<lozenge>", (1, "◊")),
- ("\\<spadesuit>", (1, "♠")),
- ("\\<clubsuit>", (1, "♣")),
- ("\\<heartsuit>", (1, "♥")),
- ("\\<diamondsuit>", (1, "♦")),
- ("\\<lbrakk>", (2, "[|")),
- ("\\<rbrakk>", (2, "|]")),
- ("\\<Longrightarrow>", (3, "==>")),
- ("\\<Rightarrow>", (2, "=>")),
- ("\\<And>", (2, "!!")),
- ("\\<Colon>", (2, "::")),
- ("\\<lparr>", (2, "(|")),
- ("\\<rparr>", (2, "|)),")),
- ("\\<longleftrightarrow>", (3, "<->")),
- ("\\<longrightarrow>", (3, "-->")),
- ("\\<rightarrow>", (2, "->")),
- ("\\<open>", (1, "‹")),
- ("\\<close>", (1, "›")),
- ("\\<newline>", (1, "⏎")),
- ("\\<^bsub>", (0, hidden "⇘" ^ "<sub>")),
- ("\\<^esub>", (0, hidden "⇙" ^ "</sub>")),
- ("\\<^bsup>", (0, hidden "⇗" ^ "<sup>")),
- ("\\<^esup>", (0, hidden "⇖" ^ "</sup>"))];
+fun output_markup (bg, en) s1 s2 =
+ let val (n, txt) = output_sym s2
+ in (n, hidden s1 ^ enclose bg en txt) end;
+
+val output_sub = output_markup ("<sub>", "</sub>");
+val output_sup = output_markup ("<sup>", "</sup>");
+val output_bold = output_markup (span "bold");
- fun output_sym s =
- if Symbol.is_raw s then (1, Symbol.decode_raw s)
- else
- (case Symtab.lookup html_syms s of
- SOME x => x
- | NONE => (size s, XML.text s));
-
- fun output_markup (bg, en) s1 s2 =
- let val (n, txt) = output_sym s2
- in (n, hidden s1 ^ enclose bg en txt) end;
+fun output_syms [] (result, width) = (implode (rev result), width)
+ | output_syms (s1 :: rest) (result, width) =
+ let
+ val (s2, ss) = (case rest of [] => ("", []) | s2 :: ss => (s2, ss));
+ val ((w, s), r) =
+ if s1 = "\\<^sub>" then (output_sub "⇩" s2, ss)
+ else if s1 = "\\<^sup>" then (output_sup "⇧" s2, ss)
+ else if s1 = "\\<^bold>" then (output_bold "❙" s2, ss)
+ else (output_sym s1, rest);
+ in output_syms r (s :: result, width + w) end;
- val output_sub = output_markup ("<sub>", "</sub>");
- val output_sup = output_markup ("<sup>", "</sup>");
- val output_bold = output_markup (span "bold");
-
- fun output_syms [] (result, width) = (implode (rev result), width)
- | output_syms (s1 :: rest) (result, width) =
- let
- val (s2, ss) = (case rest of [] => ("", []) | s2 :: ss => (s2, ss));
- val ((w, s), r) =
- if s1 = "\\<^sub>" then (output_sub "⇩" s2, ss)
- else if s1 = "\\<^sup>" then (output_sup "⇧" s2, ss)
- else if s1 = "\\<^bold>" then (output_bold "❙" s2, ss)
- else (output_sym s1, rest);
- in output_syms r (s :: result, width + w) end;
in
fun output_width str = output_syms (Symbol.explode str) ([], 0);
@@ -225,6 +89,21 @@
val _ = Output.add_mode htmlN output_width Symbol.encode_raw;
+
+fun reset_symbols () = Synchronized.change symbols (K NONE);
+
+fun init_symbols codes =
+ let
+ val mapping =
+ map (fn (s, c) => (s, (Symbol.length [s], "&#" ^ Markup.print_int c ^ ";"))) codes @
+ [("", (0, "")),
+ ("'", (1, "'")),
+ ("\\<^bsub>", (0, hidden "⇘" ^ "<sub>")),
+ ("\\<^esub>", (0, hidden "⇙" ^ "</sub>")),
+ ("\\<^bsup>", (0, hidden "⇗" ^ "<sup>")),
+ ("\\<^esup>", (0, hidden "⇖" ^ "</sup>"))];
+ in Synchronized.change symbols (K (SOME (fold Symtab.update mapping Symtab.empty))) end;
+
end;