@stackql/provider-utils 0.4.3 → 0.4.4

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stackql/provider-utils",
3
- "version": "0.4.3",
3
+ "version": "0.4.4",
4
4
  "description": "Utilities for building StackQL providers from OpenAPI specifications.",
5
5
  "type": "module",
6
6
  "main": "./src/index.js",
@@ -23,18 +23,44 @@ export function getIndefiniteArticle(resourceName) {
23
23
  return article;
24
24
  }
25
25
 
26
+ /**
27
+ * Sanitizes HTML with special handling for allowed tags and backticked content
28
+ * @param {string} text - The text to sanitize
29
+ * @return {string} - The sanitized text
30
+ */
26
31
  export function sanitizeHtml(text) {
27
- return text
32
+ if (!text) return '';
33
+
34
+ // First apply the general sanitization
35
+ let result = text
28
36
  .replace(/{/g, '{')
29
37
  .replace(/}/g, '}')
30
38
  .replace(/>/g, '>')
31
39
  .replace(/</g, '&lt;')
32
40
  // edge case
33
41
  .replace(/&#125;_&#123;/g, '&#125;&#95;&#123;')
34
- .replace(/\n/g, '<br />')
42
+ .replace(/\n/g, '<br />');
43
+
44
+ // Fix 1: Replace &lt;br&gt;, &lt;br/&gt;, &lt;p&gt;, &lt;/p&gt; back to their literal HTML tags
45
+ // Make sure <br> is always self-closing for MDX compatibility
46
+ result = result
47
+ .replace(/&lt;br\s*\/?&gt;/gi, '<br />')
48
+ .replace(/&lt;p&gt;/gi, '<p>')
49
+ .replace(/&lt;\/p&gt;/gi, '</p>');
50
+
51
+ // Fix 2: Find any &lt; or &gt; inside backticks and convert them back to < and >
52
+ // We need to handle the backtick content by finding pairs of backticks
53
+ result = result.replace(/`([^`]*)`/g, (match, content) => {
54
+ // Convert &lt; and &gt; back to < and > only within backticked content
55
+ const fixedContent = content
56
+ .replace(/&lt;/g, '<')
57
+ .replace(/&gt;/g, '>');
58
+ return '`' + fixedContent + '`';
59
+ });
60
+
61
+ return result;
35
62
  }
36
63
 
37
-
38
64
  export function getSqlMethodsWithOrderedFields(resourceData, dereferencedAPI, sqlVerb) {
39
65
  const methods = {};
40
66