soliciting feedback: which of these two syntaxes do you prefer?

body {
@each section in $(sections) where $(:title section) {
$(:title section)
}
$content
}

body {
@each section in (sections) where (:title section) {
$(:title section)
}
$content
}

(note that $ has disappeared from the @each line in the second one)

actually wait i'm a dumbass, this can consistently be (:title section) everywhere, even in the body

this is hot

body {
header.site-header {
nav.site-nav {
@each section in (sections) where (predicate section) {
a.page-link[href=$section.url] { $section.title }
}
}
}

ok follow-up question: which of these do you like better?

A: all of these rules:

  • div { Hello world } expands to <div>Hello world</div>
  • div { span { Hi } } expands to <div><span>Hi</span></div>
  • div { "Hello" span { world } } expands to <div>Hello<span>world</span></div>
  • div div > span { Hi } and p { Hello span { world } } are parse errors

B: all of these rules:

  • div { "Hello world" } expands to <div>Hello world</div>
  • div { span { "Hi" } } expands to <div><span>Hi</span></div>
  • div div > span { "Hi" } expands to <div></div><div><span>Hi</span></div>
  • p { Hello span { world } } expands to <p><Hello></Hello><span><world></world></span></p>

C: something else

@jyn not sure about fine details but much prefer a syntactic way of distinguishing text from tags, so B
@jyn oh! I figured out what's bugging me about B3! The "div > span" shorthand is clearly borrowed from CSS, but if "div div > span" was a CSS selector, the "div div" part would also indicate nesting, so the attempt to borrow people's understanding of CSS winds up being counterproductive. I think I'd maybe just leave out the shorthand.
@jyn it's hard to know without knowing how to set attrs
@b0rk attrs are bare words with optional quotes: a[href=/api], img[src="https://bsky.app/abc&x=y"]
@jyn is the idea that everything inside the [] gets put into the html verbatim? like a[href=/api hidden class="test"] would translate to <a href=/api hidden class="test">?
@b0rk basically, yeah! it's meant to look like a CSS selector.
@jyn cool! asking bc the issue i always run into with tools to generate html (like JSX etc) is sometimes they have specific ideas about what html "should" look like that are different from my ideas. So knowing that i can write any attr I want (even if it seems "wrong" somehow) and that it'll be respected would be cool
@b0rk oh interesting, what kinds of restrictions do they have? i think currently the one thing i normalize is hidden -> hidden="", but that's easy to remove.

@jyn the main thing i remember is this issue I ran into with templ where it required you to quote attribute values https://github.com/a-h/templ/issues/963 (and also how templ requires that <li> and <p> tags be closed)

the "li tags must be closed" thing doesn't seem too relevant in this case though I am curious about how br and hr tags would be represented

templ errors if HTML attributes aren't quoted · Issue #963 · a-h/templ

Describe the bug If I try run templ on this file: package main templ Hello() { <div id=main></div> } I get this error: parsing error: <div>: malformed open element: line 3, col 7 Seems related to #...

GitHub
@b0rk i decided to make self-closing blocks hr; and empty blocks require a trailing div {}, so bare names are an error now unless they're followed by a > child selector.

@jyn In theory B, but I've used twirl (https://www.playframework.com/documentation/3.0.x/ScalaTemplates) which is in school A and it was Fine™ in practice.

That said, B3 looks like it might have a typo in its expansion? At least I can't find a logic for `foo foo > bar` to expand to `<foo/><foo><bar/></foo>` Also just generally not a fan of unmatched braces.

Scala Templates - 3.0.x

Play Framework - The High Velocity Web Framework For Java and Scala

@natkr think your client might be mangling B, it renders ok on mine:
@jyn I think @natkr is saying the > reads as an unmatched grouping character to them?
@zwol @jyn Yes, but as I wrote in the other subthread I can kinda buy that based on css/emmet's precedent. I think the main thing that confused me was that my brain wants to group `a b > c` as `(a b) > c`, rather than `a (b > c)`.
@natkr @jyn my brain actually wants to read it as a CSS selector, thus (a b > c) all one thing.
@zwol @jyn Yeah… I think that's where I went first tbh.
@jyn Oh, I guess it should be parsed as `foo {}; foo { bar {} }`, with the `>` borrowed from css/emmet? Probably less confusing in "real" code where you'd have some separator (at least a newline, maybe `+` or `;` if inline?) between siblings. Or require `{}` for empty nodes.
@jyn A, but actually C since HTML is neither text nor tree it is something else, yet i like manipulating it as the former better than the latter
@PolyWolf ooh, say more! any different syntax you like more? or languages you'd point me towards to learn from?

@jyn i fear my original comment did not have as noble a thesis as you may have hoped: I was expressing a preference for "HTML template languages should operate on HTML text". however recalling some experiences doing that myself, you really do need entity escaping, so this doesn't quite work (e.x. https://github.com/p0lyw0lf/website/blob/8db2c0f8546773d7cf7dfb6bfd5407f86abf7189/src/runtime/remoteImage.js#L60 and also https://wolfgirl.dev/tags/blag/ is still broken lol)

I cut my teeth on React JSX, which does solve a lot of these escaping issues, at the cost of way too many {} and also those silly <></> fragments.

I have come around to appreciating these syntaxes because they (assumedly) handle the entity escaping issues, aren't very verbose, and map cleanly onto normal HTML ("can run the algorithm in your head"). I like A more than B just because it disallows > as an operator; I think it means a different thing in CSS, and if it did mean the same thing, non-local operators in a template language seems kinda wrong.

The "strings as bodies must be quoted" implying "unquoted things are elements" from B is nice tho, lets u work with webcomponents/not have a hardcoded list of HTML ones, so in a sense yes still C :)

website/src/runtime/remoteImage.js at 8db2c0f8546773d7cf7dfb6bfd5407f86abf7189 · p0lyw0lf/website

My website/blog! https://wolfgirl.dev/. Contribute to p0lyw0lf/website development by creating an account on GitHub.

GitHub
@PolyWolf ">" means "child combinator" in CSS. i think it's the same meaning but you're the second or third person to tell me it's confusing so i'm just going to cut it and make you use braces for nesting lol
@jyn yes but the div beforehand means the rule reads to me like div div > span, (anscestor then child) not div {} div > span (two separate rules). if you meant the example text to be the latter then i am ok with it. just avoiding ambiguity w/ how the rule is interpreted CSS-style :)
@PolyWolf ahhh ok. yes, i'm gonna require div {}, in retrospect i think bare div was a mistake
@jyn lastly i am curious: how will you handle things like <hr> or <img> that are "void elements" (https://stackoverflow.com/a/10599002)? Hardcoded list probably?
What are the allowed ways to close self-closing tags for void elements such as <br> in HTML5?

In HTML5 is it still appropriate to close a <br> tag with <br />? This obviously also applies to all other single tags. I realize this doesn't actually affect how stuff works, but what...

Stack Overflow
@PolyWolf yeah, hard-coded list
@PolyWolf actually hm i could have img; mean this is a self-closing block
@jyn @PolyWolf I think that if you’re consistent with haml, it’s fine
@jyn I prefer B (B1 seems to have a typo though)
@jyn this is not exactly what you're doing, but I'm reminded of this, that I saw a few years back: https://github.com/bodil/typed-html
GitHub - bodil/typed-html: Type checked JSX for Rust

Type checked JSX for Rust. Contribute to bodil/typed-html development by creating an account on GitHub.

GitHub