-
-
Notifications
You must be signed in to change notification settings - Fork 6
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
Enable Django-like template formatting support #4
Comments
Seems we need upgrade dependencies, PR welcome. |
Are you sure about that? From what I can tell, the commit that added this support was already available in 3.0.0, and coc-html is using 3.0.2 (see also the js-beautify 1.10 release notes). Those release notes also mention:
So I'm not sure why it isn't enabled by default in the case of coc-html. Or did you mean some other dependency that needs to be upgraded? |
I don't know how to enable it, you can help to look at the source code. |
Hi guys I found the solution just add "django" to to "html-filetypes" in coc-settings.json ex: |
Doesn't work for me.
All my html files are auto-set to ft=htmldjango coc-settings.json {
"html.enable": true,
"html.filetypes": [
"html",
"handlebars",
"django",
"htmldjango"
],
"html.format.enable": true
} Tried with django only (and changing the file filetype=django) and htmldjango only, didn't change anything.
Not seeing any html format provider option available from coc-settings though: After exporting logs
I couldn't figure out how to get languages to create a service source html |
Checkout |
Thanks! ~/.vimrc let g:coc_filetype_map = {
\ 'htmldjango': 'html',
\ } coc-settings.js "html.enable": true,
"html.format.enable": true,
"html.filetypes": [
"html",
"htmldjango"
], When I run ':Format' ( If I add Looks like all the django stuff is just ignored and leaved as is. What I wish the formatter to do is either one of the 2 following versions: Any idea how to get there? Note that I tried setting let g:coc_filetype_map = {
\ 'htmldjango': 'django',
\ } with "html.enable": true,
"html.format.enable": true,
"html.filetypes": [
"django"
], And "tailwindCSS.htmlLanguages": [
"django"
], After opening my file $ ps auxw|grep node-ipc
dori 1006799 60.0 0.3 941200 115196 ? Sl 11:43 0:01 /usr/bin/node /home/dori/.config/coc/extensions/node_modules/coc-tailwindcss/lsp/tailwindcss-language-server/dist/index.js --node-ipc --clientProcessId=1006784
dori 1006921 0.0 0.0 7628 2432 pts/4 S+ 11:43 0:00 grep --color=auto node-ipc tailwindcss server is started, but not the html one. @chemzqm any idea why? What I understand is that I should map htmldjango to django for coc-html to apply django formatting to my file, but coc-html will only work with filetype html at the moment. And it lets prettier take over if coc-prettier is installed without any custom global or local settings. |
@chemzqm another issue: the filetype map conflicts with coc-snippets. In coc-snippets, "django" filetype is associated to python files (models & co), while "htmldjango" filetype is associated to templates. I think this makes sense. Instead of remapping htmldjango to django for coc-html, it would make more sense to rename all occurences of "django" to "htmldjango" in coc-html's source code. $ perl -p -i -e 's/django/htmldjango/g' ~/.config/coc/extensions/node_modules/coc-html/lib/server.js |
Yes, PR welcome |
Thanks for updating the plugin. Unfortunately, the formatting is still quite unsatisfactory: test: <span class="flex items-center mt-3">
{%for _ in '12345'|make_list %}
{% if forloop.counter <= page.rating %}
<span class="mr-3 text-{{ current_category.color }}-400">
{% include 'svg/rating-star.svg' %}
</span>
{% else %}
<span class="mr-3">
{% include 'svg/rating-star-empty.svg' %}
</span>
{% endif %}
{% endfor %}
</span> coc-html :Format <span class="flex items-center mt-3">
{%for _ in '12345'|make_list %}
{% if forloop.counter <= page.rating %}
<span class="mr-3 text-{{ current_category.color }}-400">
{% include 'svg/rating-star.svg' %}
</span>
{% else %}
<span class="mr-3">
{% include 'svg/rating-star-empty.svg' %}
</span>
{% endif %}
{% endfor %}
</span> vim visual selection and <span class="flex items-center mt-3">
{%for _ in '12345'|make_list %}
{% if forloop.counter <= page.rating %}
<span class="mr-3 text-{{ current_category.color }}-400">
{% include 'svg/rating-star.svg' %}
</span>
{% else %}
<span class="mr-3">
{% include 'svg/rating-star-empty.svg' %}
</span>
{% endif %}
{% endfor %}
</span> = is much better already. Also, nothing will auto-add spaces in tags I looked around, but neither js-beautify nor prettier have support for django template formatting at the moment, it seems. |
Same as VSCode, it's formatted by https://github.com/Microsoft/vscode-html-languageservice, you can send feature request there |
Could someone integrate this library https://pypi.org/project/djhtml/1.2.0/ with this plugin? Reopen maybe ? |
Django templates syntax support is still not present, can it be changed? |
You should use vim syntax plugin for that. |
It's python package, you can use vim plugin that make use of it or simply write a command yourself. |
Provide reference information for carers: try coc-htmldjango |
coc-html (via
vscode-html-languageservice
) supports Handlebars templates, e.g. this formats as expected:But when using Django-like templating by replacing
{{
and}}
with{%
and%}
, the formatter can't handle that:However, looking at the
vscode-html-languageservice
source code it appears that Django templating is supported as well.Is there a way to make this work with coc-html?
The text was updated successfully, but these errors were encountered: