-
|
I have a list of attributes, e.g And I want to apply a filter to remove all “class” attributes. What’s the way to do this? |
Beta Was this translation helpful? Give feedback.
Answered by
ratsclub
Apr 28, 2026
Replies: 1 comment
-
|
You need to traverse the tree and remove the attributes. let removeClasses tree =
let isClassAttr =
function KeyValue("class", _) -> true | _ -> false
let strip attrs =
attrs |> Array.filter (fun attr -> not (isClassAttr attr))
let rec walk =
function
| ParentNode((tag, attrs), children) ->
ParentNode((tag, strip attrs), List.map walk children)
| VoidElement(tag, attrs) -> VoidElement(tag, strip attrs)
| Text _ as t -> t
walk tree
let tree = div [ _class "foo" ] [ str "hi" ]
let result = removeClasses tree
// <div>hi</div> |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
64J0
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You need to traverse the tree and remove the attributes.