@spintax/core 0.1.4 → 0.1.5

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.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,42 @@
3
3
  All notable changes to `@spintax/core` are documented here. This project adheres to
4
4
  [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
5
5
 
6
+ ## 0.1.5 — 2026-07-13
7
+
8
+ Spanish post-process fix. No API change.
9
+
10
+ ### Fixed
11
+
12
+ - **`postProcess` no longer strips the capital from every Spanish sentence.** Spanish is the only
13
+ European language whose punctuation *opens* a sentence, and the capitalization passes upper-cased
14
+ the first **character** after a sentence boundary — which, for `¿cómo estás?`, is `¿`. An inverted
15
+ mark has no uppercase form, so the pass was a no-op and the real first letter stayed lowercase.
16
+ The spacing pass had the mirror-image gap: it knew "no space *before* closing punctuation" but had
17
+ no rule for an opener, so `¿ qué tal ?` only half-collapsed.
18
+
19
+ ```
20
+ hola. ¿cómo estás? ¡genial! → Hola. ¿Cómo estás? ¡Genial!
21
+ Hola. ¿ qué tal ? → Hola. ¿Qué tal?
22
+ ```
23
+
24
+ A new `SENTENCE_OPENERS = '¿¡'` concept drives both: an opener binds to the word it opens (before
25
+ capitalization, deliberately), and the four capitalization sites — start of text, after `.!?…`,
26
+ after a block-level tag, and after a newline — allow an optional opener between the boundary and
27
+ the letter. HTML paragraphs and multi-line templates were broken exactly like the bare `. ¿` case.
28
+
29
+ The opener set is deliberately **narrow**: quotes and brackets both open *and* close, so
30
+ capitalizing after them would mangle list markers (`Elige una. (a) primero`). Golden-corpus
31
+ fixtures guard both the fix and its narrowness, in **both** engines.
32
+
33
+ ### Notes
34
+
35
+ - Mirrored into the PHP plugin engine to hold the post-process parity contract. Verified against the
36
+ shared golden corpus in both engines: TS 230 tests; the conformance runner against the real plugin
37
+ engine 99 tests / 112 assertions; the plugin's own suite 578 tests, no regressions.
38
+ - The plugin carries the same fix but ships it in a later release, so for a short window a published
39
+ plugin and this package can differ on Spanish output. The parity *contract* holds — the engines'
40
+ behavior agrees and the corpus proves it — only the release timing differs.
41
+
6
42
  ## 0.1.4 — 2026-07-13
7
43
 
8
44
  A post-process bug fix (hit in production) plus docs. No API change.
package/dist/index.cjs CHANGED
@@ -913,13 +913,19 @@ var DECIMAL_RE = /\b\d+\.\d+\b/gu;
913
913
  var MULTI_ABBR_RE = new RegExp(`\\b(?:\\p{L}{1,2}\\.${S}*){2,}`, "gu");
914
914
  var SINGLE_ABBR_RE = new RegExp(`(?<![\\p{L}\\p{N}])(?:${SINGLE_ABBREVS.join("|")})\\.(?=${S}|$|<)`, "giu");
915
915
  var TRAILING_PUNCT_RE = /([.,;:!]+)$/u;
916
+ var SENTENCE_OPENERS = "\xBF\xA1";
917
+ var OPEN = `[${SENTENCE_OPENERS}]?${S}*`;
916
918
  var SPACE_BEFORE_PUNCT_RE = new RegExp(`${S}+([,;:!?.])`, "gu");
917
919
  var SPACE_AFTER_COMMA_RE = new RegExp(`([,;:])(?!\\d)(?!${S}|$|<)`, "gu");
918
920
  var SPACE_AFTER_SENTENCE_RE = new RegExp(`([.!?])(?!\\d)(?!${S}|$|<)`, "gu");
919
- var CAP_FIRST_RE = new RegExp(`^(${S}*(?:<[^>]+>${S}*)*)(\\p{Ll})`, "u");
920
- var CAP_AFTER_SENTENCE_RE = new RegExp(`([.!?\u2026])(${S}*(?:<\\/?[^>]+>${S}*)*)(\\p{Ll})`, "gu");
921
- var CAP_AFTER_BLOCK_RE = new RegExp(`(<\\/?(?:p|h[1-6]|li|blockquote|div|td|th)[^>]*>${S}*)(\\p{Ll})`, "giu");
922
- var CAP_AFTER_BREAK_RE = new RegExp(`(\\n${S}*)(\\p{Ll})`, "gu");
921
+ var SPACE_AFTER_OPENER_RE = new RegExp(`([${SENTENCE_OPENERS}])${S}+`, "gu");
922
+ var CAP_FIRST_RE = new RegExp(`^(${S}*(?:<[^>]+>${S}*)*${OPEN})(\\p{Ll})`, "u");
923
+ var CAP_AFTER_SENTENCE_RE = new RegExp(`([.!?\u2026])(${S}*(?:<\\/?[^>]+>${S}*)*${OPEN})(\\p{Ll})`, "gu");
924
+ var CAP_AFTER_BLOCK_RE = new RegExp(
925
+ `(<\\/?(?:p|h[1-6]|li|blockquote|div|td|th)[^>]*>${S}*${OPEN})(\\p{Ll})`,
926
+ "giu"
927
+ );
928
+ var CAP_AFTER_BREAK_RE = new RegExp(`(\\n${S}*${OPEN})(\\p{Ll})`, "gu");
923
929
  var up = (ch) => ch.toUpperCase();
924
930
  function postProcess(input) {
925
931
  const placeholders = /* @__PURE__ */ new Map();
@@ -951,6 +957,7 @@ function postProcess(input) {
951
957
  text = text.replace(SPACE_BEFORE_PUNCT_RE, "$1");
952
958
  text = text.replace(SPACE_AFTER_COMMA_RE, "$1 ");
953
959
  text = text.replace(SPACE_AFTER_SENTENCE_RE, "$1 ");
960
+ text = text.replace(SPACE_AFTER_OPENER_RE, "$1");
954
961
  text = text.replace(CAP_FIRST_RE, (_m, lead, ch) => lead + up(ch));
955
962
  text = text.replace(CAP_AFTER_SENTENCE_RE, (_m, p, gap, ch) => p + gap + up(ch));
956
963
  text = text.replace(CAP_AFTER_BLOCK_RE, (_m, tag, ch) => tag + up(ch));