Skip to content

Commit 041c014

Browse files
authored
feat(Docs) Code block updates (#15160)
1 parent 27082d0 commit 041c014

File tree

7 files changed

+142
-18
lines changed

7 files changed

+142
-18
lines changed

docs/platforms/javascript/guides/react/index.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ Sentry.init({
8989
// Enable logs to be sent to Sentry
9090
enableLogs: true,
9191
// ___PRODUCT_OPTION_END___ logs
92-
9392
// ___PRODUCT_OPTION_START___ performance
93+
9494
// Set tracesSampleRate to 1.0 to capture 100%
9595
// of transactions for tracing.
9696
// Learn more at

src/components/codeBlock/code-blocks.module.scss

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,9 @@
88
border-radius: 0 0 6px 6px;
99
margin-top: 0;
1010
margin-bottom: 0;
11-
/* Wrap overly long lines so blocks never expand layout */
12-
white-space: pre-wrap;
13-
word-break: break-word;
14-
overflow-wrap: anywhere;
11+
/* Use horizontal scroll instead of wrapping */
12+
white-space: pre;
13+
overflow-x: auto;
1514
max-width: 100%;
1615
tab-size: 2;
1716
}
@@ -26,10 +25,9 @@
2625
border: 1px solid var(--accent-11);
2726
border-radius: 6px;
2827
margin: 0;
29-
/* Ensure syntax-highlighted pre behaves like above */
30-
white-space: pre-wrap;
31-
word-break: break-word;
32-
overflow-wrap: anywhere;
28+
/* Use horizontal scroll instead of wrapping */
29+
white-space: pre;
30+
overflow-x: auto;
3331
}
3432

3533
/**
@@ -76,10 +74,8 @@
7674
float: left;
7775
min-width: 100%;
7876
box-sizing: border-box;
79-
/* Allow wrapping inside each highlighted line */
80-
white-space: pre-wrap;
81-
word-break: break-word;
82-
overflow-wrap: anywhere;
77+
/* Use horizontal scroll instead of wrapping */
78+
white-space: pre;
8379
// Set placeholder for highlight accent border color to transparent
8480
border-left: 4px solid rgba(0, 0, 0, 0);
8581

src/components/codeBlock/index.tsx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,17 @@ function getCopiableText(element: HTMLDivElement) {
2525
let text = '';
2626
const walker = document.createTreeWalker(element, NodeFilter.SHOW_TEXT, {
2727
acceptNode: function (node) {
28-
// Skip if parent has .no-copy class
29-
if (node.parentElement?.classList.contains('no-copy')) {
30-
return NodeFilter.FILTER_REJECT;
28+
let parent = node.parentElement;
29+
// Walk up the tree to check if any parent has .no-copy, .hidden, or data-onboarding-option-hidden
30+
while (parent && parent !== element) {
31+
if (
32+
parent.classList.contains('no-copy') ||
33+
parent.classList.contains('hidden') ||
34+
parent.hasAttribute('data-onboarding-option-hidden')
35+
) {
36+
return NodeFilter.FILTER_REJECT;
37+
}
38+
parent = parent.parentElement;
3139
}
3240
return NodeFilter.FILTER_ACCEPT;
3341
},

src/components/codeKeywords/styles.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ export const KeywordSpan = styled(motion.span, {
162162
grid-row: 1;
163163
grid-column: 1;
164164
display: inline-block;
165-
margin-top: ${p => (p.hasPreview ? '24px' : '0')};
165+
margin-top: 0;
166166
`;
167167

168168
export const KeywordSearchInput = styled('input')<{dark: boolean}>`

src/components/docPage/type.scss

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,9 @@
206206
margin-top: 0;
207207
}
208208

209-
[data-onboarding-option].hidden {
209+
[data-onboarding-option].hidden,
210+
[data-integrations-wrapper].hidden,
211+
[data-empty-line-hidden].hidden {
210212
display: none;
211213
}
212214
// force hide markers (___PRODUCT_OPTION_START___ and ___PRODUCT_OPTION_END___)

src/components/onboarding/index.tsx

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,86 @@ export function updateElementsVisibilityForOptions(
229229
});
230230
}
231231
});
232+
233+
// Handle integrations wrapper: hide opening/closing brackets if no integrations are visible
234+
const openWrappers = document.querySelectorAll<HTMLElement>(
235+
'[data-integrations-wrapper="open"]'
236+
);
237+
238+
openWrappers.forEach(openLine => {
239+
const codeBlock = openLine.closest('code.code-highlight');
240+
if (!codeBlock) return;
241+
242+
const allLines = Array.from(codeBlock.children) as HTMLElement[];
243+
const openIndex = allLines.indexOf(openLine);
244+
245+
// Find the matching close line in the same code block
246+
let closeIndex = -1;
247+
for (let i = openIndex + 1; i < allLines.length; i++) {
248+
if (allLines[i].dataset.integrationsWrapper === 'close') {
249+
closeIndex = i;
250+
break;
251+
}
252+
}
253+
254+
if (closeIndex === -1) return;
255+
256+
// Check if any lines between open and close are visible (non-marker lines)
257+
let hasVisibleIntegrations = false;
258+
for (let i = openIndex + 1; i < closeIndex; i++) {
259+
const line = allLines[i];
260+
const isHidden = line.classList.contains('hidden');
261+
const isMarker = line.dataset.onboardingOptionHidden;
262+
263+
// Count any visible non-marker line
264+
if (!isMarker && !isHidden) {
265+
hasVisibleIntegrations = true;
266+
break;
267+
}
268+
}
269+
270+
// Toggle visibility of both open and close lines
271+
openLine.classList.toggle('hidden', !hasVisibleIntegrations);
272+
allLines[closeIndex].classList.toggle('hidden', !hasVisibleIntegrations);
273+
274+
// Hide empty lines adjacent to the wrapper when no integrations are visible
275+
if (!hasVisibleIntegrations) {
276+
// Check line before open wrapper
277+
if (openIndex > 0) {
278+
const prevLine = allLines[openIndex - 1];
279+
if (!prevLine.textContent?.trim()) {
280+
prevLine.classList.add('hidden');
281+
prevLine.dataset.emptyLineHidden = 'true';
282+
}
283+
}
284+
285+
// Check line after close wrapper
286+
if (closeIndex < allLines.length - 1) {
287+
const nextLine = allLines[closeIndex + 1];
288+
if (!nextLine.textContent?.trim()) {
289+
nextLine.classList.add('hidden');
290+
nextLine.dataset.emptyLineHidden = 'true';
291+
}
292+
}
293+
} else {
294+
// Show empty lines when integrations are visible
295+
if (openIndex > 0) {
296+
const prevLine = allLines[openIndex - 1];
297+
if (prevLine.dataset.emptyLineHidden === 'true') {
298+
prevLine.classList.remove('hidden');
299+
delete prevLine.dataset.emptyLineHidden;
300+
}
301+
}
302+
303+
if (closeIndex < allLines.length - 1) {
304+
const nextLine = allLines[closeIndex + 1];
305+
if (nextLine.dataset.emptyLineHidden === 'true') {
306+
nextLine.classList.remove('hidden');
307+
delete nextLine.dataset.emptyLineHidden;
308+
}
309+
}
310+
}
311+
});
232312
}
233313

234314
export function OnboardingOptionButtons({

src/rehype-onboarding-lines.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ function handle_inline_options(node) {
4242
// ___PRODUCT_OPTION_END___ session-replay
4343
const PRODUCT_OPTION_START = '___PRODUCT_OPTION_START___';
4444
const PRODUCT_OPTION_END = '___PRODUCT_OPTION_END___';
45+
46+
// First pass: mark lines with options
4547
node.children?.forEach(line => {
4648
const lineStr = toString(line);
4749
if (lineStr.includes(PRODUCT_OPTION_START)) {
@@ -55,4 +57,40 @@ function handle_inline_options(node) {
5557
line.properties['data-onboarding-option'] = currentOption;
5658
}
5759
});
60+
61+
// Second pass: Mark integrations array opening/closing lines
62+
// These should be hidden if all content inside is from options that are disabled
63+
for (let i = 0; i < (node.children?.length ?? 0); i++) {
64+
const line = node.children[i];
65+
const lineStr = toString(line).trim();
66+
67+
// Found "integrations: ["
68+
if (lineStr.match(/integrations:\s*\[/)) {
69+
// Mark the opening line and hide it by default
70+
line.properties['data-integrations-wrapper'] = 'open';
71+
const openClasses = Array.isArray(line.properties.className)
72+
? line.properties.className
73+
: line.properties.className
74+
? [line.properties.className]
75+
: [];
76+
line.properties.className = [...openClasses, 'hidden'];
77+
78+
// Find the closing "]," - must be exactly ],
79+
for (let j = i + 1; j < node.children.length; j++) {
80+
const closeStr = toString(node.children[j]).trim();
81+
if (closeStr === '],') {
82+
// Mark the closing line and hide it by default
83+
node.children[j].properties['data-integrations-wrapper'] = 'close';
84+
const closeClasses = Array.isArray(node.children[j].properties.className)
85+
? node.children[j].properties.className
86+
: node.children[j].properties.className
87+
? [node.children[j].properties.className]
88+
: [];
89+
node.children[j].properties.className = [...closeClasses, 'hidden'];
90+
break;
91+
}
92+
}
93+
break; // Only handle first integrations array
94+
}
95+
}
5896
}

0 commit comments

Comments
 (0)