@vojtaholik/static-kit-core 2.1.3 → 2.1.4

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/vlna.ts +9 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vojtaholik/static-kit-core",
3
- "version": "2.1.3",
3
+ "version": "2.1.4",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {
package/src/vlna.ts CHANGED
@@ -49,6 +49,10 @@ export function preventWidow(text: string): string {
49
49
  return text.replace(/\s(\S{1,15})\s*$/, "\u00A0$1");
50
50
  }
51
51
 
52
+ /** Block-level closing tags — widow prevention only applies before these */
53
+ const BLOCK_CLOSE_RE =
54
+ /^<\/(p|div|li|h[1-6]|td|th|blockquote|figcaption|section|article|dd|dt|summary|caption)\b/i;
55
+
52
56
  /** Tags whose text content should NOT be transformed */
53
57
  const SKIP_TAGS = new Set([
54
58
  "script",
@@ -112,7 +116,11 @@ export function vlnaHtml(html: string): string {
112
116
  if (inSkipTag) {
113
117
  result += text;
114
118
  } else {
115
- result += preventWidow(vlna(text));
119
+ const transformed = vlna(text);
120
+ // Only prevent widows before a closing block tag or end of string
121
+ const rest = html.slice(textEnd);
122
+ const atBlockEnd = nextTag === -1 || BLOCK_CLOSE_RE.test(rest);
123
+ result += atBlockEnd ? preventWidow(transformed) : transformed;
116
124
  }
117
125
 
118
126
  i = textEnd;