@selfhelp/shared 1.14.12 → 1.14.14

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/dist/index.mjs CHANGED
@@ -1015,7 +1015,7 @@ var CLASS_PATTERNS = [
1015
1015
  { prefix: "max-w-", values: [...SIZE_VALUES, "full", "fit", "screen", "none"] },
1016
1016
  { prefix: "max-h-", values: [...SIZE_VALUES, "full", "screen", "none"] },
1017
1017
  // typography
1018
- { prefix: "text-", values: [...SIZE_VALUES, "left", "center", "right", "justify", ...COLOR_SCALE_VALUES] },
1018
+ { prefix: "text-", values: [...SIZE_VALUES, "left", "center", "right", "justify", "white", "black", ...COLOR_SCALE_VALUES] },
1019
1019
  { prefix: "font-", values: ["thin", "light", "normal", "medium", "semibold", "bold", "extrabold", "black"] },
1020
1020
  { prefix: "leading-", values: ["none", "tight", "snug", "normal", "relaxed", "loose"] },
1021
1021
  { prefix: "tracking-", values: ["tighter", "tight", "normal", "wide", "wider", "widest"] },
@@ -1086,10 +1086,78 @@ var LITERAL_CLASSES = /* @__PURE__ */ new Set([
1086
1086
  ]);
1087
1087
 
1088
1088
  // src/cms-classes/remap.ts
1089
+ var TW_SCALE_TO_MANTINE = {
1090
+ "50": "0",
1091
+ "100": "1",
1092
+ "200": "2",
1093
+ "300": "3",
1094
+ "400": "4",
1095
+ "500": "6",
1096
+ "600": "7",
1097
+ "700": "8",
1098
+ "800": "9",
1099
+ "900": "9",
1100
+ "950": "9"
1101
+ };
1102
+ var TW_NAME_TO_MANTINE = {
1103
+ slate: "gray",
1104
+ gray: "gray",
1105
+ zinc: "gray",
1106
+ neutral: "gray",
1107
+ stone: "gray",
1108
+ red: "red",
1109
+ rose: "pink",
1110
+ pink: "pink",
1111
+ fuchsia: "grape",
1112
+ purple: "grape",
1113
+ grape: "grape",
1114
+ violet: "violet",
1115
+ indigo: "indigo",
1116
+ blue: "blue",
1117
+ sky: "cyan",
1118
+ cyan: "cyan",
1119
+ teal: "teal",
1120
+ emerald: "green",
1121
+ green: "green",
1122
+ lime: "lime",
1123
+ yellow: "yellow",
1124
+ amber: "orange",
1125
+ orange: "orange"
1126
+ };
1127
+ var COLOR_PREFIXES = ["bg-", "text-", "border-"];
1128
+ function buildColorScaleRemaps() {
1129
+ const out = [];
1130
+ for (const prefix of COLOR_PREFIXES) {
1131
+ for (const [twName, mantineName] of Object.entries(TW_NAME_TO_MANTINE)) {
1132
+ for (const [twScale, idx] of Object.entries(TW_SCALE_TO_MANTINE)) {
1133
+ out.push({
1134
+ from: `${prefix}${twName}-${twScale}`,
1135
+ to: `${prefix}${mantineName}-${idx}`,
1136
+ reason: "tailwind oklch scale \u2192 mantine hex scale (RN-safe)"
1137
+ });
1138
+ }
1139
+ }
1140
+ }
1141
+ return out;
1142
+ }
1143
+ var INTERACTIVE_DROP = [
1144
+ "hover:bg-gray-100",
1145
+ "hover:bg-blue-600",
1146
+ "hover:bg-green-600",
1147
+ "hover:bg-red-600",
1148
+ "hover:text-blue-600",
1149
+ "hover:text-green-600",
1150
+ "hover:text-red-600",
1151
+ "hover:shadow-md",
1152
+ "hover:shadow-lg",
1153
+ "hover:underline",
1154
+ "focus:outline-none",
1155
+ "focus:ring-2",
1156
+ "focus:ring-blue-500",
1157
+ "focus:ring-offset-2"
1158
+ ].map((from) => ({ from, to: null, reason: "interactive state not applicable on mobile" }));
1089
1159
  var CLASS_REMAP = [
1090
- // hover/focus on mobile only fires for keyboard nav; safe to drop.
1091
- { from: "hover:bg-gray-100", to: null, reason: "hover not applicable on mobile" },
1092
- { from: "hover:underline", to: null, reason: "hover not applicable on mobile" },
1160
+ ...INTERACTIVE_DROP,
1093
1161
  // cursor classes are no-ops on RN.
1094
1162
  { from: "cursor-pointer", to: null, reason: "no cursor on RN" },
1095
1163
  { from: "cursor-default", to: null, reason: "no cursor on RN" },
@@ -1098,7 +1166,9 @@ var CLASS_REMAP = [
1098
1166
  { from: "select-text", to: null, reason: "unsupported on RN" },
1099
1167
  // legacy aliases
1100
1168
  { from: "mantine-fw", to: "w-full" },
1101
- { from: "mantine-h-full", to: "h-full" }
1169
+ { from: "mantine-h-full", to: "h-full" },
1170
+ // standard Tailwind color scale → Mantine hex scale (RN-safe)
1171
+ ...buildColorScaleRemaps()
1102
1172
  ];
1103
1173
  var REMAP_MAP = new Map(CLASS_REMAP.map((r) => [r.from, r]));
1104
1174
  function findRemap(className) {
@@ -1172,6 +1242,149 @@ function resolveAssetSources(sources, baseUrl) {
1172
1242
  return sources.map((s) => ({ ...s, src: resolveAssetUrl(s.src, baseUrl) }));
1173
1243
  }
1174
1244
 
1245
+ // src/content/inlineFormat.ts
1246
+ var HTML_ENTITIES = {
1247
+ "&": "&",
1248
+ "&lt;": "<",
1249
+ "&gt;": ">",
1250
+ "&quot;": '"',
1251
+ "&#39;": "'",
1252
+ "&apos;": "'",
1253
+ "&nbsp;": " ",
1254
+ "&#x2f;": "/",
1255
+ "&#47;": "/"
1256
+ };
1257
+ function decodeEntities(value) {
1258
+ if (!value.includes("&")) return value;
1259
+ return value.replace(/&[a-zA-Z#0-9]+;/g, (entity) => HTML_ENTITIES[entity.toLowerCase()] ?? entity);
1260
+ }
1261
+ function looksLikeJson(trimmed) {
1262
+ const first = trimmed[0];
1263
+ if (first !== "{" && first !== "[") return false;
1264
+ try {
1265
+ JSON.parse(trimmed);
1266
+ return true;
1267
+ } catch {
1268
+ return false;
1269
+ }
1270
+ }
1271
+ var SEPARATOR_TAGS = /* @__PURE__ */ new Set([
1272
+ "br",
1273
+ "p",
1274
+ "div",
1275
+ "li",
1276
+ "ul",
1277
+ "ol",
1278
+ "h1",
1279
+ "h2",
1280
+ "h3",
1281
+ "h4",
1282
+ "h5",
1283
+ "h6",
1284
+ "blockquote",
1285
+ "tr",
1286
+ "section",
1287
+ "article",
1288
+ "header",
1289
+ "footer",
1290
+ "pre"
1291
+ ]);
1292
+ var INLINE_TAG_RE = /<(?:b|strong|i|em|u|a)\b/i;
1293
+ var TAG_RE = /<\/?([a-z][a-z0-9]*)\b([^>]*)>/gi;
1294
+ var HREF_RE = /href\s*=\s*(?:"([^"]*)"|'([^']*)')/i;
1295
+ function extractHref(attrs) {
1296
+ const match = HREF_RE.exec(attrs);
1297
+ return (match?.[1] ?? match?.[2] ?? "").trim();
1298
+ }
1299
+ function formatKey(node) {
1300
+ return `${node.bold ? 1 : 0}|${node.italic ? 1 : 0}|${node.underline ? 1 : 0}|${node.href ?? ""}`;
1301
+ }
1302
+ function parseInlineRich(value) {
1303
+ if (value == null) return [];
1304
+ const str = String(value);
1305
+ if (str === "") return [];
1306
+ const trimmed = str.trim();
1307
+ if (looksLikeJson(trimmed)) return [{ text: str }];
1308
+ if (!str.includes("<")) {
1309
+ const text = decodeEntities(str);
1310
+ return text === "" ? [] : [{ text }];
1311
+ }
1312
+ const raw = [];
1313
+ let bold = 0;
1314
+ let italic = 0;
1315
+ let underline = 0;
1316
+ const hrefStack = [];
1317
+ const pushText = (segment) => {
1318
+ if (segment === "") return;
1319
+ raw.push({
1320
+ text: segment,
1321
+ ...bold > 0 ? { bold: true } : {},
1322
+ ...italic > 0 ? { italic: true } : {},
1323
+ ...underline > 0 ? { underline: true } : {},
1324
+ ...hrefStack.length > 0 ? { href: hrefStack[hrefStack.length - 1] } : {}
1325
+ });
1326
+ };
1327
+ let lastIndex = 0;
1328
+ let match;
1329
+ TAG_RE.lastIndex = 0;
1330
+ while ((match = TAG_RE.exec(str)) !== null) {
1331
+ pushText(str.slice(lastIndex, match.index));
1332
+ lastIndex = TAG_RE.lastIndex;
1333
+ const isClose = match[0].charAt(1) === "/";
1334
+ const tag = match[1].toLowerCase();
1335
+ const attrs = match[2] ?? "";
1336
+ if (tag === "b" || tag === "strong") {
1337
+ bold = isClose ? Math.max(0, bold - 1) : bold + 1;
1338
+ } else if (tag === "i" || tag === "em") {
1339
+ italic = isClose ? Math.max(0, italic - 1) : italic + 1;
1340
+ } else if (tag === "u") {
1341
+ underline = isClose ? Math.max(0, underline - 1) : underline + 1;
1342
+ } else if (tag === "a") {
1343
+ if (isClose) {
1344
+ hrefStack.pop();
1345
+ } else {
1346
+ hrefStack.push(extractHref(attrs));
1347
+ }
1348
+ } else if (SEPARATOR_TAGS.has(tag)) {
1349
+ pushText(" ");
1350
+ }
1351
+ }
1352
+ pushText(str.slice(lastIndex));
1353
+ const merged = [];
1354
+ for (const node of raw) {
1355
+ const prev = merged[merged.length - 1];
1356
+ if (prev && formatKey(prev) === formatKey(node)) {
1357
+ prev.text += node.text;
1358
+ } else {
1359
+ merged.push({ ...node });
1360
+ }
1361
+ }
1362
+ for (const node of merged) {
1363
+ node.text = decodeEntities(node.text).replace(/\s+/g, " ");
1364
+ }
1365
+ if (merged.length > 0) {
1366
+ merged[0].text = merged[0].text.replace(/^\s+/, "");
1367
+ merged[merged.length - 1].text = merged[merged.length - 1].text.replace(/\s+$/, "");
1368
+ }
1369
+ return merged.filter((node) => node.text !== "");
1370
+ }
1371
+ function hasInlineFormatting(value) {
1372
+ if (value == null) return false;
1373
+ const str = String(value);
1374
+ if (!str.includes("<")) return false;
1375
+ if (looksLikeJson(str.trim())) return false;
1376
+ return INLINE_TAG_RE.test(str);
1377
+ }
1378
+ function stripHtmlToText(value) {
1379
+ if (!value || typeof value !== "string") return value ?? "";
1380
+ const trimmed = value.trim();
1381
+ if (looksLikeJson(trimmed)) return value;
1382
+ if (!/[<&]/.test(value)) return value;
1383
+ let out = value.replace(/<br\s*\/?>/gi, " ").replace(/<\/(p|div|li|h[1-6]|tr|blockquote)>/gi, " ").replace(/<[^>]+>/g, "");
1384
+ out = out.replace(/&[a-zA-Z#0-9]+;/g, (entity) => HTML_ENTITIES[entity.toLowerCase()] ?? entity);
1385
+ return out.replace(/\s+/g, " ").trim();
1386
+ }
1387
+
1175
1388
  // src/utils/spacing.ts
1176
1389
  var ALLOWED_KEYS = ["mt", "mb", "ms", "me", "pt", "pb", "ps", "pe"];
1177
1390
  function parseSpacing(raw) {
@@ -1282,6 +1495,7 @@ export {
1282
1495
  getStylePlatforms,
1283
1496
  getStylePluginId,
1284
1497
  gridSpanToReactNativeColumn,
1498
+ hasInlineFormatting,
1285
1499
  isKnownStyleName,
1286
1500
  isRegisteredStyleName,
1287
1501
  isStyleAllowedOnPage,
@@ -1303,6 +1517,7 @@ export {
1303
1517
  mapSpacingToPx,
1304
1518
  parseDimensionToReactNative,
1305
1519
  parseDimensionToWeb,
1520
+ parseInlineRich,
1306
1521
  parseSpacing,
1307
1522
  radiusToPx,
1308
1523
  replaceCalcedValues,
@@ -1319,6 +1534,7 @@ export {
1319
1534
  sizeToFontPx,
1320
1535
  spacingToClasses,
1321
1536
  spacingToPx,
1537
+ stripHtmlToText,
1322
1538
  stylePlatformToSet,
1323
1539
  toHeroUiSemanticProps,
1324
1540
  toMantineSemanticProps,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@selfhelp/shared",
3
- "version": "1.14.12",
3
+ "version": "1.14.14",
4
4
  "description": "Shared TypeScript package for SelfHelp web frontend and mobile app: style registry, types, API contracts, Mantine theme tokens, condition + interpolation engines, CMS class allow-list.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -34,6 +34,24 @@ describe('classifyClass (css_mobile classifier)', () => {
34
34
  expect(classifyClass('grid-cols-7').kind).toBe('drop');
35
35
  expect(classifyClass('').kind).toBe('drop');
36
36
  });
37
+
38
+ it('remaps the web dropdown standard Tailwind color scale onto the Mantine hex scale (RN-safe)', () => {
39
+ // Tailwind v4 default palette is oklch and crashes RN, so the standard
40
+ // scale the dropdown offers is rewritten onto the hex-backed Mantine scale.
41
+ expect(classifyClass('bg-blue-500')).toMatchObject({ kind: 'remap', from: 'bg-blue-500', to: 'bg-blue-6' });
42
+ expect(classifyClass('bg-green-600')).toMatchObject({ kind: 'remap', to: 'bg-green-7' });
43
+ expect(classifyClass('bg-gray-800')).toMatchObject({ kind: 'remap', to: 'bg-gray-9' });
44
+ expect(classifyClass('text-indigo-700')).toMatchObject({ kind: 'remap', to: 'text-indigo-8' });
45
+ expect(classifyClass('border-red-500')).toMatchObject({ kind: 'remap', to: 'border-red-6' });
46
+ // Tailwind-only names alias to the nearest Mantine palette.
47
+ expect(classifyClass('bg-purple-500')).toMatchObject({ kind: 'remap', to: 'bg-grape-6' });
48
+ expect(classifyClass('bg-slate-700')).toMatchObject({ kind: 'remap', to: 'bg-gray-8' });
49
+ });
50
+
51
+ it('allows text-white / text-black (plain colors, RN-safe)', () => {
52
+ expect(classifyClass('text-white').kind).toBe('allow');
53
+ expect(classifyClass('text-black').kind).toBe('allow');
54
+ });
37
55
  });
38
56
 
39
57
  describe('classifyClassString', () => {
@@ -85,7 +85,7 @@ export const CLASS_PATTERNS: readonly IClassPattern[] = [
85
85
  { prefix: 'max-w-', values: [...SIZE_VALUES, 'full', 'fit', 'screen', 'none'] },
86
86
  { prefix: 'max-h-', values: [...SIZE_VALUES, 'full', 'screen', 'none'] },
87
87
  // typography
88
- { prefix: 'text-', values: [...SIZE_VALUES, 'left', 'center', 'right', 'justify', ...COLOR_SCALE_VALUES] },
88
+ { prefix: 'text-', values: [...SIZE_VALUES, 'left', 'center', 'right', 'justify', 'white', 'black', ...COLOR_SCALE_VALUES] },
89
89
  { prefix: 'font-', values: ['thin', 'light', 'normal', 'medium', 'semibold', 'bold', 'extrabold', 'black'] },
90
90
  { prefix: 'leading-', values: ['none', 'tight', 'snug', 'normal', 'relaxed', 'loose'] },
91
91
  { prefix: 'tracking-', values: ['tighter', 'tight', 'normal', 'wide', 'wider', 'widest'] },
@@ -22,10 +22,100 @@ export interface IClassRemap {
22
22
  reason?: string;
23
23
  }
24
24
 
25
+ /**
26
+ * Standard Tailwind numeric color scale (`50..950`) → Mantine hex-backed
27
+ * scale index (`0..9`). The web dropdown (`generate-css-classes.js`) offers
28
+ * the standard Tailwind scale, but Tailwind v4's default palette is authored
29
+ * in `oklch()`, which React Native cannot parse — only the Mantine palettes
30
+ * carried by the shared preset (`theme/tailwind.ts`, indices `0..9`) resolve
31
+ * to RN-safe hex. So we rewrite the dropdown's standard scale onto the Mantine
32
+ * scale instead of dropping it. The shade is the closest visual match; this is
33
+ * a deliberate, documented web→mobile remap.
34
+ */
35
+ const TW_SCALE_TO_MANTINE: Readonly<Record<string, string>> = {
36
+ '50': '0',
37
+ '100': '1',
38
+ '200': '2',
39
+ '300': '3',
40
+ '400': '4',
41
+ '500': '6',
42
+ '600': '7',
43
+ '700': '8',
44
+ '800': '9',
45
+ '900': '9',
46
+ '950': '9',
47
+ };
48
+
49
+ /**
50
+ * Tailwind color name → Mantine palette name. Only Mantine palettes have an
51
+ * RN-safe hex scale in the shared preset; Tailwind-only names (`slate`,
52
+ * `purple`, `sky`, …) are aliased to their nearest Mantine palette.
53
+ */
54
+ const TW_NAME_TO_MANTINE: Readonly<Record<string, string>> = {
55
+ slate: 'gray',
56
+ gray: 'gray',
57
+ zinc: 'gray',
58
+ neutral: 'gray',
59
+ stone: 'gray',
60
+ red: 'red',
61
+ rose: 'pink',
62
+ pink: 'pink',
63
+ fuchsia: 'grape',
64
+ purple: 'grape',
65
+ grape: 'grape',
66
+ violet: 'violet',
67
+ indigo: 'indigo',
68
+ blue: 'blue',
69
+ sky: 'cyan',
70
+ cyan: 'cyan',
71
+ teal: 'teal',
72
+ emerald: 'green',
73
+ green: 'green',
74
+ lime: 'lime',
75
+ yellow: 'yellow',
76
+ amber: 'orange',
77
+ orange: 'orange',
78
+ };
79
+
80
+ const COLOR_PREFIXES = ['bg-', 'text-', 'border-'] as const;
81
+
82
+ /** Build the `{prefix}{twName}-{twScale}` → `{prefix}{mantineName}-{idx}` remaps. */
83
+ function buildColorScaleRemaps(): IClassRemap[] {
84
+ const out: IClassRemap[] = [];
85
+ for (const prefix of COLOR_PREFIXES) {
86
+ for (const [twName, mantineName] of Object.entries(TW_NAME_TO_MANTINE)) {
87
+ for (const [twScale, idx] of Object.entries(TW_SCALE_TO_MANTINE)) {
88
+ out.push({
89
+ from: `${prefix}${twName}-${twScale}`,
90
+ to: `${prefix}${mantineName}-${idx}`,
91
+ reason: 'tailwind oklch scale → mantine hex scale (RN-safe)',
92
+ });
93
+ }
94
+ }
95
+ }
96
+ return out;
97
+ }
98
+
99
+ /** Interactive-state classes the web dropdown offers but RN can't honour. */
100
+ const INTERACTIVE_DROP = [
101
+ 'hover:bg-gray-100',
102
+ 'hover:bg-blue-600',
103
+ 'hover:bg-green-600',
104
+ 'hover:bg-red-600',
105
+ 'hover:text-blue-600',
106
+ 'hover:text-green-600',
107
+ 'hover:text-red-600',
108
+ 'hover:shadow-md',
109
+ 'hover:shadow-lg',
110
+ 'hover:underline',
111
+ 'focus:outline-none',
112
+ 'focus:ring-2',
113
+ 'focus:ring-blue-500',
114
+ 'focus:ring-offset-2',
115
+ ].map((from): IClassRemap => ({ from, to: null, reason: 'interactive state not applicable on mobile' }));
116
+
25
117
  export const CLASS_REMAP: readonly IClassRemap[] = [
26
- // hover/focus on mobile only fires for keyboard nav; safe to drop.
27
- { from: 'hover:bg-gray-100', to: null, reason: 'hover not applicable on mobile' },
28
- { from: 'hover:underline', to: null, reason: 'hover not applicable on mobile' },
118
+ ...INTERACTIVE_DROP,
29
119
  // cursor classes are no-ops on RN.
30
120
  { from: 'cursor-pointer', to: null, reason: 'no cursor on RN' },
31
121
  { from: 'cursor-default', to: null, reason: 'no cursor on RN' },
@@ -35,6 +125,8 @@ export const CLASS_REMAP: readonly IClassRemap[] = [
35
125
  // legacy aliases
36
126
  { from: 'mantine-fw', to: 'w-full' },
37
127
  { from: 'mantine-h-full', to: 'h-full' },
128
+ // standard Tailwind color scale → Mantine hex scale (RN-safe)
129
+ ...buildColorScaleRemaps(),
38
130
  ];
39
131
 
40
132
  const REMAP_MAP = new Map<string, IClassRemap>(CLASS_REMAP.map((r) => [r.from, r]));
@@ -0,0 +1,116 @@
1
+ /*
2
+ SPDX-FileCopyrightText: 2026 Humdek, University of Bern
3
+ SPDX-License-Identifier: MPL-2.0
4
+ */
5
+ import { describe, it, expect } from 'vitest';
6
+ import { parseInlineRich, hasInlineFormatting, stripHtmlToText } from '../inlineFormat';
7
+
8
+ describe('parseInlineRich', () => {
9
+ it('returns a single plain run for tag-free text', () => {
10
+ expect(parseInlineRich('hello world')).toEqual([{ text: 'hello world' }]);
11
+ });
12
+
13
+ it('returns an empty list for empty / nullish input', () => {
14
+ expect(parseInlineRich('')).toEqual([]);
15
+ expect(parseInlineRich(null)).toEqual([]);
16
+ expect(parseInlineRich(undefined)).toEqual([]);
17
+ });
18
+
19
+ it('marks <strong> and <b> as bold', () => {
20
+ expect(parseInlineRich('a <strong>bold</strong> c')).toEqual([
21
+ { text: 'a ' },
22
+ { text: 'bold', bold: true },
23
+ { text: ' c' },
24
+ ]);
25
+ expect(parseInlineRich('<b>x</b>')).toEqual([{ text: 'x', bold: true }]);
26
+ });
27
+
28
+ it('marks <em>/<i> as italic and <u> as underline (merging same-format runs)', () => {
29
+ // <em>e</em><i>i</i> are both italic and adjacent, so they merge.
30
+ expect(parseInlineRich('<em>e</em><i>i</i><u>u</u>')).toEqual([
31
+ { text: 'ei', italic: true },
32
+ { text: 'u', underline: true },
33
+ ]);
34
+ });
35
+
36
+ it('combines nested formatting into one run', () => {
37
+ expect(parseInlineRich('<strong>bold <em>both</em></strong>')).toEqual([
38
+ { text: 'bold ', bold: true },
39
+ { text: 'both', bold: true, italic: true },
40
+ ]);
41
+ });
42
+
43
+ it('captures the href on anchor runs', () => {
44
+ expect(parseInlineRich('see <a href="https://x.test">here</a>')).toEqual([
45
+ { text: 'see ' },
46
+ { text: 'here', href: 'https://x.test' },
47
+ ]);
48
+ });
49
+
50
+ it('flattens the leading <p> wrapper the editor leaves behind', () => {
51
+ // The exact "label authored as plain text but stored wrapped" case.
52
+ expect(parseInlineRich('<p class="single-line-paragraph">9 STEF</p>')).toEqual([
53
+ { text: '9 STEF' },
54
+ ]);
55
+ });
56
+
57
+ it('collapses block tags + <br> to single spaces', () => {
58
+ expect(parseInlineRich('<p>a</p><p>b</p>')).toEqual([{ text: 'a b' }]);
59
+ expect(parseInlineRich('line<br/>break')).toEqual([{ text: 'line break' }]);
60
+ });
61
+
62
+ it('keeps bold across a block boundary as separate runs', () => {
63
+ expect(parseInlineRich('<p><strong>A</strong></p><p>b</p>')).toEqual([
64
+ { text: 'A', bold: true },
65
+ { text: ' b' },
66
+ ]);
67
+ });
68
+
69
+ it('decodes HTML entities', () => {
70
+ expect(parseInlineRich('a &amp; <strong>b&nbsp;c</strong>')).toEqual([
71
+ { text: 'a & ' },
72
+ { text: 'b c', bold: true },
73
+ ]);
74
+ });
75
+
76
+ it('drops unknown tags but keeps their text', () => {
77
+ expect(parseInlineRich('<span class="x">keep</span>')).toEqual([{ text: 'keep' }]);
78
+ });
79
+
80
+ it('never touches structured JSON payloads', () => {
81
+ const json = '{"type":"array","items":["a","b"]}';
82
+ expect(parseInlineRich(json)).toEqual([{ text: json }]);
83
+ });
84
+ });
85
+
86
+ describe('hasInlineFormatting', () => {
87
+ it('is true only when a supported inline tag is present', () => {
88
+ expect(hasInlineFormatting('<strong>x</strong>')).toBe(true);
89
+ expect(hasInlineFormatting('<em>x</em>')).toBe(true);
90
+ expect(hasInlineFormatting('<a href="#">x</a>')).toBe(true);
91
+ });
92
+
93
+ it('is false for plain text, block-only markup, and JSON', () => {
94
+ expect(hasInlineFormatting('plain')).toBe(false);
95
+ expect(hasInlineFormatting('<p>plain</p>')).toBe(false);
96
+ expect(hasInlineFormatting('{"a":1}')).toBe(false);
97
+ expect(hasInlineFormatting(null)).toBe(false);
98
+ });
99
+ });
100
+
101
+ describe('stripHtmlToText', () => {
102
+ it('strips tags to readable plain text', () => {
103
+ expect(stripHtmlToText('<p>a</p><p>b</p>')).toBe('a b');
104
+ expect(stripHtmlToText('<strong>bold</strong> text')).toBe('bold text');
105
+ });
106
+
107
+ it('leaves tag-free strings and JSON untouched', () => {
108
+ expect(stripHtmlToText('plain')).toBe('plain');
109
+ const json = '{"a":1}';
110
+ expect(stripHtmlToText(json)).toBe(json);
111
+ });
112
+
113
+ it('decodes entities', () => {
114
+ expect(stripHtmlToText('a &amp; b')).toBe('a & b');
115
+ });
116
+ });
@@ -0,0 +1,5 @@
1
+ /*
2
+ SPDX-FileCopyrightText: 2026 Humdek, University of Bern
3
+ SPDX-License-Identifier: MPL-2.0
4
+ */
5
+ export * from './inlineFormat';