@stackql/provider-utils 0.4.8 → 0.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.
package/package.json
CHANGED
package/src/docgen/helpers.js
CHANGED
|
@@ -28,21 +28,69 @@ export function getIndefiniteArticle(resourceName) {
|
|
|
28
28
|
* @param {string} text - The text to sanitize
|
|
29
29
|
* @return {string} - The sanitized text
|
|
30
30
|
*/
|
|
31
|
+
// export function sanitizeHtml(text) {
|
|
32
|
+
// if (!text) return '';
|
|
33
|
+
|
|
34
|
+
// // Special handling for code tags - temporarily replace them with placeholders
|
|
35
|
+
// // that won't get escaped in the general sanitization
|
|
36
|
+
// let result = text
|
|
37
|
+
// // Replace <code> tags with a safe placeholder
|
|
38
|
+
// .replace(/<code>/g, '___CODE_OPEN___')
|
|
39
|
+
// .replace(/<\/code>/g, '___CODE_CLOSE___');
|
|
40
|
+
|
|
41
|
+
// // Remove <nobr> tags completely
|
|
42
|
+
// result = result
|
|
43
|
+
// .replace(/<nobr>/g, '')
|
|
44
|
+
// .replace(/<\/nobr>/g, '');
|
|
45
|
+
|
|
46
|
+
// // Then apply the general sanitization
|
|
47
|
+
// result = result
|
|
48
|
+
// .replace(/{/g, '{')
|
|
49
|
+
// .replace(/}/g, '}')
|
|
50
|
+
// .replace(/>/g, '>')
|
|
51
|
+
// .replace(/</g, '<')
|
|
52
|
+
// // edge case
|
|
53
|
+
// .replace(/}_{/g, '}_{')
|
|
54
|
+
// .replace(/\n/g, '<br />');
|
|
55
|
+
|
|
56
|
+
// // Fix 1: Replace <br>, <br/>, <p>, </p> back to their literal HTML tags
|
|
57
|
+
// // Make sure <br> is always self-closing for MDX compatibility
|
|
58
|
+
// result = result
|
|
59
|
+
// .replace(/<br\s*\/?>/gi, '<br />')
|
|
60
|
+
// .replace(/<p>/gi, '<p>')
|
|
61
|
+
// .replace(/<\/p>/gi, '</p>');
|
|
62
|
+
|
|
63
|
+
// // Fix 2: Find any < or > inside backticks and convert them back to < and >
|
|
64
|
+
// // We need to handle the backtick content by finding pairs of backticks
|
|
65
|
+
// result = result.replace(/`([^`]*)`/g, (match, content) => {
|
|
66
|
+
// // Convert < and > back to < and > only within backticked content
|
|
67
|
+
// const fixedContent = content
|
|
68
|
+
// .replace(/</g, '<')
|
|
69
|
+
// .replace(/>/g, '>');
|
|
70
|
+
// return '`' + fixedContent + '`';
|
|
71
|
+
// });
|
|
72
|
+
|
|
73
|
+
// // Finally, restore the code tags
|
|
74
|
+
// result = result
|
|
75
|
+
// .replace(/___CODE_OPEN___/g, '<code>')
|
|
76
|
+
// .replace(/___CODE_CLOSE___/g, '</code>');
|
|
77
|
+
|
|
78
|
+
// return result;
|
|
79
|
+
// }
|
|
31
80
|
export function sanitizeHtml(text) {
|
|
32
81
|
if (!text) return '';
|
|
33
82
|
|
|
34
83
|
// Special handling for code tags - temporarily replace them with placeholders
|
|
35
|
-
// that won't get escaped in the general sanitization
|
|
36
84
|
let result = text
|
|
37
85
|
// Replace <code> tags with a safe placeholder
|
|
38
86
|
.replace(/<code>/g, '___CODE_OPEN___')
|
|
39
87
|
.replace(/<\/code>/g, '___CODE_CLOSE___');
|
|
40
|
-
|
|
41
|
-
|
|
88
|
+
|
|
89
|
+
// Remove <nobr> tags completely
|
|
42
90
|
result = result
|
|
43
91
|
.replace(/<nobr>/g, '')
|
|
44
92
|
.replace(/<\/nobr>/g, '');
|
|
45
|
-
|
|
93
|
+
|
|
46
94
|
// Then apply the general sanitization
|
|
47
95
|
result = result
|
|
48
96
|
.replace(/{/g, '{')
|
|
@@ -51,17 +99,18 @@ export function sanitizeHtml(text) {
|
|
|
51
99
|
.replace(/</g, '<')
|
|
52
100
|
// edge case
|
|
53
101
|
.replace(/}_{/g, '}_{')
|
|
102
|
+
// Handle all types of line breaks - very important!
|
|
103
|
+
.replace(/\r\n/g, '<br />')
|
|
104
|
+
.replace(/\r/g, '<br />')
|
|
54
105
|
.replace(/\n/g, '<br />');
|
|
55
106
|
|
|
56
107
|
// Fix 1: Replace <br>, <br/>, <p>, </p> back to their literal HTML tags
|
|
57
|
-
// Make sure <br> is always self-closing for MDX compatibility
|
|
58
108
|
result = result
|
|
59
109
|
.replace(/<br\s*\/?>/gi, '<br />')
|
|
60
110
|
.replace(/<p>/gi, '<p>')
|
|
61
111
|
.replace(/<\/p>/gi, '</p>');
|
|
62
112
|
|
|
63
|
-
// Fix 2:
|
|
64
|
-
// We need to handle the backtick content by finding pairs of backticks
|
|
113
|
+
// Fix 2: Handle backticked content more carefully
|
|
65
114
|
result = result.replace(/`([^`]*)`/g, (match, content) => {
|
|
66
115
|
// Convert < and > back to < and > only within backticked content
|
|
67
116
|
const fixedContent = content
|
|
@@ -70,11 +119,16 @@ export function sanitizeHtml(text) {
|
|
|
70
119
|
return '`' + fixedContent + '`';
|
|
71
120
|
});
|
|
72
121
|
|
|
122
|
+
// IMPORTANT: Explicitly sanitize any <location> tags that might be in the text
|
|
123
|
+
// This ensures they get properly escaped even if added later
|
|
124
|
+
result = result.replace(/<location>/g, '<location>')
|
|
125
|
+
.replace(/<\/location>/g, '</location>');
|
|
126
|
+
|
|
73
127
|
// Finally, restore the code tags
|
|
74
128
|
result = result
|
|
75
129
|
.replace(/___CODE_OPEN___/g, '<code>')
|
|
76
130
|
.replace(/___CODE_CLOSE___/g, '</code>');
|
|
77
|
-
|
|
131
|
+
|
|
78
132
|
return result;
|
|
79
133
|
}
|
|
80
134
|
|
|
@@ -161,9 +161,17 @@ export function createInsertExamples(providerName, serviceName, resourceName, re
|
|
|
161
161
|
content += ' value: ' + type + '\n';
|
|
162
162
|
|
|
163
163
|
if (description) {
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
164
|
+
content += ' description: |\n';
|
|
165
|
+
|
|
166
|
+
// Split by lines and remove empty lines
|
|
167
|
+
const lines = description
|
|
168
|
+
.split(/\n/)
|
|
169
|
+
.filter(line => line.trim() !== ''); // Remove completely empty lines
|
|
170
|
+
|
|
171
|
+
// Process each line with proper indentation
|
|
172
|
+
lines.forEach(line => {
|
|
173
|
+
content += ' ' + line.trim() + '\n'; // trim each line to remove extra spaces
|
|
174
|
+
});
|
|
167
175
|
}
|
|
168
176
|
|
|
169
177
|
// Add enum values if available
|