Is there a way to investigate a Html tree?

141 views
Skip to first unread message

Peter Damoc

unread,
Jul 28, 2016, 5:21:58 AM7/28/16
to Elm Discuss
I need to gather all the class names used in a Html tree generated by the app. 

Is there a way to do this short of converting the html to a string and manually parsing it?

 



--
There is NO FATE, we are the creators.
blog: http://damoc.ro/

Noah Hall

unread,
Jul 28, 2016, 6:47:14 AM7/28/16
to elm-d...@googlegroups.com
My implementation of server-side rendering allows you to do exactly
that, without turning it to a string.

Checkout how this is implemented ->
https://github.com/eeue56/elm-server-side-renderer/blob/master/src/Query.elm#L51
> --
> You received this message because you are subscribed to the Google Groups
> "Elm Discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to elm-discuss...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Peter Damoc

unread,
Jul 28, 2016, 7:18:52 AM7/28/16
to Elm Discuss
I took quick look and I got here:
https://github.com/eeue56/elm-server-side-renderer/blob/master/src/Helpers.elm#L31

query leads to nodeTypeFromHtml which is actually living in a module named HtmlToString :) 

Looks like you are still turning it into a string. 
I'm imagining that with the help of that native, the string representation is smarter (ready for Json decoding) 

Am I missing something or misreading the code? 



Noah Hall

unread,
Jul 28, 2016, 7:39:58 AM7/28/16
to elm-d...@googlegroups.com
It turns the internal representation to a string representation. It doesn't actually render it at that point. It's just the internal representation.

Peter Damoc

unread,
Jul 28, 2016, 7:52:45 AM7/28/16
to Elm Discuss
Will calling toString on a Html element render it or will it print the internal representation? 

I'm trying to avoid going to Native, if possible. 


Noah Hall

unread,
Jul 28, 2016, 8:07:07 AM7/28/16
to elm-d...@googlegroups.com
Hope. This is what I tried first, but toString sadly does things to js  objects that make that hard. The rest of the helpers in that file are dedicated to trying to get that to work, actually. By replacing and collecting fields and properties.

Conrad Dean

unread,
Jul 28, 2016, 9:44:13 AM7/28/16
to Elm Discuss
I've been trying to figure out how to do this with elm-markdown objects as well, but haven't gotten anywhere with it.

Yosuke Torii

unread,
Jul 28, 2016, 11:56:06 AM7/28/16
to Elm Discuss
Recently I wrote a little parser for `toString` representation.


It turns
toString <| div [] [ input [ type' "text", class "foo", onClick 1 ] [], text "hello" ]

into
Record ([Property "type" (StringLiteral "node"),Property "tag" (StringLiteral "div"),Property "facts" (Record []),Property "children" (Record ([Property "0" (Record ([Property "type" (StringLiteral "node"),Property "tag" (StringLiteral "input"),Property "facts" (Record ([Property "type" (StringLiteral "text"),Property "className" (StringLiteral "foo"),Property "EVENT" (Record ([Property "click" (Record ([Property "options" (Record ([Property "stopPropagation" (Union "False" []),Property "preventDefault" (Union "False" [])])),Property "decoder" (Value "<decoder>")]))]))])),Property "children" (Record []),Property "namespace" (Value "<internal structure>"),Property "descendantsCount" (Value "0")])),Property "1" (Record ([Property "type" (StringLiteral "text"),Property "text" (StringLiteral "hello")]))])),Property "namespace" (Value "<internal structure>"),Property "descendantsCount" (Value "2")])

Peter, is this close to what you want to do?


2016年7月28日木曜日 18時21分58秒 UTC+9 Peter Damoc:

Peter Damoc

unread,
Jul 29, 2016, 7:25:26 AM7/29/16
to Elm Discuss
Hi Yousuke,

This looks like something I could use to inspect for classes. Thank you! 
I will investigate further. 



--
You received this message because you are subscribed to the Google Groups "Elm Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elm-discuss...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages