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

Jinja2 is parsing CSS & chokes on valid syntax #68

Open
alanhogan opened this issue Jun 1, 2011 · 4 comments
Open

Jinja2 is parsing CSS & chokes on valid syntax #68

alanhogan opened this issue Jun 1, 2011 · 4 comments

Comments

@alanhogan
Copy link

This took a long time to figure out…

I was getting this error for some reason:

~/path > hyde gen -r
 22:27:10 hyde.engine Reading site configuration from [/path/site.yaml]
 22:27:10 hyde Regenerating the site...
 22:27:10 hyde.engine Reading site contents
 22:27:10 hyde.engine Generating site at [/path]
 22:27:10 hyde.engine Configuring the template environment
 22:27:10 hyde.engine Reading site contents
{'index_file_names': ['index.html'], 'append_slash': False, 'strip_extensions': ['html']}
 22:27:10 hyde.engine Generating site to [/path/deploy]
Traceback (most recent call last):
  File "/usr/local/bin/hyde", line 8, in <module>
    load_entry_point('hyde==0.8', 'console_scripts', 'hyde')()
  File "/Library/Python/2.6/site-packages/hyde-0.8-py2.6.egg/EGG-INFO/scripts/main.py", line 10, in main
    Engine().run()
  File "build/bdist.macosx-10.6-universal/egg/commando.py", line 198, in run
  File "/Library/Python/2.6/site-packages/hyde-0.8-py2.6.egg/hyde/engine.py", line 90, in gen
    gen.generate_all(incremental=incremental)
  File "/Library/Python/2.6/site-packages/hyde-0.8-py2.6.egg/hyde/generator.py", line 198, in generate_all
    self.__generate_node__(self.site.content, incremental)
  File "/Library/Python/2.6/site-packages/hyde-0.8-py2.6.egg/hyde/generator.py", line 289, in __generate_node__
    self.__generate_resource__(resource, incremental)
  File "/Library/Python/2.6/site-packages/hyde-0.8-py2.6.egg/hyde/generator.py", line 302, in __generate_resource__
    self.update_deps(resource)
  File "/Library/Python/2.6/site-packages/hyde-0.8-py2.6.egg/hyde/generator.py", line 144, in update_deps
    deps.extend(self.template.get_dependencies(rel_path))
  File "/Library/Python/2.6/site-packages/hyde-0.8-py2.6.egg/hyde/ext/templates/jinja.py", line 592, in get_dependencies
    ast = self.env.parse(text)
  File "/Library/Python/2.6/site-packages/Jinja2-2.5.5-py2.6.egg/jinja2/environment.py", line 393, in parse
    self.handle_exception(exc_info, source_hint=source)
  File "<unknown>", line 1, in template
jinja2.exceptions.TemplateSyntaxError: Missing end of comment tag

Turns out, a recent change I made caused my compiled CSS files (I am not compiling using Hyde mechanisms currently, FWIW) to contain the string {#. Jinja2 freaked out because it thought it was the beginning of a comment.

The above is perfectly valid syntax in CSS; after all, if you are minifying your CSS and it contains an @media section that starts with an ID-based selector, then wham: @media something{#foo{...}}. And you won’t be able to hyde gen -r anymore.

Note that my CSS is within the content/media/css directory.

@alanhogan
Copy link
Author

Basically, I’m not sure why my CSS is being parsed like templates.

@sodiumjoe
Copy link

I just hit this problem with minified css as well.

@monkeyraptor
Copy link

Yep, I got that error too.
I resolved that by moving the #foo after a class or comma, like this:
@media (rule) {.foo_class{...} #foo_ID{...} }
or
@media (rule) {.foo_class, #foo_ID{...} .other_class{...} }

@michilu
Copy link

michilu commented Sep 20, 2016

I resolved that by changing the comment_start_string option of jinja2.Environment to {##, like this:

jinja2_environment = {
  'comment_start_string': '{##',
},

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

4 participants