top | item 33417311

(no title)

notriddle | 3 years ago

> If `class` was instead a kind of child, initially limited to a single instance per element, extending to multiple instances in a backward-compatible manner would not require introducing the DSL. It would be natural. Just allow many `class` children.

That's not the operative difference between children and attributes in HTML.

In HTML, if an element is unsupported, its contents are shown, while its attributes are ignored. This means, if a browser saw something like this:

    <p>
        <class>literature</class>
        <class>english</class>
        Billions of years ago, the Universe was created. This made a lot of people very angry, and has been widely considered a bad idea.
    </p>
In browsers that don't support, or even predate classes, you would want them to be ignored. This only works if they're attributes.

discuss

order

djedr|3 years ago

I was talking about is making up a new markup language, which doesn't have to inherit the distinctions and behaviors of HTML.

If, in this language, you wanted to have this feature in combination with what I proposed, you could simply mark the attribute-like children, to inform the engine that it should apply different defaults for them and unmarked children that it doesn't recognize.

This is what I do in the first variant of my language:

  a [
    href=[...]
    [...]
  ]
the `=` appended to `href` marks it as an attribute.

This certainly simplifies things when translating to HTML.

But if we were not constrained by the legacy of HTML then perhaps bothering with this when designing a new language would be unnecessary. Maybe not having this default behavior does not matter in practice and you can have a simpler language without it.

To determine whether that's the case it would help to answer: when is the feature you described useful in HTML? And also: when is this feature harmful?

notriddle|3 years ago

If you just want to have your language throw up an error whenever it sees an unrecognized element, then you’ll probably be able to simplify it a lot. It’s probably fine, since

* as long as you use a build tool the errors will be seen by the author (who will know how to fix them) and not the reader

* graceful degradation and format extensions are a crapshoot due to Hyrum’s Law [1]

[1]: https://news.ycombinator.com/item?id=30726668