@esposter/shared 3.3.0 → 3.5.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.
Files changed (2) hide show
  1. package/dist/index.js +57 -7
  2. package/package.json +3 -3
package/dist/index.js CHANGED
@@ -267,16 +267,43 @@ const transformCellAlign = (tagName, attribs) => {
267
267
  tagName
268
268
  };
269
269
  };
270
+ const transformLink = (tagName, attribs) => ({
271
+ attribs: {
272
+ ...attribs,
273
+ rel: "noopener noreferrer nofollow",
274
+ target: "_blank"
275
+ },
276
+ tagName
277
+ });
278
+ const TEXT_ALIGN_REGEXES = [/^(?:left|right|center|justify)$/u];
279
+ const TABLE_ALLOWED_STYLES = {
280
+ table: {
281
+ "border-collapse": [/^collapse$/u],
282
+ width: [/^100%$/u]
283
+ },
284
+ td: { "text-align": TEXT_ALIGN_REGEXES },
285
+ th: { "text-align": TEXT_ALIGN_REGEXES }
286
+ };
270
287
  const sanitizeHtml = (...[html, options]) => baseSanitizeHtml(html, {
271
288
  ...options,
272
289
  allowedAttributes: {
273
- ...options?.allowedAttributes,
290
+ ...options?.allowedAttributes || baseSanitizeHtml.defaults.allowedAttributes,
291
+ a: [
292
+ "href",
293
+ "rel",
294
+ "target"
295
+ ],
274
296
  table: ["style"],
275
297
  td: ["style"],
276
298
  th: ["style"]
277
299
  },
300
+ allowedStyles: {
301
+ ...options?.allowedStyles,
302
+ ...TABLE_ALLOWED_STYLES
303
+ },
278
304
  transformTags: {
279
305
  ...options?.transformTags,
306
+ a: transformLink,
280
307
  table: (tagName, attribs) => ({
281
308
  attribs: {
282
309
  ...attribs,
@@ -297,12 +324,13 @@ const COLOR_REGEXES = [
297
324
  ];
298
325
  const sanitizeTextHtml = (html) => sanitizeHtml(html, {
299
326
  allowedAttributes: {
300
- a: [
301
- "href",
302
- "rel",
303
- "target"
304
- ],
305
327
  code: ["class"],
328
+ input: [
329
+ "checked",
330
+ "disabled",
331
+ "type"
332
+ ],
333
+ li: ["data-checked", "data-type"],
306
334
  pre: ["class"],
307
335
  span: [
308
336
  "class",
@@ -313,12 +341,34 @@ const sanitizeTextHtml = (html) => sanitizeHtml(html, {
313
341
  MENTION_LABEL_ATTRIBUTE,
314
342
  MENTION_TYPE_ATTRIBUTE,
315
343
  "style"
316
- ]
344
+ ],
345
+ ul: ["data-type"]
346
+ },
347
+ allowedClasses: {
348
+ code: ["language-*"],
349
+ pre: ["language-*"],
350
+ span: ["hljs*"]
317
351
  },
318
352
  allowedStyles: { span: {
319
353
  "background-color": COLOR_REGEXES,
320
354
  "border-radius": [/^[\d.]+(?<unit>px|em|rem|%)$/u],
321
355
  color: COLOR_REGEXES
356
+ } },
357
+ allowedTags: [
358
+ ...baseSanitizeHtml.defaults.allowedTags,
359
+ "input",
360
+ "label"
361
+ ],
362
+ transformTags: { input: (tagName, { checked }) => {
363
+ const attribs = {
364
+ disabled: "",
365
+ type: "checkbox"
366
+ };
367
+ if (checked !== void 0) attribs.checked = checked;
368
+ return {
369
+ attribs,
370
+ tagName
371
+ };
322
372
  } }
323
373
  });
324
374
  //#endregion
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@esposter/shared",
3
- "version": "3.3.0",
3
+ "version": "3.5.0",
4
4
  "description": "A library that contains shared typescript code.",
5
5
  "keywords": [
6
6
  "error-handling",
@@ -56,7 +56,7 @@
56
56
  "devDependencies": {
57
57
  "@arethetypeswrong/core": "^0.18.5",
58
58
  "@azure/data-tables": "^13.3.2",
59
- "@esposter/configuration": "3.3.0",
59
+ "@esposter/configuration": "3.5.0",
60
60
  "@types/node": "^26.6.3",
61
61
  "@types/sanitize-html": "^2.16.1",
62
62
  "publint": "^0.3.24",
@@ -71,5 +71,5 @@
71
71
  "inlinedDependencies": {
72
72
  "type-fest": "5.10.0"
73
73
  },
74
- "gitHead": "5854a00717502d8de96adc8b44d3621ab85f9b57"
74
+ "gitHead": "dd47fa9c4f07dcf7a9ce49a09874a6bcf4e4ace4"
75
75
  }