@stackql/provider-utils 0.1.9 → 0.2.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stackql/provider-utils",
3
- "version": "0.1.9",
3
+ "version": "0.2.0",
4
4
  "description": "Utilities for building StackQL providers from OpenAPI specifications.",
5
5
  "type": "module",
6
6
  "main": "./src/index.js",
@@ -23,52 +23,43 @@ export function getIndefiniteArticle(resourceName) {
23
23
  return article;
24
24
  }
25
25
 
26
- // export function sanitizeHtml(text) {
27
- // return text
28
- // // Replace "<" unless it's followed by "a", "/a", "b", "/b", "strong", or "/strong"
29
- // .replace(/<(?!\/?(?:a|b|strong)\b)/gi, '&lt;')
30
- // // Replace ">" unless it's preceded by "</a", "<a ...>", "</b", "<b ...>", "</strong", or "<strong ...>"
31
- // .replace(/(?<!<\/?(?:a|b|strong)[^>]*)>/gi, '&gt;')
32
- // // Add quotes around unquoted href values (within <a ...>)
33
- // .replace(/(<a\b[^>]*?)href=([^"' \t\r\n>]+)/gi, '$1href="$2"')
34
- // // Wrap backticked text with <code>
35
- // .replace(/`([^`]+)`/g, '<code>$1</code>')
36
- // // Replace { and }
37
- // .replace(/{/g, '&#123;')
38
- // .replace(/}/g, '&#125;')
39
- // // Escape backslash
40
- // .replace(/\\/g, '\\\\')
41
- // // Replace " with &quot; UNLESS inside <code>...</code> OR inside an href="...".
42
- // // The alternation matches either a whole <code>...</code> block, an href="...",
43
- // // or a bare " to replace.
44
- // .replace(/(<code>[\s\S]*?<\/code>)|(\bhref="[^"]*")|"/gi, (m, code, href) => {
45
- // if (code) return code; // keep code blocks untouched
46
- // if (href) return href; // keep href="..." quotes untouched
47
- // return '&quot;'; // everything else: replace "
48
- // });
49
- // }
50
-
51
26
  export function sanitizeHtml(text) {
52
27
  return text
53
- // Replace "<" unless it's followed by "a", "/a", "b", "/b", "strong", or "/strong"
54
- .replace(/<(?!\/?(?:a|b|strong|code)\b)/gi, '&lt;')
28
+ // Replace "<" unless it's followed by "a", "/a", "b", "/b", "strong"
29
+ .replace(/<(?!\/?(?:a|b|strong)\b)/gi, '&lt;')
55
30
  // Replace ">" unless it's preceded by "</a", "<a ...>", "</b", "<b ...>", "</strong", or "<strong ...>"
56
- .replace(/(?<!<\/?(?:a|b|strong|code)[^>]*)>/gi, '&gt;')
31
+ .replace(/(?<!<\/?(?:a|b|strong)[^>]*)>/gi, '&gt;')
57
32
  // Add quotes around unquoted href values (within <a ...>)
58
33
  .replace(/(<a\b[^>]*?)href=([^"' \t\r\n>]+)/gi, '$1href="$2"')
59
- // Wrap backticked text with <code>
60
- .replace(/`([^`]+)`/g, '<code>$1</code>')
61
- // Within code tags, escape markdown special characters
62
- .replace(/(<code[^>]*>)([\s\S]*?)(<\/code>)/gi, (match, openTag, content, closeTag) => {
63
- // Escape markdown characters inside code tags
64
- const escapedContent = content
65
- .replace(/\*/g, '&ast;') // Escape asterisks (for italic/bold)
66
- .replace(/_/g, '&lowbar;') // Escape underscores (for italic/bold)
67
- .replace(/\[/g, '&#91;') // Escape brackets (for links)
68
- .replace(/\]/g, '&#93;')
69
- .replace(/\(/g, '&#40;') // Escape parentheses (for links)
70
- .replace(/\)/g, '&#41;');
71
- return openTag + escapedContent + closeTag;
34
+ // Special handling for code tags - remove them if they contain * or _
35
+ .replace(/<code>([\s\S]*?)<\/code>/gi, (match, content) => {
36
+ if (content.includes('*') || content.includes('_')) {
37
+ // If code block has problematic characters, remove the code tags
38
+ // and escape the special characters
39
+ return content
40
+ .replace(/\*/g, '&ast;') // Escape asterisks
41
+ .replace(/_/g, '&lowbar;') // Escape underscores
42
+ .replace(/\[/g, '&#91;') // Escape brackets
43
+ .replace(/\]/g, '&#93;')
44
+ .replace(/\(/g, '&#40;') // Escape parentheses
45
+ .replace(/\)/g, '&#41;');
46
+ }
47
+ // Otherwise keep the code tags
48
+ return match;
49
+ })
50
+ // Wrap backticked text with <code> but only if it doesn't contain * or _
51
+ .replace(/`([^`]+)`/g, (match, content) => {
52
+ if (content.includes('*') || content.includes('_')) {
53
+ // If backticked content has problematic characters, don't add code tags
54
+ return content
55
+ .replace(/\*/g, '&ast;')
56
+ .replace(/_/g, '&lowbar;')
57
+ .replace(/\[/g, '&#91;')
58
+ .replace(/\]/g, '&#93;')
59
+ .replace(/\(/g, '&#40;')
60
+ .replace(/\)/g, '&#41;');
61
+ }
62
+ return `<code>${content}</code>`;
72
63
  })
73
64
  // Replace { and }
74
65
  .replace(/{/g, '&#123;')