From 7cfc4e5146be5666419451bdd516f1f3f264d24a Mon Sep 17 00:00:00 2001 From: Enrico Tassi Date: Sun, 25 Jan 2015 14:42:51 +0100 Subject: Imported Upstream version 8.5~beta1+dfsg --- tools/coqdoc/output.ml | 92 ++++++++++++++++++++++++++++++++++---------------- 1 file changed, 62 insertions(+), 30 deletions(-) (limited to 'tools/coqdoc/output.ml') diff --git a/tools/coqdoc/output.ml b/tools/coqdoc/output.ml index 2d29c447..ae6e6388 100644 --- a/tools/coqdoc/output.ml +++ b/tools/coqdoc/output.ml @@ -1,6 +1,6 @@ (************************************************************************) (* v * The Coq Proof Assistant / The Coq Development Team *) -(* () | Some n -> printf "\\setcounter{tocdepth}{%i}\n" n); @@ -383,6 +385,14 @@ module Latex = struct end; last_was_in := false + let sublexer_in_doc c = + if c = '*' && !last_was_in then begin + Tokens.flush_sublexer (); + output_char '*' + end else + Tokens.output_tagged_symbol_char None c; + last_was_in := false + let initialize () = initialize_tex_html (); Tokens.token_tree := token_tree_latex; @@ -399,8 +409,11 @@ module Latex = struct let ident s loc = last_was_in := s = "in"; try - let tag = Index.find (get_module false) loc in - reference (translate s) tag + match loc with + | None -> raise Not_found + | Some loc -> + let tag = Index.find (get_module false) loc in + reference (translate s) tag with Not_found -> if is_tactic s then printf "\\coqdoctac{%s}" (translate s) @@ -522,8 +535,8 @@ module Html = struct printf "\n"; printf "\n\n"; - printf "\n" !charset; - printf "\n"; + printf "\n" !charset; + printf "\n"; printf "%s\n\n\n" !page_title; printf "\n\n
\n\n
\n
\n\n"; printf "
\n\n" @@ -558,7 +571,7 @@ module Html = struct printf "

%s %s

\n\n" ln (get_module true) end - let indentation n = for i = 1 to n do printf " " done + let indentation n = for _i = 1 to n do printf " " done let line_break () = printf "
\n" @@ -573,9 +586,6 @@ module Html = struct | '&' -> printf "&" | c -> output_char c - let raw_string s = - for i = 0 to String.length s - 1 do char s.[i] done - let escaped = let buff = Buffer.create 5 in fun s -> @@ -585,10 +595,24 @@ module Html = struct | '<' -> Buffer.add_string buff "<" | '>' -> Buffer.add_string buff ">" | '&' -> Buffer.add_string buff "&" + | '\'' -> Buffer.add_string buff "´" + | '\"' -> Buffer.add_string buff """ | c -> Buffer.add_char buff c done; Buffer.contents buff + let sanitize_name s = + let rec loop esc i = + if i < 0 then if esc then escaped s else s + else match s.[i] with + | 'a'..'z' | 'A'..'Z' | '0'..'9' | '.' | '_' -> loop esc (i-1) + | '<' | '>' | '&' | '\'' | '\"' -> loop true (i-1) + | _ -> + (* This name contains complex characters: + this is probably a notation string, we simply hash it. *) + Digest.to_hex (Digest.string s) + in loop false (String.length s - 1) + let latex_char _ = () let latex_string _ = () @@ -618,19 +642,19 @@ module Html = struct let ident_ref m fid typ s = match find_module m with | Local -> - printf "" m fid; - printf "%s" typ s + printf "" m (sanitize_name fid); + printf "%s" typ s | External m when !externals -> - printf "" m fid; - printf "%s" typ s + printf "" m (sanitize_name fid); + printf "%s" typ s | External _ | Unknown -> - printf "%s" typ s + printf "%s" typ s let reference s r = match r with | Def (fullid,ty) -> - printf "" fullid; - printf "%s" (type_name ty) s + printf "" (sanitize_name fullid); + printf "%s" (type_name ty) s | Ref (m,fullid,ty) -> ident_ref m fullid (type_name ty) s @@ -640,7 +664,7 @@ module Html = struct | Some ref -> reference s ref | None -> if issymbchar then output_string s - else printf "%s" s + else printf "%s" s let sublexer c loc = let tag = @@ -648,6 +672,9 @@ module Html = struct in Tokens.output_tagged_symbol_char tag c + let sublexer_in_doc c = + Tokens.output_tagged_symbol_char None c + let initialize () = initialize_tex_html(); Tokens.token_tree := token_tree_html; @@ -657,16 +684,20 @@ module Html = struct match Tokens.translate s with Some s -> s | None -> escaped s let keyword s loc = - printf "%s" (translate s) + printf "%s" (translate s) let ident s loc = if is_keyword s then begin - printf "%s" (translate s) + printf "%s" (translate s) end else begin - try reference (translate s) (Index.find (get_module false) loc) + try + match loc with + | None -> raise Not_found + | Some loc -> + reference (translate s) (Index.find (get_module false) loc) with Not_found -> if is_tactic s then - printf "%s" (translate s) + printf "%s" (translate s) else if !Cdglobals.interpolate && !in_doc (* always a var otherwise *) then @@ -818,7 +849,7 @@ module Html = struct "[library]", m ^ ".html", t else sprintf "[%s, in %s]" (type_name t) m m , - sprintf "%s.html#%s" m s, t) + sprintf "%s.html#%s" m (sanitize_name s), t) let format_bytype_index = function | Library, idx -> @@ -827,7 +858,7 @@ module Html = struct Index.map (fun s m -> let text = sprintf "[in %s]" m m in - (text, sprintf "%s.html#%s" m s, t)) idx + (text, sprintf "%s.html#%s" m (sanitize_name s), t)) idx (* Impression de la table d'index *) let print_index_table_item i = @@ -923,8 +954,6 @@ module TeXmacs = struct let (preamble : string Queue.t) = in_doc := false; Queue.create () - let push_in_preamble s = Queue.add s preamble - let header () = output_string "(*i This file has been automatically generated with the command \n"; @@ -989,6 +1018,9 @@ module TeXmacs = struct let sublexer c l = if !in_doc then Tokens.output_tagged_symbol_char None c else char c + let sublexer_in_doc c = + char c + let initialize () = Tokens.token_tree := token_tree_texmacs; Tokens.outfun := output_sublexer_string @@ -1045,8 +1077,6 @@ module TeXmacs = struct let paragraph () = printf "\n\n" - let line_break_true () = printf "" - let line_break () = printf "\n" let empty_line_of_code () = printf "\n" @@ -1107,12 +1137,13 @@ module Raw = struct let stop_quote () = printf "\"" let indentation n = - for i = 1 to n do printf " " done + for _i = 1 to n do printf " " done let keyword s loc = raw_ident s let ident s loc = raw_ident s let sublexer c l = char c + let sublexer_in_doc c = char c let initialize () = Tokens.token_tree := ref Tokens.empty_ttree; @@ -1226,6 +1257,7 @@ let char = select Latex.char Html.char TeXmacs.char Raw.char let keyword = select Latex.keyword Html.keyword TeXmacs.keyword Raw.keyword let ident = select Latex.ident Html.ident TeXmacs.ident Raw.ident let sublexer = select Latex.sublexer Html.sublexer TeXmacs.sublexer Raw.sublexer +let sublexer_in_doc = select Latex.sublexer_in_doc Html.sublexer_in_doc TeXmacs.sublexer_in_doc Raw.sublexer_in_doc let initialize = select Latex.initialize Html.initialize TeXmacs.initialize Raw.initialize let proofbox = select Latex.proofbox Html.proofbox TeXmacs.proofbox Raw.proofbox -- cgit v1.2.3