@adeu/core 1.25.0 → 1.26.0

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/src/utils/docx.ts CHANGED
@@ -560,6 +560,27 @@ export function get_run_style_markers(
560
560
  return [prefix, suffix];
561
561
  }
562
562
 
563
+ /**
564
+ * Splits `text` into [leading_ws, core, trailing_ws]. Emphasis markers must
565
+ * wrap only the core: `**The Supplier **` (a bold run with a trailing space)
566
+ * is malformed Markdown — CommonMark requires the closing delimiter to hug
567
+ * non-whitespace — and it poisons every downstream CriticMarkup consumer
568
+ * (QA 2026-07-19 F-03/F-10). Fully-whitespace text yields ["", "", text] so
569
+ * callers skip the markers entirely.
570
+ */
571
+ export function split_boundary_whitespace(
572
+ text: string,
573
+ ): [string, string, string] {
574
+ const core = text.trim();
575
+ if (!core) return ["", "", text];
576
+ const lead_len = text.length - text.trimStart().length;
577
+ return [
578
+ text.substring(0, lead_len),
579
+ text.substring(lead_len, lead_len + core.length),
580
+ text.substring(lead_len + core.length),
581
+ ];
582
+ }
583
+
563
584
  export function apply_formatting_to_segments(
564
585
  text: string,
565
586
  prefix: string,
@@ -567,10 +588,17 @@ export function apply_formatting_to_segments(
567
588
  ): string {
568
589
  if (!prefix && !suffix) return text;
569
590
  if (!text) return "";
570
- if (!text.includes("\n")) return `${prefix}${text}${suffix}`;
591
+
592
+ const wrap = (segment: string): string => {
593
+ const [lead, core, trail] = split_boundary_whitespace(segment);
594
+ if (!core) return segment;
595
+ return `${lead}${prefix}${core}${suffix}${trail}`;
596
+ };
597
+
598
+ if (!text.includes("\n")) return wrap(text);
571
599
 
572
600
  const parts = text.split("\n");
573
- return parts.map((p) => (p ? `${prefix}${p}${suffix}` : "")).join("\n");
601
+ return parts.map((p) => (p ? wrap(p) : "")).join("\n");
574
602
  }
575
603
 
576
604
  export function get_run_text(run: Run): string {