@mgdis/core-ui-helpers 1.0.6 → 1.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1582,7 +1582,7 @@
1582
1582
  */
1583
1583
  const minify = (html, config) => {
1584
1584
  let reinsert_ignored = false;
1585
- const { checked_html, ignored } = getState();
1585
+ const { checked_html, ignored, constants } = getState();
1586
1586
 
1587
1587
  if (!checked_html && !isHtml(html)) return html
1588
1588
 
@@ -1613,6 +1613,18 @@
1613
1613
  // Collapse any remaining multiple spaces to single spaces.
1614
1614
  html = html.replace(/ {2,}/g, ' ');
1615
1615
 
1616
+ // Protect space between text content and an opening tag (e.g., "text <a>")
1617
+ html = html.replace(
1618
+ /(\S) (<[a-zA-Z][a-zA-Z0-9_:-]*)/g,
1619
+ `$1___MINIFY-PROTECTED-SPACE___$2`
1620
+ );
1621
+
1622
+ // Protect space between a closing tag and text content (e.g., "</a> text")
1623
+ html = html.replace(
1624
+ /(<\/[a-zA-Z][a-zA-Z0-9_:-]*>) (\S)/g,
1625
+ `$1___MINIFY-PROTECTED-SPACE___$2`
1626
+ );
1627
+
1616
1628
  // Remove specific single spaces between tags and whitespace within tags.
1617
1629
  html = html.replace(/ >/g, ">"); // <tag > -> <tag>
1618
1630
  html = html.replace(/ </g, "<"); // leading space before tag
@@ -1621,6 +1633,9 @@
1621
1633
  html = html.replace(/<\s+\//g, '</'); // < /tag> -> </tag>
1622
1634
  html = html.replace(/<\/\s+/g, '</'); // </ tag> -> </tag>
1623
1635
 
1636
+ // Unprotect space around inner tags
1637
+ html = html.replace(new RegExp('___MINIFY-PROTECTED-SPACE___', 'g'), ' ');
1638
+
1624
1639
  // Trim spaces around equals signs in attributes (run before value trim)
1625
1640
  // This handles `attr = "value"` -> `attr="value"`
1626
1641
  html = html.replace(/ = /g, "=");
@@ -1765,6 +1780,9 @@
1765
1780
  output_lines[output_lines.length - 1] =
1766
1781
  output_lines.at(-1) + current_line_value.charAt(0);
1767
1782
  current_line_value = current_line_value.slice(1).trim();
1783
+
1784
+ /* If nothing left after extracting punctuation, skip this line. */
1785
+ if (current_line_value.length === 0) return
1768
1786
  }
1769
1787
  }
1770
1788