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

Revisiting div class/id shorthand #172

Closed
yhtez opened this issue Apr 3, 2019 · 5 comments
Closed

Revisiting div class/id shorthand #172

yhtez opened this issue Apr 3, 2019 · 5 comments

Comments

@yhtez
Copy link
Contributor

yhtez commented Apr 3, 2019

As of #137 (which as far as I can tell fixes the ambiguity issue outlined in #35 and #28) I don't see any reason why the shorthand syntax for classes and ids can't be expanded to allow the case with no element tag such as .awesome-class#unique-id instead of div.awesome-class#unique-id.
I'd be happy to look into making a PR to add this functionality if you wouldn't be apposed to this syntax now.

@lambda-fairy
Copy link
Owner

lambda-fairy commented Apr 6, 2019

Good idea!

The only issue would be the interaction with named attributes. Currently class/id shorthands and named attributes can be interleaved in an arbitrary way, so e.g.

div contenteditable? #unique-id dir="rtl" .awesome-class {}

is valid syntax.

If we do the obvious thing and allow omitting the element name with no other changes, then

contenteditable? #unique-id dir="rtl" .awesome-class {}

would be valid syntax. That's not ambiguous but it could be confusing.

I think an easy solution would be to say that any classes/ids must come before named attributes. That eliminates the confusing example I gave above, and I think it was an accident that the interleaving was allowed in the first place.

What do you think @zth0? If you're happy with this tweak then I'm happy to take a PR 🙂

@yhtez
Copy link
Contributor Author

yhtez commented Apr 7, 2019

The way I was planning to go about it would have been to only allow omitting element name if only if the first attribute of the element is a class or id shorthand such that

.awesome-class contenteditable? dir="rtl" #unique-id {}
#unique-id contenteditable? dir="rtl" .awesome-class {}

is valid syntax (still allowing any order of class and id attrs beyond the implicit div) but

contenteditable? #unique-id dir="rtl" .awesome-class {}

isn't (which prevents it from being confusing.)

I'm not sure if you meant allowing omitting element name even without any attrs but I'd prefer not to go about it this way as I think this causes more breakage than is necessary.
For example blocks with no element name would instead be wrapped in a div https://github.com/lfairy/maud/blob/f652784adbdd57d1510e83fd17ed2a888655eb8b/maud/tests/basic_syntax.rs#L30-L39 would generate the html hello<div> ducks geese</div> swans

I'm not sure if this matches what you were thinking but I think that going about it this way instead would prevent this from breaking any old code and should be simpler to implement.

@yhtez
Copy link
Contributor Author

yhtez commented Apr 7, 2019

Opened PR #173 with my suggested implementation, let me know what you think and if I missed anything or you would rather your idea.

@yhtez yhtez closed this as completed Apr 7, 2019
@lambda-fairy
Copy link
Owner

Oh I forgot about plain blocks. That makes sense to me!

@lambda-fairy
Copy link
Owner

BTW, issues should stay open until the PR has been merged.

@lambda-fairy lambda-fairy reopened this Apr 13, 2019
lambda-fairy pushed a commit that referenced this issue Apr 20, 2019
* Add implicit div class/id shorthand

* Add newline

* Add short explanation and example of implicit div
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants