+let mathmlns = "http://www.w3.org/1998/Math/MathML";;
+let xmldiffns = "http://helm.cs.unibo.it/XmlDiff";;
+let helmns = "http://www.cs.unibo.it/helm";;
+
+type highlighted_nodes = Gdome.node list;;
+
+let rec make_visible (n: Gdome.node) =
+ match n#get_parentNode with
+ None -> ()
+ | Some p ->
+ match p#get_namespaceURI, p#get_localName with
+ Some nu, Some ln when
+ nu#to_string = mathmlns && ln#to_string = "maction" ->
+ (new Gdome.element_of_node p)#setAttribute
+ ~name:(Gdome.domString "selection")
+ ~value:(Gdome.domString "2") ;
+ make_visible p
+ | _,_ -> make_visible p
+;;
+
+let highlight_node ?(color="yellow") (doc: Gdome.document) (n: Gdome.node) =
+ let highlight (n: Gdome.node) =
+ let highlighter =
+ doc#createElementNS
+ ~namespaceURI:(Some (Gdome.domString mathmlns))
+ ~qualifiedName:(Gdome.domString "m:mstyle")
+ in
+ highlighter#setAttribute ~name:(Gdome.domString "background")
+ ~value:(Gdome.domString color) ;
+ highlighter#setAttributeNS
+ ~namespaceURI:(Some (Gdome.domString xmldiffns))
+ ~qualifiedName:(Gdome.domString "xmldiff:type")
+ ~value:(Gdome.domString "fake") ;
+ let parent =
+ match n#get_parentNode with
+ None -> assert false
+ | Some p -> p
+ in
+ ignore
+ (parent#replaceChild ~oldChild:n ~newChild:(highlighter :> Gdome.node)) ;
+ ignore (highlighter#appendChild n) ;
+ (highlighter :> Gdome.node)
+ in
+ let rec find_mstylable_node n =
+ match n#get_namespaceURI, n#get_localName with
+ Some nu, Some ln when
+ nu#to_string = mathmlns &&
+ let ln = ln#to_string in
+ ln <> "mtr" && ln <> "mtd" -> n
+ | Some nu, Some ln when
+ nu#to_string = mathmlns &&
+ let ln = ln#to_string in
+ ln = "mtr" || ln = "mtd" ->
+prerr_endline "@@@ find_mstylable_node scendo";
+ let true_child =
+ match n#get_firstChild with
+ None -> assert false
+ | Some n -> n
+ in
+ find_mstylable_node true_child
+ | _,_ ->
+prerr_endline ("@@@ find_mstylable_node salgo da " ^ match n#get_localName with Some n -> n#to_string | None -> "_") ;
+ match n#get_parentNode with
+ None -> assert false
+ | Some p -> find_mstylable_node p
+ in
+ let highlighter = highlight (find_mstylable_node n) in
+ make_visible highlighter ;
+ highlighter
+;;
+
+let highlight_nodes ~xrefs (doc:Gdome.document) =
+ let highlighted = ref [] in
+ let rec aux (n:Gdome.element) =
+ if
+ List.mem
+ (n#getAttributeNS ~namespaceURI:(Gdome.domString helmns)
+ ~localName:(Gdome.domString "xref"))#to_string
+ xrefs
+ then
+ highlighted :=
+ (highlight_node ~color:"#00ff00"(* light green *) doc (n :> Gdome.node))::
+ !highlighted ;
+ let children = n#get_childNodes in
+ for i = 0 to children#get_length - 1 do
+ match children#item i with
+ None -> assert false
+ | Some n ->
+ if n#get_nodeType = GdomeNodeTypeT.ELEMENT_NODE then
+ aux (new Gdome.element_of_node n)
+ done
+ in
+ aux doc#get_documentElement ;
+ !highlighted
+;;
+
+let dim_nodes =
+ List.iter
+ (function (n : Gdome.node) ->
+ assert
+ (n#get_nodeType = GdomeNodeTypeT.ELEMENT_NODE &&
+ ((new Gdome.element_of_node n)#getAttributeNS
+ ~namespaceURI:(Gdome.domString xmldiffns)
+ ~localName:(Gdome.domString "type"))#to_string = "fake") ;
+ let true_child =
+ match n#get_firstChild with
+ None -> assert false
+ | Some n -> n in
+ let p =
+ match n#get_parentNode with
+ None -> assert false
+ | Some n -> n
+ in
+ ignore (p#replaceChild ~oldChild:n ~newChild:true_child)
+ )
+;;
+