]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/www/lambdadelta/bin/xhtbl/xmlUnparser.ml
update in basic_2
[helm.git] / helm / www / lambdadelta / bin / xhtbl / xmlUnparser.ml
index f413aa0ef071632dd034054ea3dcf320386b6b27..2f29e4bb728192f22c7f5142428826d63013597e 100644 (file)
@@ -8,12 +8,22 @@ module O = Options
 module T = Table
 module M = Matrix
 
+let xhtbl = "xhtbl"
+
 let i = 0
 
 let myself = F.basename (Sys.argv.(0))
 
 let msg = P.sprintf "This file was generated by %s, do not edit" myself
 
+let compose uri ext =
+   if uri.[pred (S.length uri)] = '/' then uri else
+   try
+      let i = S.index uri '#' in
+      let uri, fragment = S.sub uri 0 i, S.sub uri i (S.length uri - i) in
+      uri ^ ext ^ fragment
+   with Not_found -> uri ^ ext
+
 let border cell =
    let str = S.make 4 'n' in
    if cell.M.cb.T.n then str.[0] <- 's';   
@@ -22,24 +32,30 @@ let border cell =
    if cell.M.cb.T.w then str.[3] <- 's';
    str :: cell.M.cc
 
-let text = function
-   | T.Plain s       -> s
-   | T.Link (uri, s) -> P.sprintf "<a href=\"%s\">%s</a>" uri s
+let text baseuri ext = function
+   | T.Plain s              -> s
+   | T.Link (true, uri, s)  -> P.sprintf "<a href=\"%s\">%s</a>" uri s
+   | T.Link (false, uri, s) -> 
+      let uri = !O.baseuri ^ baseuri ^ compose uri ext in
+      P.sprintf "<a href=\"%s\">%s</a>" uri s
+
+let name cell =
+   if cell.M.cn = "" then "" else P.sprintf " id=\"%s\"" cell.M.cn
 
 let key cell =
-   if cell.M.ck = [] then "<br/>" else S.concat " " (L.map text cell.M.ck)
+   if cell.M.ck = [] then "<br/>" else S.concat "" (L.map (text cell.M.cu cell.M.cx) cell.M.ck)
 
 let ind i = S.make (2 * i) ' '
 
 let out_cell och cell =
-   let cc = border cell in
-   P.fprintf och "%s<td class=\"%s\">%s</td>\n"
-      (ind (i+4)) (S.concat " " cc) (key cell)
+   let cc = xhtbl :: border cell in
+   P.fprintf och "%s<td class=\"%s\"%s>%s</td>\n"
+      (ind (i+3)) (S.concat " " cc) (name cell) (key cell)
 
 let out_row och row =
-   P.fprintf och "%s<tr>\n" (ind (i+3));
+   P.fprintf och "%s<tr class=\"%s\">\n" (ind (i+2)) xhtbl;
    A.iter (out_cell och) row;
-   P.fprintf och "%s</tr>\n" (ind (i+3))
+   P.fprintf och "%s</tr>\n" (ind (i+2))
 
 let out_space och (name, uri) =
    let name = if name = "" then name else ":" ^ name in
@@ -60,10 +76,8 @@ let open_out name spaces =
 
 let output och name matrix =
    P.fprintf och "<xsl:template name=\"%s\">\n" name;
-   P.fprintf och "%s<table cellpadding=\"4\" cellspacing=\"0\">\n" (ind (i+1));
-   P.fprintf och "%s<tbody>\n" (ind (i+2));
-   A.iter (out_row och) matrix.M.m; 
-   P.fprintf och "%s</tbody>\n" (ind (i+2));
+   P.fprintf och "%s<table class=\"%s\" cellpadding=\"4\" cellspacing=\"0\">\n" (ind (i+1)) xhtbl;
+   A.iter (out_row och) matrix.M.m;
    P.fprintf och "%s</table>\n" (ind (i+1));
    P.fprintf och "</xsl:template>\n\n"