@@ -43,55 +43,61 @@ def run(self) -> tuple[list[nodes.Node], list[nodes.system_message]]:
4343 symbol = self .text .strip ()
4444 registry : ExternalCodeRegistry = self .env .external_code_registry
4545 substitutions : dict [str , str ] = self .env .external_code_substitutions
46+ display = symbol
4647 url = registry .resolve_url (self .kind , symbol , substitutions )
4748
49+ if url is None and ('/' in symbol or '#' in symbol ):
50+ repo_path , display = parse_local_ref (symbol )
51+ url = registry .resolve_external_repo_url (repo_path , substitutions )
52+
4853 if url :
4954 ref = nodes .reference (
5055 self .rawtext ,
51- symbol ,
56+ display ,
5257 refuri = url ,
5358 internal = False ,
5459 )
5560 return [ref ], []
5661
5762 if registry .is_registered (self .kind , symbol ):
58- literal = nodes .literal (self .rawtext , symbol )
63+ literal = nodes .literal (self .rawtext , display )
5964 return [literal ], []
6065
61- msg = self .state_machine .reporter .warning (
62- f'external c:{ self .kind } reference target not found: { symbol } ' ,
63- line = self .lineno ,
64- )
65- literal = nodes .literal (self .rawtext , symbol )
66- return [literal ], [msg ]
66+ literal = nodes .literal (self .rawtext , display )
67+ return [literal ], []
6768
6869
6970class ExternalFileRefRole (SphinxRole ):
7071 def run (self ) -> tuple [list [nodes .Node ], list [nodes .system_message ]]:
7172 path = self .text .strip ()
7273 registry : ExternalCodeRegistry = self .env .external_code_registry
7374 substitutions : dict [str , str ] = self .env .external_code_substitutions
75+ repo_root_path = getattr (self .env , 'external_code_workspace_root_path' , None )
76+ display = parse_local_ref (path )[1 ]
7477 url = registry .resolve_file_url (path , substitutions )
7578
79+ if url is None :
80+ url = registry .resolve_external_repo_url (
81+ path ,
82+ substitutions ,
83+ repo_root_path = repo_root_path ,
84+ )
85+
7686 if url :
7787 ref = nodes .reference (
7888 self .rawtext ,
79- path ,
89+ display ,
8090 refuri = url ,
8191 internal = False ,
8292 )
8393 return [ref ], []
8494
8595 if registry .is_file_registered (path ):
86- literal = nodes .literal (self .rawtext , path )
96+ literal = nodes .literal (self .rawtext , display )
8797 return [literal ], []
8898
89- msg = self .state_machine .reporter .warning (
90- f'external file reference target not found: { path } ' ,
91- line = self .lineno ,
92- )
93- literal = nodes .literal (self .rawtext , path )
94- return [literal ], [msg ]
99+ literal = nodes .literal (self .rawtext , display )
100+ return [literal ], []
95101
96102
97103class LocalCodeRefRole (SphinxRole ):
@@ -126,12 +132,8 @@ def _run_local_ref(role: SphinxRole) -> tuple[list[nodes.Node], list[nodes.syste
126132 )
127133 return [ref ], []
128134
129- msg = role .state_machine .reporter .warning (
130- f'local reference could not be resolved: { repo_path } ' ,
131- line = role .lineno ,
132- )
133135 literal = nodes .literal (role .rawtext , display_name or repo_path )
134- return [literal ], [msg ]
136+ return [literal ], []
135137
136138
137139def _rewrite_external_roles (_app : Sphinx , _docname : str , source : list [str ]) -> None :
@@ -165,6 +167,11 @@ def _attach_registry(app: Sphinx, env: BuildEnvironment, _docnames) -> None:
165167 if repo_root_path is None and west_manifest_path is not None :
166168 repo_root_path = str (Path (west_manifest_path ).parent )
167169 repo_root = Path (repo_root_path ) if repo_root_path else None
170+ workspace_root = None
171+ if matter_module_path is not None :
172+ workspace_root = Path (matter_module_path ).parents [2 ]
173+ elif west_manifest_path is not None :
174+ workspace_root = Path (west_manifest_path ).parent .parent
168175 substitutions = load_documentation_substitutions (
169176 shortcuts_path ,
170177 repo_root_path = repo_root ,
@@ -173,6 +180,7 @@ def _attach_registry(app: Sphinx, env: BuildEnvironment, _docnames) -> None:
173180 )
174181 env .external_code_substitutions = substitutions
175182 env .external_code_repo_root_path = repo_root
183+ env .external_code_workspace_root_path = workspace_root
176184 env .external_code_registry = load_external_code_registry (
177185 registry_path ,
178186 substitutions = substitutions ,
0 commit comments