diff --git a/src/rehype-onboarding-lines.js b/src/rehype-onboarding-lines.js index b834945cf4594..58c0e27296b83 100644 --- a/src/rehype-onboarding-lines.js +++ b/src/rehype-onboarding-lines.js @@ -58,38 +58,53 @@ function handle_inline_options(node) { } }); + // Helper to add a class to a line's className property + const addClass = (line, className) => { + const existing = line.properties.className; + line.properties.className = [ + ...(Array.isArray(existing) ? existing : existing ? [existing] : []), + className, + ]; + }; + // Second pass: Mark integrations array opening/closing lines - // These should be hidden if all content inside is from options that are disabled + // Hide wrapper only if ALL content inside is conditional (from onboarding options) for (let i = 0; i < (node.children?.length ?? 0); i++) { const line = node.children[i]; const lineStr = toString(line).trim(); // Found "integrations: [" if (lineStr.match(/integrations:\s*\[/)) { - // Mark the opening line and hide it by default line.properties['data-integrations-wrapper'] = 'open'; - const openClasses = Array.isArray(line.properties.className) - ? line.properties.className - : line.properties.className - ? [line.properties.className] - : []; - line.properties.className = [...openClasses, 'hidden']; - // Find the closing "]," - must be exactly ], + // Find the closing "]," + let closeIndex = -1; for (let j = i + 1; j < node.children.length; j++) { - const closeStr = toString(node.children[j]).trim(); - if (closeStr === '],') { - // Mark the closing line and hide it by default + if (toString(node.children[j]).trim() === '],') { + closeIndex = j; node.children[j].properties['data-integrations-wrapper'] = 'close'; - const closeClasses = Array.isArray(node.children[j].properties.className) - ? node.children[j].properties.className - : node.children[j].properties.className - ? [node.children[j].properties.className] - : []; - node.children[j].properties.className = [...closeClasses, 'hidden']; break; } } + + if (closeIndex === -1) break; + + // Check if ALL content is conditional (has onboarding-option attribute or is a marker) + const hasAlwaysVisibleContent = node.children + .slice(i + 1, closeIndex) + .some(contentLine => { + const isMarker = contentLine.properties['data-onboarding-option-hidden']; + const hasOption = contentLine.properties['data-onboarding-option']; + const hasContent = toString(contentLine).trim(); + return hasContent && !isMarker && !hasOption; + }); + + // Only hide wrapper if ALL content is conditional + if (!hasAlwaysVisibleContent) { + addClass(line, 'hidden'); + addClass(node.children[closeIndex], 'hidden'); + } + break; // Only handle first integrations array } }