-
-
Notifications
You must be signed in to change notification settings - Fork 43
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
Add pugClassNotation 'attribute' option #203
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code is looking good until now 👍
You can proceed like this
Do you want to handle id
in another PR? Or currently just solve it for class
?
You know what, a separate PR would be better. It's classes I really need and I'm not sure I'll get on to IDs soon. Hopefully this helps anyone else wanting to have a go at it! |
Could you update https://github.com/prettier/plugin-pug/blob/main/docs/guide/pug-specific-options.md e.g. - var clazz = 'ma-2 px-1'
div(class=clazz) |
c80ff50
to
ec27266
Compare
I just broke my rebase cherry 😊 I hope you didn't want any of that whitespace in the guide, sorry about that. |
Ah, these whitespaces are necessary cause otherwise VuePress will render these in one line instead of adding a newline |
Oh no! I have an overzealous markdown formatter I'm afraid. Whitespace is restored now... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cause of work for my employer, I hope I can setup and bundle everything together this evening or over the weekend
@@ -773,6 +775,20 @@ export class PugPrinter { | |||
if (token.val !== true) { | |||
this.result += `=${token.val}`; | |||
} | |||
} else if (token.name === 'class' && this.options.pugClassNotation === 'attribute') { | |||
const val: string = isQuoted(token.val) ? token.val.slice(1, -1).trim() : token.val; | |||
const classes: string[] = val.split(/\s+/); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thought: I'm a little bit afraid of this line and don't know what it's doing if the class contains js code with spaces 🤔
But I think I will merge it for now
This is a partial fix for #167 covering classes, I think it should be fairly straightforward to implement for IDs next, please let me know if this direction is right and I'll get on to it!
Thanks!