Skip to content

Commit

Permalink
Fix incomplete HTML not preserved
Browse files Browse the repository at this point in the history
  • Loading branch information
mohd-akram committed Dec 20, 2023
1 parent 45a538c commit c6ecffb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ function format(/** @type {string} */ html, indent = " ", width = 80) {
for (const s of args) {
let out = "";

if (!specialElement && /^\s*$/.test(s)) {
if (!s || (!specialElement && /^\s*$/.test(s))) {
const newline = span.indexOf("\n");
const len = newline == -1 ? span.length : newline;
if (lastSpace) {
Expand Down
6 changes: 6 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,12 @@ test(
"Collector's\n<div>\n stuff\n</div>'"
);

test(
"Preserve incomplete HTML",
"<pre>do not remove me",
"<pre>do not remove me"
);

test(
"Handle invalid HTML",
"< this is a very long sentence to test the regex",
Expand Down

0 comments on commit c6ecffb

Please sign in to comment.