OlivierBlanvillain / monadic-html

Tiny DOM binding library for Scala.js
https://olivierblanvillain.github.io/monadic-html/examples/
MIT License
225 stars 24 forks source link

Text element filter #104

Open bbarker opened 6 years ago

bbarker commented 6 years ago

This seems to be a pervasive issue, though it usually doesn't cause an issue in rendering. However, when it does, it is fairly annoying:

https://stackoverflow.com/questions/38469002/how-to-strip-text-from-xml-string-in-scala

I suggest we have a way like this to rewrite rules. Not sure if we want to implement the full version from scala.xml - haven't looked at it yet, but I suspect we could do something much simpler, as with a tail recursive filter.

OlivierBlanvillain commented 6 years ago

I'm not sure it's worth putting these helper... With a clean ADT, traversing and transforming trees is really simple, for example here how I would what is asked on the linked question:

def traverse(n: Node): Node =
  n match {
    case g @ Group(ns) => g.copy(nodes = ns.map(traverse))
    case e @ Elem(_, _, _, _, ns) => e.copy(child = ns.map(traverse))
    case Text(_) => Text("")
    case x => x
  }