microsoft / vscode

Visual Studio Code
https://code.visualstudio.com
MIT License
163.71k stars 29.09k forks source link

HTML img tag is reformatted despite setting "html.format.unformatted" #13177

Closed ph-dev-2016 closed 7 years ago

ph-dev-2016 commented 8 years ago

Steps to Reproduce:

  1. VS Code's setting "html.format.unformatted": includes img, so it should NOT be reformatted
  2. I have an img tag in Django HTML template. <img src="{% static "notesapp/site_icon.png" %}" alt="site_icon" style="width:150px;height:150px;" />
  3. If I press CTRL-S to save the file, VS Code adds extra space characters around the .png file name. <img src="{% static " notesapp/site_icon.png " %}" alt="site_icon" style="width:150px;height:150px;" />

Because of this the image file is not found when I browse the site This step3 is the bug.

If I save from menu File/Save, then this img tag is NOT reformatted. So it works differently depending on whether you save from CTRL-S or from File menu.

aeschli commented 8 years ago

@ph-dev-2016 Can you add a small code snippet that shows the bug? I'm not able to reproduce.

ph-dev-2016 commented 8 years ago

I included a code snippet, but for some reason Github does not show the text correctly. If this is a line in my Django template file before save <img src="{% static "mysapp/site_icon.png" %}" alt="site_icon" style="width:64x;height:64px;" />

in save it becomes (extra spaces in the static file name in quotes) <img src="{% static " mysapp/site_icon.png " %} " alt="site_icon" style="width:64x;height:64px;" />

aeschli commented 7 years ago

The problem is that your snippet is not really html. From a HTML perspective, the src attribute ends with the first quote: src="{% static ". mysapp/site_icon.png is considered the second attribute. The formatter decides to separate the attributes with a space.

You'd need a proper formatter for Django that takes the templates into account.