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 sends comments to a new line when the comment does not include a space as the first character

See original GitHub issue

Description

The HTML formatter sends comments to a new line when the comment does not include a space as the first character. It works properly when the HTML comment starts with any white space character. I believe the issue is here: https://github.com/beautify-web/js-beautify/blob/master/js/src/html/beautifier.js#L698

Related issues: #1337 #426

Input

The code looked like this before beautification:

<!--start button--><button>Click here</button><!--end button-->

Expected Output

The code should have looked like this after beautification:

<!--start button--><button>Click here</button><!--end button-->

Actual Output

The code actually looked like this after beautification:

<!--start button--><button>Click here</button>
<!--end button-->

To have this function properly add a space at the start of the second comment.

Input

The code looked like this before beautification:

<!--start button--><button>Click here</button><!-- end button-->

Actual Output

The code actually looked like this after beautification:

<!--start button--><button>Click here</button><!-- end button-->

Environment

I tested this on beautifier.io

Settings

{
  "indent_size": "2",
  "indent_char": " ",
  "max_preserve_newlines": "-1",
  "preserve_newlines": false,
  "keep_array_indentation": false,
  "break_chained_methods": false,
  "indent_scripts": "normal",
  "brace_style": "collapse",
  "space_before_conditional": false,
  "unescape_strings": false,
  "jslint_happy": false,
  "end_with_newline": false,
  "wrap_line_length": "0",
  "indent_inner_html": true,
  "comma_first": false,
  "e4x": false,
  "indent_empty_lines": false
}

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
cfyacommented, Aug 24, 2020

I would like to work on this @avigoldman @aashigupta19

2reactions
bitwisemancommented, Apr 13, 2021

To clarify, I think the requested behavior is that the following input remains unchanged:

<button>Click here</button><!--end button-->
<button>Click here</button><!-- end button-->
<button>Click here</button>
<!--end button-->
<button>Click here</button>
<!-- end button-->
Read more comments on GitHub >

github_iconTop Results From Across the Web

HTML Comments - W3Schools
HTML comments are not displayed in the browser, but they can help document your HTML source code. HTML Comment Tag. You can add...
Read more >
Render a string in HTML and preserve spaces and linebreaks
As part of that I have a description (retrieved from a db) that has spaces and new lines. When it is rendered the...
Read more >
RFC 2822: Internet Message Format
RFC 2822 Internet Message Format April 2001 that wherever this standard allows for folding white space (not simply WSP characters), a CRLF may...
Read more >
Aardvark Comment Format - The Open Group
Review comments or `bugs' should be phrased wherever possible in terms of ... NOTE that page and line numbers must not include spaces:...
Read more >
1. Creating Your First Page - Creating a Website - O'Reilly
Every web page you build along the way will be a bona fide HTML document. Note. The HTML standard doesn't have anything to...
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