From c6ecffbbfeec1c075e9177c58ab761de4d457ea3 Mon Sep 17 00:00:00 2001 From: Mohamed Akram Date: Wed, 20 Dec 2023 13:45:05 +0400 Subject: [PATCH] Fix incomplete HTML not preserved --- index.js | 2 +- test.js | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index b9b31fa..31d294b 100644 --- a/index.js +++ b/index.js @@ -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) { diff --git a/test.js b/test.js index 1ec318e..59ab6a2 100644 --- a/test.js +++ b/test.js @@ -272,6 +272,12 @@ test( "Collector's\n
\n stuff\n
'" ); +test( + "Preserve incomplete HTML", + "
do not remove me",
+  "
do not remove me"
+);
+
 test(
   "Handle invalid HTML",
   "< this is a very long sentence to test the regex",