@oxyhq/core 10.1.1 → 10.1.2

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.
@@ -59,12 +59,11 @@ const INLINE_NEEDS_NORMALIZATION = /[^\x20-\x7E]|^ | $| {2}/;
59
59
  /**
60
60
  * Same idea as {@link INLINE_NEEDS_NORMALIZATION}, for MULTILINE values: `\n`
61
61
  * joins the printable-ASCII fast-path alphabet, and the additional shapes a
62
- * normalized body can never contain are a space before a line break (trailing
63
- * horizontal whitespace) and a run of three line breaks (more than one blank
64
- * line). A single space AFTER a line break is legal — a one-space indent is
65
- * the author's, and normalization deliberately preserves it.
62
+ * normalized body can never contain are a space adjacent to a line break — on
63
+ * either side, since every line is trimmed — and a run of three line breaks
64
+ * (more than one blank line).
66
65
  */
67
- const MULTILINE_NEEDS_NORMALIZATION = /[^\x20-\x7E\n]|^[ \n]|[ \n]$| {2}| \n|\n{3}/;
66
+ const MULTILINE_NEEDS_NORMALIZATION = /[^\x20-\x7E\n]|^[ \n]|[ \n]$| {2}| \n|\n |\n{3}/;
68
67
  /** Any run of whitespace, including tabs, line breaks and Unicode spaces. */
69
68
  const ANY_WHITESPACE_RUN = /\s+/g;
70
69
  /**
@@ -86,8 +85,18 @@ const LINE_BREAK_FORMS = /\r\n|\r|\p{Zl}|\p{Zp}/gu;
86
85
  * Applied AFTER {@link LINE_BREAK_FORMS}, so no line break can hide in it.
87
86
  */
88
87
  const HORIZONTAL_WHITESPACE_RUN = /[^\S\n]+/g;
89
- /** Horizontal whitespace at the end of a line — the blank-line spoiler. */
88
+ /**
89
+ * Horizontal whitespace at the END of a line — the blank-line spoiler: it is
90
+ * what makes an "empty" line non-empty and hides it from {@link EXCESS_BLANK_LINES}.
91
+ */
90
92
  const TRAILING_HORIZONTAL_WHITESPACE = / +\n/g;
93
+ /**
94
+ * Horizontal whitespace at the START of a line: source-markup indentation. HTML
95
+ * collapses it by spec, so it is invisible where the text came from and carries
96
+ * no meaning — it only becomes visible once a client renders the value with
97
+ * `white-space: pre-wrap`.
98
+ */
99
+ const LEADING_HORIZONTAL_WHITESPACE = /\n +/g;
91
100
  /** Three or more line breaks: more than one blank line between paragraphs. */
92
101
  const EXCESS_BLANK_LINES = /\n{3,}/g;
93
102
  /**
@@ -131,20 +140,23 @@ export function normalizeInlineText(value) {
131
140
  * 2. Unify every line-break form (CRLF, lone CR, U+2028, U+2029) to `\n`.
132
141
  * 3. Collapse runs of HORIZONTAL whitespace (spaces, tabs, NBSP and friends)
133
142
  * to a single space. Line breaks are untouched.
134
- * 4. Strip the horizontal whitespace at the END of each line.
143
+ * 4. Strip the horizontal whitespace at BOTH ends of every line.
135
144
  * 5. Collapse three or more line breaks to exactly one blank line (`\n\n`).
136
- * 6. Trim both ends.
145
+ * 6. Trim both ends of the value.
137
146
  *
138
147
  * STEP 4 MUST PRECEDE STEP 5 — this is the whole point of the function. A
139
148
  * "blank" line that actually contains spaces (`"a\n \n \nb"`) breaks the
140
149
  * run of `\n` characters, so a bare `\n{3,}` collapse (step 5 alone) never sees
141
150
  * it and the extra blank lines survive into the UI. That is exactly the bug in
142
- * federated post bodies. Removing the trailing horizontal whitespace first
143
- * turns those lines into real, empty lines, which step 5 then collapses.
151
+ * federated post bodies. Trimming each line first turns those lines into real,
152
+ * empty lines, which step 5 then collapses.
144
153
  *
145
- * A single space at the START of a line is preserved: only RUNS of horizontal
146
- * whitespace collapse, and an indent is not trailing whitespace, so a one-space
147
- * indent is treated as the author's and left alone.
154
+ * Every line is trimmed on BOTH sides, so a leading indent is removed outright
155
+ * rather than reduced to one space. Step 3 has already destroyed whatever indent
156
+ * the author wrote (`" Mundo"` `" Mundo"`), so a surviving space would not
157
+ * be the author's intent — it would be an arbitrary remnant of exactly the
158
+ * source-markup indentation this function exists to erase, and `pre-wrap` renders
159
+ * it. Indentation is invisible in HTML by spec; it must be invisible here too.
148
160
  *
149
161
  * A value that is empty or whitespace-only returns `''`.
150
162
  *
@@ -159,6 +171,7 @@ export function normalizeMultilineText(value) {
159
171
  .replace(LINE_BREAK_FORMS, '\n')
160
172
  .replace(HORIZONTAL_WHITESPACE_RUN, ' ')
161
173
  .replace(TRAILING_HORIZONTAL_WHITESPACE, '\n')
174
+ .replace(LEADING_HORIZONTAL_WHITESPACE, '\n')
162
175
  .replace(EXCESS_BLANK_LINES, '\n\n')
163
176
  .trim();
164
177
  }