@redpanda-data/docs-extensions-and-macros 4.12.1 → 4.12.2
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
|
@@ -138,34 +138,52 @@ module.exports = function renderConnectFields(children, prefix = '') {
|
|
|
138
138
|
if (child.examples && child.examples.length) {
|
|
139
139
|
block += `[source,yaml]\n----\n# Examples:\n`;
|
|
140
140
|
if (child.kind === 'array') {
|
|
141
|
-
// Render arrays in flow style (with brackets) instead of block style
|
|
142
141
|
child.examples.forEach(example => {
|
|
143
142
|
if (Array.isArray(example)) {
|
|
144
|
-
//
|
|
145
|
-
const
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
143
|
+
// Check if array contains any objects
|
|
144
|
+
const hasObjects = example.some(item => typeof item === 'object' && item !== null);
|
|
145
|
+
|
|
146
|
+
if (hasObjects) {
|
|
147
|
+
// Use block style for arrays of objects
|
|
148
|
+
block += renderYamlList(child.name, [example]);
|
|
149
|
+
} else {
|
|
150
|
+
// Use flow style for arrays of primitives: fieldName: [item1, item2, ...]
|
|
151
|
+
const items = example.map(item => {
|
|
152
|
+
if (typeof item === 'string') {
|
|
153
|
+
// Check if already quoted (starts and ends with quotes)
|
|
154
|
+
const alreadyQuoted = item.startsWith('"') && item.endsWith('"');
|
|
155
|
+
|
|
156
|
+
if (alreadyQuoted) {
|
|
157
|
+
// Already quoted, return as-is
|
|
158
|
+
return item;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// Check if quoting is needed
|
|
162
|
+
const needsQuoting = item === '' ||
|
|
163
|
+
item === '*' ||
|
|
164
|
+
/^(true|false|null|yes|no|on|off)$/i.test(item) ||
|
|
165
|
+
/^[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?$/.test(item) ||
|
|
166
|
+
/[:\[\]\{\},&>|%@`"]/.test(item) ||
|
|
167
|
+
/\s/.test(item); // any whitespace
|
|
168
|
+
|
|
169
|
+
if (needsQuoting) {
|
|
170
|
+
// Escape backslashes first, then double quotes
|
|
171
|
+
const escaped = item.replace(/\\/g, '\\\\').replace(/"/g, '\\"');
|
|
172
|
+
return `"${escaped}"`;
|
|
173
|
+
}
|
|
174
|
+
return item;
|
|
175
|
+
}
|
|
176
|
+
// For primitives (numbers, booleans, etc.), convert to string
|
|
177
|
+
const strValue = String(item);
|
|
178
|
+
// Check if the stringified value needs quoting
|
|
179
|
+
if (/[:\[\]\{\},&>|%@`"]/.test(strValue) || /\s/.test(strValue)) {
|
|
180
|
+
const escaped = strValue.replace(/\\/g, '\\\\').replace(/"/g, '\\"');
|
|
155
181
|
return `"${escaped}"`;
|
|
156
182
|
}
|
|
157
|
-
return
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
// Check if the stringified value needs quoting
|
|
162
|
-
if (/[:\[\]\{\},&>|%@`"]/.test(strValue) || /^[\s]|[\s]$/.test(strValue)) {
|
|
163
|
-
const escaped = strValue.replace(/\\/g, '\\\\').replace(/"/g, '\\"');
|
|
164
|
-
return `"${escaped}"`;
|
|
165
|
-
}
|
|
166
|
-
return strValue;
|
|
167
|
-
});
|
|
168
|
-
block += `${child.name}: [${items.join(', ')}]\n`;
|
|
183
|
+
return strValue;
|
|
184
|
+
});
|
|
185
|
+
block += `${child.name}: [${items.join(', ')}]\n`;
|
|
186
|
+
}
|
|
169
187
|
} else {
|
|
170
188
|
// Fallback for non-array examples (shouldn't happen for array fields)
|
|
171
189
|
block += `${child.name}: ${example}\n`;
|