@@ -211,35 +211,32 @@ def on_page_markdown(self, markdown: str, page: Page, **kwargs: Any) -> str: #
211211
212212 Returns:
213213 The same Markdown. We only use this hook to keep a reference to the current page URL,
214- used during Markdown conversion by the anchor scanner tree processor .
214+ used during Markdown conversion by the anchor/heading scanner tree processors .
215215 """
216216 # YORE: Bump 2: Remove line.
217217 self ._url_to_page [page .url ] = page
218218 self .current_page = page
219219 return markdown
220220
221221 def on_page_content (self , html : str , page : Page , ** kwargs : Any ) -> str : # noqa: ARG002
222- """Map anchors to URLs .
222+ """Register breadcrumbs .
223223
224224 Hook for the [`on_page_content` event](https://www.mkdocs.org/user-guide/plugins/#on_page_content).
225- In this hook, we map the IDs of every anchor found in the table of contents to the anchors absolute URLs.
226- This mapping will be used later to fix unresolved reference of the form `[title][identifier]` or
227- `[identifier][]`.
225+ In this hook, we register breadcrumbs for each heading on each page.
226+ These breadcrumbs are used to provide contextual information in backlinks.
228227
229228 Arguments:
230229 html: HTML converted from Markdown.
231230 page: The related MkDocs page instance.
232231 kwargs: Additional arguments passed by MkDocs.
233232
234233 Returns:
235- The same HTML. We only use this hook to map anchors to URLs.
234+ The same HTML.
236235 """
237236 self .current_page = page
238- # Collect `std`-domain URLs.
239- if self .scan_toc :
240- _log .debug ("Mapping identifiers to URLs for page %s" , page .file .src_path )
237+ if self .record_backlinks :
241238 for item in page .toc .items :
242- self .map_urls (page , item )
239+ self ._register_breadcrumbs (page , item )
243240 return html
244241
245242 @event_priority (- 50 ) # Late, after mkdocstrings has finished loading inventories.
@@ -299,30 +296,43 @@ def on_env(self, env: Environment, /, *, config: MkDocsConfig, files: Files) ->
299296 # ----------------------------------------------------------------------- #
300297 # Utilities #
301298 # ----------------------------------------------------------------------- #
302- # TODO: Maybe stop exposing this method in the future .
299+ # YORE: Bump 2: Remove block .
303300 def map_urls (self , page : Page , anchor : AnchorLink ) -> None :
304- """Recurse on every anchor to map its ID to its absolute URL.
301+ """Deprecated. Recurse on every anchor to map its ID to its absolute URL.
302+
303+ This method is deprecated and will be removed in a future release.
304+ Please use the `register_anchor` or `register_url` methods instead.
305305
306306 This method populates `self._primary_url_map` by side-effect.
307307
308308 Arguments:
309309 page: The page containing the anchors.
310310 anchor: The anchor to process and to recurse on.
311311 """
312- return self ._map_urls (page , anchor )
312+ warn (
313+ "The `map_urls` method is deprecated and will be removed in a future release. "
314+ "Please use the `register_anchor` or `register_url` methods instead." ,
315+ DeprecationWarning ,
316+ stacklevel = 2 ,
317+ )
318+ self ._map_urls (page , anchor )
313319
314- def _map_urls ( self , page : Page , anchor : AnchorLink , parent : BacklinkCrumb | None = None ) -> None :
315- # YORE: Bump 2: Remove block.
320+ # YORE: Bump 2: Remove block.
321+ def _map_urls ( self , page : Page | str , anchor : AnchorLink ) -> None :
316322 if isinstance (page , str ):
317323 try :
318324 page = self ._url_to_page [page ]
319325 except KeyError :
320326 page = self .current_page # type: ignore[assignment]
321327
322- self .register_anchor (page , anchor .id , title = anchor .title , primary = True )
328+ self .register_anchor (page , anchor .id , title = anchor .title , primary = True ) # type: ignore[arg-type]
329+ self ._register_breadcrumbs (page , anchor ) # type: ignore[arg-type]
330+
331+ def _register_breadcrumbs (self , page : Page , anchor : AnchorLink , parent : BacklinkCrumb | None = None ) -> None :
332+ # Getting a breadcrumb has a side-effect of registering it in the breadcrumbs map.
323333 breadcrumb = self ._get_breadcrumb (page , anchor , parent )
324334 for child in anchor .children :
325- self ._map_urls (page , child , breadcrumb )
335+ self ._register_breadcrumbs (page , child , breadcrumb )
326336
327337 def _get_breadcrumb (
328338 self ,
0 commit comments