Skip to content
Discussion options

You must be logged in to vote

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>

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by 64J0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants