hostilefork / replpad-js

Interactive Web Console for Rebol language (Ren-C branch)
GNU Lesser General Public License v3.0
13 stars 9 forks source link

Allow printing HTML with multiple child nodes #72

Closed BrianOtto closed 5 years ago

BrianOtto commented 5 years ago

I ran into an annoying issue, while building the game tutorial, where I couldn't insert complex HTML when using print/html in the REPL.

e.g. print/html "<div>1</div><div>2</div>"

This would only output/insert the first <div>1</div>. This is a trivial example, but it was affecting things like trying to get multiple images to display on a single line.

The reason this is happening is because the /html refinement uses load to create an HTML element around the content. This function only uses the firstChild when inserting the content, and so this causes all other child elements to get removed.

Is there a reason it does this? If not, then I would suggest using the alternative method in my PR instead. It uses insertAdjacentHTML which allows you to insert arbitrary HTML and also preserve any events that are attached to it. It also bypasses load completely and will insert the HTML after the last child, similar to how appendChild works.

<test-repl> ran okay and the change doesn't appear to affect the UI in any way.

hostilefork commented 5 years ago

No reason not to use it other than "I'd never heard of that"... (I was trying to use DocumentFragment-style things at some point, but I guess it wasn't working!)

Seems to resolve: https://github.com/hostilefork/replpad-js/issues/69

So, great!