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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: add support for Django / Jinja templates #24

Closed
Uninen opened this issue Dec 3, 2019 · 8 comments
Closed

Feature request: add support for Django / Jinja templates #24

Uninen opened this issue Dec 3, 2019 · 8 comments

Comments

@Uninen
Copy link

Uninen commented Dec 3, 2019

Django / Jinja templates are heavily used in Python world and would be great addition to Shiki supported languages.

In an unrelated note, Kudos for this awesome library, yet another home run 馃憤

@canibanoglu
Copy link

I'm looking into this but I have a question. I found this repo which includes a lot of syntaxes for various combinations of Jinja with other languages.

This works just fine in VS Code due to file extensions but with shiki there's a need for explicitly specifiying which language to use for tokenization. Which means that to have JS syntax highlighting within a Jinja template you'd have to pass jinja-js which wouldn't necessarily work with CSS highlighting within the same file.

The question is what is the desired API? Do we want to have things work automagically when we just pass jinja as the language or is it OK if we expect the user to specify which one they want to use specifically (like jinja-js or jinja-css)? I can't think of an easy way to implement the first one and the second one is a bit limited because you'd have to add a new syntax file for every combination you would want to use.

Or we just add Jinja's raw syntax and leave it at that. Thoughts?

@Uninen
Copy link
Author

Uninen commented Jan 26, 2020

At least for me during past ~15 years of Django development, most code involving Djano/Jinja templates have mostly or fully been HTML-only (not including special cases when you're intentionally writing something special w/ other languages but usually no code formatter works in those cases).

I'm not sure what's the difference between first case and just implementing the raw Jinja syntax? I think the initial solution could (and should) be as simple as possible, and if someone needs a more fine-tuned API, they can file a new ticket for the specific use case which then can be evaluated case by case. In other words, the basic use case would be jinja-html or whatever the base Jinja syntax is :)

@canibanoglu
Copy link

Alright, that makes a lot of sense :) I'll try to get something up this weekend

@octref
Copy link
Collaborator

octref commented Aug 21, 2020

I'm not sure if something is missing, but this doesn't look right and I'm not familiari with Jinja.

image

I'm using:
https://github.com/samuelcolvin/jinjahtml-vscode/blob/master/syntaxes/jinja.tmLanguage.json

@Uninen
Copy link
Author

Uninen commented Aug 21, 2020

Indeed, no, it does not look right. Jinja is a superset of Django templates, most Django (vscode) plugins seem to get the syntax right.

Although, as with all templates and colorizations, it's also somewhat of opinion as well...

@octref
Copy link
Collaborator

octref commented Aug 22, 2020

It seems django can generate any text file and has no strict grammar. How should it be highlighted then?

@Uninen
Copy link
Author

Uninen commented Aug 22, 2020

Well that is true in the sense that Django is just a tool like Vue, but Django templates do have a strictly defined grammar just as Vue templates do. (You can opt-out from using the template language but obviously then you're not expecting to use template highlighter tools either.)

I'm not really sure how Django templates are defined, though. I'm sorry if my previous comment was misleading. I meant that the styling (theme) of the syntax highlighting is a matter of opinion, not the syntax itself. (In the posted example above the HTML is not properly highlighted for example, but most Django template tools do highlight HTML as it should be in my opinion.)

If it helps I can dig up the source for Django templates or maybe some examples of vscode plugins? I'm not an expert of these matters by any means but I'm happy to help in any way I can.

@octref
Copy link
Collaborator

octref commented Aug 26, 2020

OK, I added jinja-html lang:

image

@octref octref closed this as completed in 0c88c0f Aug 26, 2020
antfu added a commit that referenced this issue Jan 26, 2024
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

3 participants