Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

226
Views
How to configure prettier in a browser to ident html

I want to format html just by indention. So I've found out that I can do that using prettier. Here is my current options:

import prettier from 'prettier/standalone';
import htmlParser from 'prettier/parser-html';

    return prettier.format(source, {
                    parser: 'html',
                    plugins: [htmlParser],
                    tabWidth: 2,
                    htmlWhitespaceSensitivity: "strict",
                    bracketSpacing: false,
                });

What I see is that most of the tags are broken and some didn't start from the new line:

<li><p style="margin:0" 
              >123321<a
                href="https://123"
                >123</a
              > 
              (<a href="https://abc">abc</a
              >)</p
            ></li 
          > 
          <li
            ><p style="margin:0"
              ><a
                href="https://xyz"
                >xyz</a
              ></p
            ></li
          >

What I want is

<li>
    <p style="margin:0">123321
        <a href="https://123">123</a>
    </p>
</li>
<li>
    <p style="margin:0">
        <a href="https://xyz">xyz</a>
    </p>
</li>

Any ideas what prettier options would help to achieve that?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can set htmlWhitespaceSensitivity to "ignore" in your options. See https://prettier.io/docs/en/options.html#html-whitespace-sensitivity.

return prettier.format(source, { 
        parser: 'html', 
        plugins: [htmlParser], 
        tabWidth: 2, 
        htmlWhitespaceSensitivity: "ignore"
    });

The output doesn't look exactly like you wanted it, but closer.

<li>
  <p style="margin: 0">
    123321
    <a href="https://123">123</a>
    (
    <a href="https://abc">abc</a>
    )
  </p>
</li>
<li>
  <p style="margin: 0"><a href="https://xyz">xyz</a></p>
</li>
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!