@@ -526,6 +526,7 @@ interface DiagramOptions {
526526 refinementLayout ?: DiagramLayout ;
527527 decisionLayout ?: DiagramLayout ;
528528 dependencyLayout ?: DiagramLayout ;
529+ clickTargets ?: Record < string , string > ;
529530}
530531
531532function generateDiagramsFile (
@@ -555,6 +556,7 @@ function generateDiagramsFile(
555556 labelMode : opts ?. labelMode ?? "friendly" ,
556557 cluster : true ,
557558 connectedOnly : false ,
559+ clickTargets : opts ?. clickTargets ,
558560 } ) ,
559561 ) ;
560562 lines . push ( "```" ) ;
@@ -565,6 +567,7 @@ function generateDiagramsFile(
565567 format : "mermaid" ,
566568 layout : opts ?. refinementLayout ?? "TD" ,
567569 labelMode : opts ?. labelMode ?? "friendly" ,
570+ clickTargets : opts ?. clickTargets ,
568571 } ) ;
569572 if ( refinement . includes ( "-->" ) ) {
570573 lines . push ( "## Refinement Chain" ) ;
@@ -580,6 +583,7 @@ function generateDiagramsFile(
580583 format : "mermaid" ,
581584 layout : opts ?. decisionLayout ?? "TD" ,
582585 labelMode : opts ?. labelMode ?? "friendly" ,
586+ clickTargets : opts ?. clickTargets ,
583587 } ) ;
584588 if ( decisions . includes ( "-->" ) ) {
585589 lines . push ( "## Decision Map" ) ;
@@ -595,6 +599,7 @@ function generateDiagramsFile(
595599 format : "mermaid" ,
596600 layout : opts ?. dependencyLayout ?? "LR" ,
597601 labelMode : opts ?. labelMode ?? "friendly" ,
602+ clickTargets : opts ?. clickTargets ,
598603 } ) ;
599604 if ( dependencies . includes ( "-->" ) || dependencies . includes ( "-.->" ) ) {
600605 lines . push ( "## Dependency Graph" ) ;
@@ -612,10 +617,29 @@ function generateDiagramsFile(
612617// Public API
613618// ---------------------------------------------------------------------------
614619
620+ /** Build a click target map from node anchors for use in embedded diagrams. */
621+ function buildAnchorClickMap (
622+ nodes : Node [ ] ,
623+ nodeMap : NodeLocationMap ,
624+ currentFile : string ,
625+ ) : Record < string , string > {
626+ const targets : Record < string , string > = { } ;
627+ for ( const node of nodes ) {
628+ const loc = nodeMap . get ( node . id ) ;
629+ if ( ! loc ) continue ;
630+ targets [ node . id ] =
631+ loc . file === "" || loc . file === currentFile
632+ ? `#${ loc . anchor } `
633+ : `./${ loc . file } #${ loc . anchor } ` ;
634+ }
635+ return targets ;
636+ }
637+
615638/** Options for controlling JSON-to-Markdown conversion. */
616639export interface ConvertOptions {
617640 form : "single-file" | "multi-doc" ;
618641 embedDiagrams ?: boolean ;
642+ diagramLinks ?: boolean ;
619643 labelMode ?: "friendly" | "compact" ;
620644 relationshipLayout ?: DiagramLayout ;
621645 refinementLayout ?: DiagramLayout ;
@@ -625,6 +649,7 @@ export interface ConvertOptions {
625649
626650interface MarkdownRenderOptions {
627651 embedDiagrams ?: boolean ;
652+ diagramLinks ?: boolean ;
628653 labelMode ?: "friendly" | "compact" ;
629654 relationshipLayout ?: DiagramLayout ;
630655 refinementLayout ?: DiagramLayout ;
@@ -690,6 +715,9 @@ export function jsonToMarkdownSingle(
690715 doc . relationships &&
691716 doc . relationships . length > 0
692717 ) {
718+ const clickTargets = options ?. diagramLinks
719+ ? buildAnchorClickMap ( doc . nodes , nodeMap , "" )
720+ : undefined ;
693721 lines . push ( "## Diagrams" ) ;
694722 lines . push ( "" ) ;
695723 lines . push ( "### Relationship Graph" ) ;
@@ -703,6 +731,7 @@ export function jsonToMarkdownSingle(
703731 labelMode : options ?. labelMode ?? "friendly" ,
704732 cluster : true ,
705733 connectedOnly : false ,
734+ clickTargets,
706735 } ) ,
707736 ) ;
708737 lines . push ( "```" ) ;
@@ -782,6 +811,9 @@ export function jsonToMarkdownMultiDoc(
782811 doc . relationships &&
783812 doc . relationships . length > 0
784813 ) {
814+ const clickTargets = options ?. diagramLinks
815+ ? buildAnchorClickMap ( doc . nodes , nodeMap , "DIAGRAMS.md" )
816+ : undefined ;
785817 writeFileSync (
786818 join ( outDir , "DIAGRAMS.md" ) ,
787819 generateDiagramsFile ( doc , {
@@ -790,6 +822,7 @@ export function jsonToMarkdownMultiDoc(
790822 refinementLayout : options ?. refinementLayout ,
791823 decisionLayout : options ?. decisionLayout ,
792824 dependencyLayout : options ?. dependencyLayout ,
825+ clickTargets,
793826 } ) ,
794827 ) ;
795828 }
@@ -870,6 +903,7 @@ export function jsonToMarkdown(
870903 output ,
871904 jsonToMarkdownSingle ( doc , {
872905 embedDiagrams : options . embedDiagrams ,
906+ diagramLinks : options . diagramLinks ,
873907 labelMode : options . labelMode ,
874908 relationshipLayout : options . relationshipLayout ,
875909 refinementLayout : options . refinementLayout ,
@@ -880,6 +914,7 @@ export function jsonToMarkdown(
880914 } else {
881915 jsonToMarkdownMultiDoc ( doc , output , {
882916 embedDiagrams : options . embedDiagrams ,
917+ diagramLinks : options . diagramLinks ,
883918 labelMode : options . labelMode ,
884919 relationshipLayout : options . relationshipLayout ,
885920 refinementLayout : options . refinementLayout ,
0 commit comments