hububb-saas-shared 1.2.52 → 1.2.53

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.
@@ -1,12 +1,19 @@
1
1
  export declare function isGuideBodyHtml(body: string): boolean;
2
+ /** @deprecated Legacy HTML helper — new guides store markdown. */
2
3
  export declare function escapeGuideHtml(text: string): string;
3
- /** Converts legacy plain-text guide bodies to simple HTML paragraphs. */
4
+ /** @deprecated Legacy HTML helper new guides store markdown. */
4
5
  export declare function plainTextToGuideHtml(body: string): string;
5
- /** Normalizes stored guide body for HTML rendering (guest + mobile display). */
6
+ /** Best-effort conversion for guides saved as HTML before the markdown migration. */
7
+ export declare function htmlToMarkdown(html: string): string;
8
+ /** Returns markdown suitable for editors and react-markdown renderers. */
9
+ export declare function normalizeGuideBodyMarkdown(body: string | null | undefined): string;
10
+ /** @deprecated Use normalizeGuideBodyMarkdown */
6
11
  export declare function normalizeGuideBodyForDisplay(body: string | null | undefined): string;
7
- /** Prepares stored guide body for rich-text editors. */
12
+ /** Prepares stored guide body for markdown editors. */
13
+ export declare function guideBodyToEditorMarkdown(body: string | null | undefined): string;
14
+ /** @deprecated Use guideBodyToEditorMarkdown */
8
15
  export declare function guideBodyToEditorHtml(body: string | null | undefined): string;
9
16
  export declare function stripGuideBodyPreview(body: string | null | undefined): string;
10
17
  export declare function isGuideBodyEmpty(body: string | null | undefined): boolean;
11
- /** Tags allowed when sanitizing guide HTML for display. */
18
+ /** @deprecated HTML sanitization is unused when rendering markdown. */
12
19
  export declare const GUIDE_BODY_ALLOWED_TAGS: readonly ["p", "br", "strong", "b", "em", "i", "ul", "ol", "li", "h2", "h3", "h4", "a", "blockquote"];
@@ -4,15 +4,18 @@ exports.GUIDE_BODY_ALLOWED_TAGS = void 0;
4
4
  exports.isGuideBodyHtml = isGuideBodyHtml;
5
5
  exports.escapeGuideHtml = escapeGuideHtml;
6
6
  exports.plainTextToGuideHtml = plainTextToGuideHtml;
7
+ exports.htmlToMarkdown = htmlToMarkdown;
8
+ exports.normalizeGuideBodyMarkdown = normalizeGuideBodyMarkdown;
7
9
  exports.normalizeGuideBodyForDisplay = normalizeGuideBodyForDisplay;
10
+ exports.guideBodyToEditorMarkdown = guideBodyToEditorMarkdown;
8
11
  exports.guideBodyToEditorHtml = guideBodyToEditorHtml;
9
12
  exports.stripGuideBodyPreview = stripGuideBodyPreview;
10
13
  exports.isGuideBodyEmpty = isGuideBodyEmpty;
11
14
  const HTML_TAG_PATTERN = /<\s*[a-z][^>]*>/i;
12
- const EMPTY_HTML_PATTERNS = [/^<p>\s*<\/p>$/i, /^<p><br\s*\/?><\/p>$/i, /^<p>\s*<br\s*\/?>\s*<\/p>$/i];
13
15
  function isGuideBodyHtml(body) {
14
16
  return HTML_TAG_PATTERN.test(body);
15
17
  }
18
+ /** @deprecated Legacy HTML helper — new guides store markdown. */
16
19
  function escapeGuideHtml(text) {
17
20
  return text
18
21
  .replace(/&/g, '&amp;')
@@ -21,7 +24,7 @@ function escapeGuideHtml(text) {
21
24
  .replace(/"/g, '&quot;')
22
25
  .replace(/'/g, '&#39;');
23
26
  }
24
- /** Converts legacy plain-text guide bodies to simple HTML paragraphs. */
27
+ /** @deprecated Legacy HTML helper new guides store markdown. */
25
28
  function plainTextToGuideHtml(body) {
26
29
  const blocks = body
27
30
  .split(/\n{2,}/)
@@ -33,35 +36,64 @@ function plainTextToGuideHtml(body) {
33
36
  .map((paragraph) => `<p>${escapeGuideHtml(paragraph).replace(/\n/g, '<br />')}</p>`)
34
37
  .join('');
35
38
  }
36
- /** Normalizes stored guide body for HTML rendering (guest + mobile display). */
37
- function normalizeGuideBodyForDisplay(body) {
39
+ /** Best-effort conversion for guides saved as HTML before the markdown migration. */
40
+ function htmlToMarkdown(html) {
41
+ let text = html
42
+ .replace(/\r\n/g, '\n')
43
+ .replace(/<br\s*\/?>/gi, '\n')
44
+ .replace(/<\/(p|div|h[1-6]|li|blockquote)>/gi, '\n')
45
+ .replace(/<(strong|b)[^>]*>([\s\S]*?)<\/\1>/gi, '**$2**')
46
+ .replace(/<(em|i)[^>]*>([\s\S]*?)<\/\1>/gi, '*$2*')
47
+ .replace(/<li[^>]*>/gi, '- ')
48
+ .replace(/<[^>]+>/g, '')
49
+ .replace(/&nbsp;/gi, ' ')
50
+ .replace(/&amp;/gi, '&')
51
+ .replace(/&lt;/gi, '<')
52
+ .replace(/&gt;/gi, '>')
53
+ .replace(/\n{3,}/g, '\n\n');
54
+ return text.trim();
55
+ }
56
+ /** Returns markdown suitable for editors and react-markdown renderers. */
57
+ function normalizeGuideBodyMarkdown(body) {
38
58
  if (!(body === null || body === void 0 ? void 0 : body.trim()))
39
59
  return '';
40
60
  if (isGuideBodyHtml(body))
41
- return body;
42
- return plainTextToGuideHtml(body);
61
+ return htmlToMarkdown(body);
62
+ return body.trim();
63
+ }
64
+ /** @deprecated Use normalizeGuideBodyMarkdown */
65
+ function normalizeGuideBodyForDisplay(body) {
66
+ return normalizeGuideBodyMarkdown(body);
43
67
  }
44
- /** Prepares stored guide body for rich-text editors. */
68
+ /** Prepares stored guide body for markdown editors. */
69
+ function guideBodyToEditorMarkdown(body) {
70
+ return normalizeGuideBodyMarkdown(body);
71
+ }
72
+ /** @deprecated Use guideBodyToEditorMarkdown */
45
73
  function guideBodyToEditorHtml(body) {
46
- return normalizeGuideBodyForDisplay(body);
74
+ return guideBodyToEditorMarkdown(body);
47
75
  }
48
76
  function stripGuideBodyPreview(body) {
49
- if (!(body === null || body === void 0 ? void 0 : body.trim()))
77
+ const markdown = normalizeGuideBodyMarkdown(body);
78
+ if (!markdown)
50
79
  return '';
51
- const source = isGuideBodyHtml(body)
52
- ? body.replace(/<[^>]+>/g, ' ').replace(/&nbsp;/gi, ' ')
53
- : body;
54
- return source.replace(/\s+/g, ' ').trim();
80
+ return markdown
81
+ .replace(/```[\s\S]*?```/g, ' ')
82
+ .replace(/`([^`]+)`/g, '$1')
83
+ .replace(/!\[([^\]]*)\]\([^)]+\)/g, '$1')
84
+ .replace(/\[([^\]]+)\]\([^)]+\)/g, '$1')
85
+ .replace(/^#{1,6}\s+/gm, '')
86
+ .replace(/^>\s+/gm, '')
87
+ .replace(/^[-*+]\s+/gm, '')
88
+ .replace(/^\d+\.\s+/gm, '')
89
+ .replace(/[*_~]/g, '')
90
+ .replace(/\s+/g, ' ')
91
+ .trim();
55
92
  }
56
93
  function isGuideBodyEmpty(body) {
57
- if (!(body === null || body === void 0 ? void 0 : body.trim()))
58
- return true;
59
- const normalized = normalizeGuideBodyForDisplay(body).trim();
60
- if (!normalized)
61
- return true;
62
- return EMPTY_HTML_PATTERNS.some((pattern) => pattern.test(normalized));
94
+ return !normalizeGuideBodyMarkdown(body);
63
95
  }
64
- /** Tags allowed when sanitizing guide HTML for display. */
96
+ /** @deprecated HTML sanitization is unused when rendering markdown. */
65
97
  exports.GUIDE_BODY_ALLOWED_TAGS = [
66
98
  'p',
67
99
  'br',
@@ -1,5 +1,5 @@
1
1
  export { GUIDE_ICON_KEYS, GUIDE_ICON_LABELS, GUIDE_ICON_PHOSPHOR_NAMES, type GuideIconKey } from './icons';
2
- export { GUIDE_BODY_ALLOWED_TAGS, escapeGuideHtml, guideBodyToEditorHtml, isGuideBodyEmpty, isGuideBodyHtml, normalizeGuideBodyForDisplay, plainTextToGuideHtml, stripGuideBodyPreview, } from './body';
2
+ export { GUIDE_BODY_ALLOWED_TAGS, escapeGuideHtml, guideBodyToEditorHtml, guideBodyToEditorMarkdown, htmlToMarkdown, isGuideBodyEmpty, isGuideBodyHtml, normalizeGuideBodyForDisplay, normalizeGuideBodyMarkdown, plainTextToGuideHtml, stripGuideBodyPreview, } from './body';
3
3
  export declare const propertyGuideSchema: import("zod").ZodObject<{
4
4
  id: import("zod").ZodNumber;
5
5
  propertyId: import("zod").ZodNumber;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.propertyGuideSchema = exports.stripGuideBodyPreview = exports.plainTextToGuideHtml = exports.normalizeGuideBodyForDisplay = exports.isGuideBodyHtml = exports.isGuideBodyEmpty = exports.guideBodyToEditorHtml = exports.escapeGuideHtml = exports.GUIDE_BODY_ALLOWED_TAGS = exports.GUIDE_ICON_PHOSPHOR_NAMES = exports.GUIDE_ICON_LABELS = exports.GUIDE_ICON_KEYS = void 0;
3
+ exports.propertyGuideSchema = exports.stripGuideBodyPreview = exports.plainTextToGuideHtml = exports.normalizeGuideBodyMarkdown = exports.normalizeGuideBodyForDisplay = exports.isGuideBodyHtml = exports.isGuideBodyEmpty = exports.htmlToMarkdown = exports.guideBodyToEditorMarkdown = exports.guideBodyToEditorHtml = exports.escapeGuideHtml = exports.GUIDE_BODY_ALLOWED_TAGS = exports.GUIDE_ICON_PHOSPHOR_NAMES = exports.GUIDE_ICON_LABELS = exports.GUIDE_ICON_KEYS = void 0;
4
4
  const zod_1 = require("zod");
5
5
  const icons_1 = require("./icons");
6
6
  var icons_2 = require("./icons");
@@ -11,9 +11,12 @@ var body_1 = require("./body");
11
11
  Object.defineProperty(exports, "GUIDE_BODY_ALLOWED_TAGS", { enumerable: true, get: function () { return body_1.GUIDE_BODY_ALLOWED_TAGS; } });
12
12
  Object.defineProperty(exports, "escapeGuideHtml", { enumerable: true, get: function () { return body_1.escapeGuideHtml; } });
13
13
  Object.defineProperty(exports, "guideBodyToEditorHtml", { enumerable: true, get: function () { return body_1.guideBodyToEditorHtml; } });
14
+ Object.defineProperty(exports, "guideBodyToEditorMarkdown", { enumerable: true, get: function () { return body_1.guideBodyToEditorMarkdown; } });
15
+ Object.defineProperty(exports, "htmlToMarkdown", { enumerable: true, get: function () { return body_1.htmlToMarkdown; } });
14
16
  Object.defineProperty(exports, "isGuideBodyEmpty", { enumerable: true, get: function () { return body_1.isGuideBodyEmpty; } });
15
17
  Object.defineProperty(exports, "isGuideBodyHtml", { enumerable: true, get: function () { return body_1.isGuideBodyHtml; } });
16
18
  Object.defineProperty(exports, "normalizeGuideBodyForDisplay", { enumerable: true, get: function () { return body_1.normalizeGuideBodyForDisplay; } });
19
+ Object.defineProperty(exports, "normalizeGuideBodyMarkdown", { enumerable: true, get: function () { return body_1.normalizeGuideBodyMarkdown; } });
17
20
  Object.defineProperty(exports, "plainTextToGuideHtml", { enumerable: true, get: function () { return body_1.plainTextToGuideHtml; } });
18
21
  Object.defineProperty(exports, "stripGuideBodyPreview", { enumerable: true, get: function () { return body_1.stripGuideBodyPreview; } });
19
22
  exports.propertyGuideSchema = (0, zod_1.object)({
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "type": "commonjs",
3
3
  "name": "hububb-saas-shared",
4
- "version": "1.2.52",
4
+ "version": "1.2.53",
5
5
  "description": "This is a shared package for the hububb saas project",
6
6
  "types": "./dist/index.d.ts",
7
7
  "main": "./dist/index.js",