From 5d2b096f29adf3d139c4de46321e26790e9b4211 Mon Sep 17 00:00:00 2001 From: Pierre Letouzey Date: Fri, 5 Dec 2014 16:29:39 +0100 Subject: coqdoc: fix a few issues with xhtml validity (backport 1636f7 and 754abf1 from v8.4) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - For the style of identifiers, coqdoc was using a 'type' attribute of tag . But this attribute isn't a legal attribute of tag according to the xhtml norm. Instead, I propose to use 'title' for that. The coqdoc.css now supports both approaches. - The names of inner links (cross references #foo) were containing arbitrary characters (in the case of a notation string). For instance in Utf8_core : Instead, when strange characters are detected, we now hash the string via Digest, and use this hexa hash as html label. - And some whitespace before /> --- tools/coqdoc/coqdoc.css | 57 +++++++++++++++++++++++++++++++++++++++++++++++++ tools/coqdoc/output.ml | 44 +++++++++++++++++++++++++------------- 2 files changed, 86 insertions(+), 15 deletions(-) (limited to 'tools/coqdoc') diff --git a/tools/coqdoc/coqdoc.css b/tools/coqdoc/coqdoc.css index ccd285f18..44399cd8b 100644 --- a/tools/coqdoc/coqdoc.css +++ b/tools/coqdoc/coqdoc.css @@ -160,8 +160,65 @@ tr.infrulemiddle hr { #footer { font-size: 65%; font-family: sans-serif; } +/* Identifiers: ) */ + .id { display: inline; } +.id[title="constructor"] { + color: rgb(60%,0%,0%); +} + +.id[title="var"] { + color: rgb(40%,0%,40%); +} + +.id[title="variable"] { + color: rgb(40%,0%,40%); +} + +.id[title="definition"] { + color: rgb(0%,40%,0%); +} + +.id[title="abbreviation"] { + color: rgb(0%,40%,0%); +} + +.id[title="lemma"] { + color: rgb(0%,40%,0%); +} + +.id[title="instance"] { + color: rgb(0%,40%,0%); +} + +.id[title="projection"] { + color: rgb(0%,40%,0%); +} + +.id[title="method"] { + color: rgb(0%,40%,0%); +} + +.id[title="inductive"] { + color: rgb(0%,0%,80%); +} + +.id[title="record"] { + color: rgb(0%,0%,80%); +} + +.id[title="class"] { + color: rgb(0%,0%,80%); +} + +.id[title="keyword"] { + color : #cf1d1d; +/* color: black; */ +} + +/* Deprecated rules using the 'type' attribute of (not xhtml valid) */ + .id[type="constructor"] { color: rgb(60%,0%,0%); } diff --git a/tools/coqdoc/output.ml b/tools/coqdoc/output.ml index a3e4c4000..78a73a88b 100644 --- a/tools/coqdoc/output.ml +++ b/tools/coqdoc/output.ml @@ -535,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" @@ -595,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 _ = () @@ -628,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 @@ -650,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 = @@ -670,11 +684,11 @@ 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 match loc with @@ -683,7 +697,7 @@ module Html = struct 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 @@ -835,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 -> @@ -844,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 = -- cgit v1.2.3