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

parse error with <style> tag #4

Closed
dermetfan opened this issue Dec 22, 2016 · 4 comments
Closed

parse error with <style> tag #4

dermetfan opened this issue Dec 22, 2016 · 4 comments

Comments

@dermetfan
Copy link

dermetfan commented Dec 22, 2016

I decided to try ructe for a small web project.

This is a reduced sample that should suffice to reproduce the problem.

main.rs:

include!(concat!(env!("OUT_DIR"), "/templates.rs"));

fn main() {
    templates::style(&mut std::io::stdout()).unwrap();
}

style.rs.html:

@()

<html>
<head>
<style>
#content {
    color: red;
}
</style>
</head>

<body>
<div id="content">Content!</div>
</body>
</html>

This results in a compilation error:

error[E0425]: unresolved name `templates::style`
 --> src/main.rs:4:5
  |
4 |     templates::style(&mut std::io::stdout()).unwrap();
  |     ^^^^^^^^^^^^^^^^

A more informative message is found in target/debug/build/<project>/output:

cargo:warning=Template parse error Eof in "/path/to/project/ructe-issue-3/templates/style.rs.html": "{\n    color: red;\n}\n</style>\n</head>\n\n<body>\n<div id=\"content\">Content!</div>\n</body>\n</html>\n"

The templates compiles if I remove the content of the <style>-tag.

My guess would be that ructe is confused by the curly braces in CSS, as the error message reports an Eof parse error at the first {.

@kaj
Copy link
Owner

kaj commented Dec 22, 2016

Yes. Since the curly braces are used for delimiting blocks they are not allowed unescaped in templates.

Since there is nothing that would explain a block at that position, it would be possible to actually allow raw curly braces there, but the easy solution is to just escape curly brackets like so:

<style>
#content @{
    color: red;
@}
</style>

@dermetfan
Copy link
Author

dermetfan commented Dec 23, 2016

Thanks for the quick clarification! Maybe this should be mentioned in the readme - I couldn't find information on escaping there (other than HTML escaping).

kaj added a commit that referenced this issue Jan 2, 2017
Add a section about curly brackets to the readme.

Suggested by @dermetfan in #4.
@kaj
Copy link
Owner

kaj commented Jan 2, 2017

Yep, it should be in the documentation (such as it is). I added a paragraph to README.md.

kaj added a commit that referenced this issue Jan 2, 2017
Add a section about curly brackets to the readme (this was originally
commited on the feature/staticfiles branch by mistake).

Suggested by @dermetfan in #4.
@dermetfan
Copy link
Author

Great, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants