D
D
dopo7a2021-12-03 18:51:46
Visual Studio Code
dopo7a, 2021-12-03 18:51:46

Visual studio code formatter - how to exclude part of the code from processing?

Hello.

(Formatter in VSC can be launched like this: alt+shift+f or ctrl+shift+p+"format document")
How to exclude part of the code from processing by the built-in VSC formatter?
Let me explain with an example of HTML.
Code part:

...
<div>...<div
><div>...</div>
...

After the formatter, this part becomes:
...
<div>...<div>
<div>...</div>
...

It is required that the formatter does not touch such places. And if the built-in one can’t be configured and tricked like that, then are there third-party preening/formatting plugins that allow you to exclude individual pieces of code from processing?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
dopo7a, 2021-12-28
@dopo7a

I am providing an answer to my own question.
VSC has this setting:

// Keep text content together between this string.
  "html.format.unformattedContentDelimiter": "",

which can be accessed through the interface like this:
Extensions>HTML>Format: Unformatted Content Delimiter.

If you set a separator in this setting, for example, this:
<!--unformat-->,
then my question is solved like this:
<!--unformat-->
  <div
  ><div></div>
  </div>
<!--unformat-->

During autoformat, the code between delimiters will not be affected.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question