Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[enhance] xhtml.opa: added a function to update an xhtml attribute by…

… appending a new value to it (usefull for updating class attribute especially)
  • Loading branch information...
commit 1ad0ca51d5c2e7682a136c8cf53bafc55cb98a49 1 parent b6f4e6c
Frederic Ye Aqua-Ye authored
Showing with 19 additions and 0 deletions.
  1. +19 −0 stdlib/core/xhtml/xhtml.opa
19 stdlib/core/xhtml/xhtml.opa
View
@@ -1156,6 +1156,25 @@ Xhtml =
aux(x)
/**
+ * Update (by appending) an attribute to an xhtml node, add it if not already present
+ */
+ update_attribute(name: string, value: string, x:xhtml):xhtml =
+ rec aux(x)=
+ match x : xhtml
+ {fragment=[x]} -> aux(x)
+ {~args namespace=_ tag=_ content=_ specific_attributes=_} as x->
+ args = match find_attr(name,args) with
+ {some=val} ->
+ value = "{val} {value}"
+ l = remove_attr(name,args)
+ [{~name namespace="" ~value}|l]
+ {none} -> [{~name namespace="" ~value}|args]
+ @opensums({x with ~args})
+ _ -> x
+ end
+ aux(x)
+
+ /**
* Set an attribute to an xhtml node. Replace if already_exists
*/
set_attribute(name: string, value: string, x:xhtml):xhtml =
Please sign in to comment.
Something went wrong with that request. Please try again.