@stackql/provider-utils 0.1.7 → 0.1.9
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
package/src/docgen/helpers.js
CHANGED
|
@@ -23,24 +23,59 @@ 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, '<')
|
|
30
|
+
// // Replace ">" unless it's preceded by "</a", "<a ...>", "</b", "<b ...>", "</strong", or "<strong ...>"
|
|
31
|
+
// .replace(/(?<!<\/?(?:a|b|strong)[^>]*)>/gi, '>')
|
|
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, '{')
|
|
38
|
+
// .replace(/}/g, '}')
|
|
39
|
+
// // Escape backslash
|
|
40
|
+
// .replace(/\\/g, '\\\\')
|
|
41
|
+
// // Replace " with " 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 '"'; // everything else: replace "
|
|
48
|
+
// });
|
|
49
|
+
// }
|
|
50
|
+
|
|
26
51
|
export function sanitizeHtml(text) {
|
|
27
52
|
return text
|
|
28
53
|
// Replace "<" unless it's followed by "a", "/a", "b", "/b", "strong", or "/strong"
|
|
29
|
-
.replace(/<(?!\/?(?:a|b|strong)\b)/gi, '<')
|
|
54
|
+
.replace(/<(?!\/?(?:a|b|strong|code)\b)/gi, '<')
|
|
30
55
|
// Replace ">" unless it's preceded by "</a", "<a ...>", "</b", "<b ...>", "</strong", or "<strong ...>"
|
|
31
|
-
.replace(/(?<!<\/?(?:a|b|strong)[^>]*)>/gi, '>')
|
|
56
|
+
.replace(/(?<!<\/?(?:a|b|strong|code)[^>]*)>/gi, '>')
|
|
32
57
|
// Add quotes around unquoted href values (within <a ...>)
|
|
33
58
|
.replace(/(<a\b[^>]*?)href=([^"' \t\r\n>]+)/gi, '$1href="$2"')
|
|
34
59
|
// Wrap backticked text with <code>
|
|
35
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, '*') // Escape asterisks (for italic/bold)
|
|
66
|
+
.replace(/_/g, '_') // Escape underscores (for italic/bold)
|
|
67
|
+
.replace(/\[/g, '[') // Escape brackets (for links)
|
|
68
|
+
.replace(/\]/g, ']')
|
|
69
|
+
.replace(/\(/g, '(') // Escape parentheses (for links)
|
|
70
|
+
.replace(/\)/g, ')');
|
|
71
|
+
return openTag + escapedContent + closeTag;
|
|
72
|
+
})
|
|
36
73
|
// Replace { and }
|
|
37
74
|
.replace(/{/g, '{')
|
|
38
75
|
.replace(/}/g, '}')
|
|
39
76
|
// Escape backslash
|
|
40
77
|
.replace(/\\/g, '\\\\')
|
|
41
78
|
// Replace " with " 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
79
|
.replace(/(<code>[\s\S]*?<\/code>)|(\bhref="[^"]*")|"/gi, (m, code, href) => {
|
|
45
80
|
if (code) return code; // keep code blocks untouched
|
|
46
81
|
if (href) return href; // keep href="..." quotes untouched
|
|
@@ -40,7 +40,7 @@ export function createFieldsSection(resourceData, dereferencedAPI) {
|
|
|
40
40
|
|
|
41
41
|
// Add the method description if available
|
|
42
42
|
if (methodData.respDescription && methodData.respDescription.trim().toUpperCase() !== 'OK') {
|
|
43
|
-
content += `${methodData.respDescription}\n\n`;
|
|
43
|
+
content += `${sanitizeHtml(methodData.respDescription)}\n\n`;
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
// Add the table header
|