@vojtaholik/static-kit-core 2.1.2 → 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 +22 -3
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vojtaholik/static-kit-core",
3
- "version": "2.1.2",
3
+ "version": "2.1.4",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {
package/src/vlna.ts CHANGED
@@ -23,11 +23,21 @@
23
23
  const SINGLE_CHAR_RE = /(?<=\s|^)([ksvzouaiKSVZOUAI]) /g;
24
24
 
25
25
  /**
26
- * Replace space after single-char Czech prepositions/conjunctions with \u00A0.
26
+ * Short (2–3 char) Czech prepositions that shouldn't end a line.
27
+ * Case-insensitive match at word boundary.
28
+ */
29
+ const SHORT_PREP_RE =
30
+ /(?<=\s|^)(bez|nad|pod|pro|při|přes|před|mezi|jako|ani|ale|nebo|Bez|Nad|Pod|Pro|Při|Přes|Před|Mezi|Jako|Ani|Ale|Nebo|BEZ|NAD|POD|PRO|PŘI|PŘES|PŘED|MEZI|JAKO|ANI|ALE|NEBO|do|ke|ku|na|od|po|se|ve|za|ze|Do|Ke|Ku|Na|Od|Po|Se|Ve|Za|Ze|DO|KE|KU|NA|OD|PO|SE|VE|ZA|ZE) /g;
31
+
32
+ /**
33
+ * Replace space after Czech prepositions/conjunctions with \u00A0.
34
+ * Handles single-char (k, s, v…) and short words (bez, nad, pro…).
27
35
  * Plain text only — no HTML awareness.
28
36
  */
29
37
  export function vlna(text: string): string {
30
- return text.replace(SINGLE_CHAR_RE, "$1\u00A0");
38
+ return text
39
+ .replace(SINGLE_CHAR_RE, "$1\u00A0")
40
+ .replace(SHORT_PREP_RE, "$1\u00A0");
31
41
  }
32
42
 
33
43
  /**
@@ -39,6 +49,10 @@ export function preventWidow(text: string): string {
39
49
  return text.replace(/\s(\S{1,15})\s*$/, "\u00A0$1");
40
50
  }
41
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
+
42
56
  /** Tags whose text content should NOT be transformed */
43
57
  const SKIP_TAGS = new Set([
44
58
  "script",
@@ -49,6 +63,7 @@ const SKIP_TAGS = new Set([
49
63
  "kbd",
50
64
  "var",
51
65
  "samp",
66
+ "title",
52
67
  ]);
53
68
 
54
69
  /**
@@ -101,7 +116,11 @@ export function vlnaHtml(html: string): string {
101
116
  if (inSkipTag) {
102
117
  result += text;
103
118
  } else {
104
- result += 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;
105
124
  }
106
125
 
107
126
  i = textEnd;