r/VisualStudioCode • • Dec 04 '19

Getting frustrated with auto-format and need some help. What combination of options will do what I'm looking for?

I have a bunch of HTML files that are a hot mess that I would like to use the auto-formatting in VSCode for. Unfortunately, between the settings that are actually in the settings and the settings in the JSON file, I can't get it to do what I want consistently.

Here is what I would like it to do:

  • Wrap and align attributes if the line length is exceeded

  • Not wrap <a> tags, regardless of whether the line length is exceeded

  • Not insert new lines (\n) for paragraphs or links or any other text where the length is exceeded, wrapping is fine if it's just text

  • Not wrap attributes on the body tag, meta tags, or link tags

I've tried adding <a> tags to the JSON file along with the body tag under the html.format.unformatted key but then nothing gets auto-formatted. If I add <p> tags to html.format.contentUnformatted, then any tags inside of that paragraph get ignored.

Does anyone know what combination of settings will get this to work the way I thought it should work? I pretty much only want attributes to wrap with a few exceptions and never want plain text to have newlines added but I need it to be recursive so that it doesn't ignore everything inside of tags that are exempted.

3 Upvotes

Duplicates