1- import React , { useMemo } from 'react' ;
1+ import React from 'react' ;
22import MDXComponents from '@theme-original/MDXComponents' ;
3+ import MemoryGraphHeader from '@site/src/components/MemoryGraphHeader' ;
34import styles from './styles.module.css' ;
45
5- const MEMORY_GRAPH_BASE_URL = 'https://memory-graph.com/' ;
6-
76/**
8- * Wraps a ```lang debug code block with a header bar linking out to
9- * Bas Terwijn's Memory Graph web debugger (memory-graph.com), so students
10- * can step through the exact snippet from the lesson and watch variables/
11- * references change line by line.
12- *
13- * Unlike InteractivePython, this doesn't replace the block with an editor —
14- * the theme's normal <pre> still renders (syntax highlighting, copy button,
15- * line numbers all keep working). We just read the raw code to build a
16- * deep link and drop a button above it.
7+ * Wraps a ```lang debug (debug-only) code block: a flush MemoryGraphHeader
8+ * sitting directly on top of the theme's normal <pre>, so syntax
9+ * highlighting and the built-in copy button keep working.
1710 *
18- * Memory Graph reads code from a URL *fragment* (`#code=...`), not a query
19- * string — that's deliberate on their end, it means the code never gets
20- * sent to their server, it's only ever interpreted client-side once the
21- * page loads. Don't "fix" this to `?code=`.
11+ * For ```lang interactive debug (both keywords), MDXComponents renders
12+ * MemoryGraphHeader directly above InteractivePython instead, skipping
13+ * this component entirely — see src/theme/MDXComponents.js.
2214 */
2315export default function MemoryGraphBlock ( props ) {
24- const { children } = props ;
25- const rawCode = children ?. props ?. children ?. trim ( ) || '' ;
26-
27- const memoryGraphUrl = useMemo (
28- ( ) => `${ MEMORY_GRAPH_BASE_URL } #code=${ encodeURIComponent ( rawCode ) } ` ,
29- [ rawCode ]
30- ) ;
16+ const rawCode = props . children ?. props ?. children || '' ;
3117
3218 return (
3319 < div className = { styles . wrapper } >
34- < div className = { styles . header } >
35- < span className = { styles . headerText } > Debug Mode</ span >
36- < a
37- href = { memoryGraphUrl }
38- target = "_blank"
39- rel = "noopener noreferrer"
40- className = { styles . openButton }
41- >
42- Open in Memory Graph ↗
43- </ a >
44- </ div >
20+ < MemoryGraphHeader code = { rawCode } flush />
4521 < MDXComponents . pre { ...props } />
4622 </ div >
4723 ) ;
48- }
24+ }
0 commit comments