question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

HTML formatter breaks layout by introducing newlines

See original GitHub issue

Moved here from https://github.com/microsoft/vscode/issues/144042

Description

The HTML formatter breaks the layout of the page.

Input

The code looked like this before beautification:

<span>
  <span>
    <span>1:02</span
    ><time-dot>.</time-dot
    ><time-decimals>27</time-decimals>
  </span>
</span>

Expected Output

The code should have looked like this after beautification:

<!-- no change? -->
<span>
  <span>
    <span>1:02</span
    ><time-dot>.</time-dot
    ><time-decimals>27</time-decimals>
  </span>
</span>

Actual Output

The code actually looked like this after beautification:

<span>
  <span>
    <span>1:02</span>
    <time-dot>.</time-dot>
    <time-decimals>27</time-decimals>
  </span>
</span>

This introduces newlines (and spaces) before and after the <time-dot> element, which adds visual space between the elements on the page that was not there before:

Screen Shot 2022-02-27 at 14 40 15

Steps to Reproduce

Paste into https://beautifier.io/ or format in VSCode.

Environment

OS: N/A

Settings

Default?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
bitwisemancommented, Mar 4, 2022

@lgarron

This is good bug. Took me looking twice at the image, but that made it clear what the problem is. Thanks!

It appears that you want <time-dot> and <time-decimals> to be treated as “inline” elements.

However, the beautifier doesn’t do the end braces the way you said in your expected output. Once you made the elements “inline”, the expected output would be:

<span>
  <span>
    <span>1:02</span><time-dot>.</time-dot><time-decimals>27</time-decimals>
  </span>
</span>

Question: <time-dot> and <time-decimals> are not valid html elements. Where are you getting them?

1reaction
lgarroncommented, Feb 28, 2022

FYI: The bug template says:

  • Do not include screenshots! This library is a text processor, we need text inputs and outputs for debugging and fixing issues.

I assume this means “do not submit screenshots without submitting associated text examples”, not “screenshots are forbidden, even if they illustrate the text examples”. Apologies if that’s not the case.

Read more comments on GitHub >

github_iconTop Results From Across the Web

HTML formatter breaks layout by introducing a newline #144042
This introduces newlines (and spaces) before and after the <time-dot> element, which adds visual space between the elements on the page that ...
Read more >
The Dos and Don'ts of Adding an HTML Line Break
To do a line break in HTML, use the <br> tag. Simply place the tag wherever you want to force a line break....
Read more >
How to prevent VS Code from breaking up long HTML lines ...
I am using prettier for formatting, and have set the printWidth option which works in javascript code, but for HTML it seems to...
Read more >
How to Preserve Newlines, Line Breaks, and Whitespace in ...
Preserve Newlines, Line Breaks, and Whitespace in HTML. Use the white-space: pre; setting to display long-form content containing whitespace ...
Read more >
Add a Line Break in HTML - Tutorial - TeachUcomp, Inc.
This tutorial shows you how to add a line break in HTML. By default, browsers ignore many formatting keystrokes that we take for...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found