agilord / domino

An incremental DOM library, with support for virtual DOM and components, written in Dart.
19 stars 4 forks source link

Named character references support #9

Open Wdestroier opened 6 days ago

Wdestroier commented 6 days ago

Is it possible to use named character references? For example:  . Would be great to be able to insert raw html anywhere too. For reference, the HTML standard: https://html.spec.whatwg.org/dev/named-characters.html#named-character-references.

isoos commented 5 days ago

@Wdestroier: I see why these would be useful here, but at the same time, I think these should belong in a separate package, as they would be more useful on their own. I'd expect it to be present in a package like package:html or it could be a simple package that does this and only this feature.

isoos commented 5 days ago

@Wdestroier: I'm revisiting my prior comment because I thought that it was asked on another package of mine (diacritic), and the conversion direction is the opposite here. In short, let's zero the previous comment, it is not relevant here.

isoos commented 5 days ago

Is it possible to use named character references? For example:  

I think I may have written   in the past decade a few times, but I haven't seen the need for most of the named character references like á or similar, as every system seem to support unicode and utf-8 nowadays. So writing these characters seems not really worth it.

Would be great to be able to insert raw html anywhere too.

The low-level API supports this: https://pub.dev/documentation/domino/latest/domino/DomBuilder/innerHtml.html, although not at any position, only as part of the inner (unsafe) HTML content. If you would write arbitrary HTML as part an attribute, the entire DOM element needs to be written as part of the samie content.

There is no DomNode exposure of it, we could add it easily.

However, I don't think I would add more than that, e.g. arbitrary HTML attribute content seems to unsafe and it seems to me that one should always have better safe HTML option. I can see that some apps may need arbitrary inner HTML, hence its support, but if you have compelling evidence for arbitrary attributes, I may reconsider this.

Wdestroier commented 5 days ago

I think I may have written   in the past decade a few times, but I haven't seen the need for most of the named character references like á or similar, as every system seem to support unicode and utf-8 nowadays. So writing these characters seems not really worth it.

True, the main reason I need   is to rewrite existing code. The "visible" unicode characters are unnecessary to me. I'm unsure if the other whitespace characters, such as   or ​, are used. That's why I proposed a general feature.

The low-level API supports this: https://pub.dev/documentation/domino/latest/domino/DomBuilder/innerHtml.html, although not at any position, only as part of the inner (unsafe) HTML content.

I tried to write builder.text('Text without'); builder.innerHtml(' '); builder.text('CSS styles.');, but the code threw an exception that the Cursor had been moved.

I can see that some apps may need arbitrary inner HTML, hence its support.

It's very useful. My workaround to "embed"   anywhere was to define it as final nbsp = span(styles: {'white-space': 'pre'}, text: ' '); and undo a few custom styles applied to the span tag.

isoos commented 4 days ago

Have you tried the Unicode escape code for the  : \u00a0? It could be 'Text without\u00a0CSS styles.'.