Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optional tags problem #91

Closed
dy opened this issue May 31, 2019 · 5 comments
Closed

Optional tags problem #91

dy opened this issue May 31, 2019 · 5 comments

Comments

@dy
Copy link

dy commented May 31, 2019

According to the standard, some elements may omit closing tags.
Example:

import htm from 'https://unpkg.com/htm?module'
let html = htm.bind((a, b, c) => console.log(a, b, c))

html`<ul><li><li></ul>`

As we see in the output, a single h('li', null, undefined) was called.

It seems that htm disregards the actual closing tag and just matches the </ signature, so that any open tag can be closed with "generic" end tag as <someTag><//>, which is quite handy in many ways.

This brings more serious problem with br tag.
Example (from the spec):

html`<p>P. Sherman<br>
42 Wallaby Way<br>
Sydney</p>`

that gives a single h('br', null, undefined) call.

@developit
Copy link
Owner

developit commented Jun 4, 2019

As of 2.0, htm is an XML dialect in order to match JSX, not an HTML dialect. Optional tags are not supported, instead use XML self-closing tags:

html`<p>P. Sherman<br />
42 Wallaby Way<br />
Sydney</p>`

@dy dy closed this as completed Jun 4, 2019
@dy
Copy link
Author

dy commented Jul 6, 2019

Just stumbled upon this implementing custom tags.
By design, special h function accepts "html spread" <...> tag.
Turns out, htm isn't on good terms with unclosed tags. Using <.../> doesn't seem as elegant.

Just leaving that here.

@dy
Copy link
Author

dy commented Jul 6, 2019

In addition, some other use-cases of unclosed tags left out:

<?xml version="1.0" encoding="UTF-8" ?>
<!doctype html>
<![CDATA[ ...  ]]>
<!-- comment -->
<!--[if expression]> HTML <![endif]-->

Not necessary useful, but little parser improvement (eg. a customizable dict of unclosed tags) could make htm support extended XML markups, not only JSX. That would make it handy for consuming packages, not only direct use.

@dy
Copy link
Author

dy commented Jul 6, 2019

Sorry for bothering with notifications, just one more potentially realistic improvement over JSX.
There's no good way to leave comments in JSX now.
Could be handy to support standard html syntax for them <!-- Commented out parts --> or something alike.

@dy
Copy link
Author

dy commented Mar 8, 2020

In case if someone needs better support for html - there's xhtm - extensible htm version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants