karax icon indicating copy to clipboard operation
karax copied to clipboard

verbatim shouldn't create a wrapper div

Open ajusa opened this issue 3 years ago • 5 comments

Using verbatim shouldn't cause a wrapper div to be created, it isn't always the desired behavior. https://github.com/karaxnim/karax/pull/160 tries addressing this with a new verbatimRaw, but I would suggest just not having verbatim create a div at all, it is super easy for the user to add a wrapper div if needed. Also, verbatim must have a parent HTML element anyway.

I'd also argue that it is pretty unintuitive for a hidden element to be created if you just want to display something like & properly.

ajusa avatar May 08 '21 00:05 ajusa

Agreed.

Araq avatar May 08 '21 08:05 Araq

agreed; if you have a working PR that avoids creating a div with verbatim, then https://github.com/karaxnim/karax/pull/160 can be closed

timotheecour avatar May 17 '21 07:05 timotheecour

#160 is incorrect anyways. Example:

let node = "This is an inner div <div>inner div</div>".verbatimRaw
# node == VNode("This is an inner div ")

It completely discards any other children. You probably shouldn't do this anyways (not the point of verbatim), but it also shouldn't result in discarded data.

The reason why verbatim currently uses a div is because of the above. To capture many children in one node. The way around this would be to make toDom return a list of nodes and all the places that call it be modified to handle a list of nodes. Then the surrounding div for verbatim could be removed.

jyapayne avatar May 23 '21 14:05 jyapayne

I recall that React has a special <>/</> syntax. Maybe we could similarly create a special "empty" node which allows a list of nodes to be returned without any additional tags being output?

dom96 avatar May 23 '21 20:05 dom96

Hmm, that could work as well

jyapayne avatar May 24 '21 02:05 jyapayne

other frameworks append custom html comments to solve this problem iirc:

<!-- start arbitrary text #1 -->
...
<!-- end arbitrary text #1 -->

hamidb80 avatar Aug 27 '23 15:08 hamidb80

Completed in #270

geotre avatar Oct 20 '23 15:10 geotre