-
Notifications
You must be signed in to change notification settings - Fork 2
Description
Could we find a way to write inline scripts and styles without wrapping them in quotes?
Context
People from the Hypermedia movement make libraries like these, enabling LOB without any builders (like Webpack):
Using them involves many inline scripts and styles. It would be great to enable IDE highlighting / autocompletion for them and, ideally, compile time lints.
The issue's history from Reddit
Q: Do inline scripts and styles need to be wrapped into quotes and PreEscaped
? That's the major issue I'm having with Maud. It's really nice to think of components, having html alongside the rest of the code, but being unable to setup scripts / styles lints in the editor makes me often retreat to Askama.
Why string literals have to be wrapped in quotes btw? As I remember Maud needs it because it uses macro_rules, but you seem to use proc macros. Isn't there a way to avoid quoting?
A: Currently, you do need to use PreEscaped
with quotes if you want to put content inside a <style> or <script> tag, however as you mentioned, I do care for DX and having good code locality promotes that, so I'll see exactly how I will go about this.
As for why this is required, the syn parser used in proc macros has limitations when it comes to 'any unquoted tokens', as its designed specifically to parse Rust tokens, it doesn't have the ability to collect detailed information about white space, newlines, line breaks, etc., as those things are not really relevant for Rust code. This means you have to join spans (a span is a sort of cursor pointing to a specific location in the source code), from the start of the text to the end of the text, although this feature is only available in nightly.
<!-- v span1 v span2 -->`
<div> Hello, World! </div>
Joining the span1 and span2 would give us the text node
Hello, World