77# For the full list of built-in configuration values, see the documentation: https://www.sphinx-doc.org/en/master/usage/configuration.html
88
99import os
10+ import re
1011import subprocess
12+ from docutils import nodes
1113
12- # Functions
1314def get_version ():
1415 props_path = os .path .join (os .path .dirname (__file__ ), '..' , 'zip-content' , 'module.prop' )
1516
@@ -36,6 +37,24 @@ def get_revision():
3637 except Exception :
3738 return None
3839
40+ def transform_doc_links (app , docname , source ):
41+ """Phase 1: Convert local .rst links (no anchor) to :doc: roles."""
42+ source [0 ] = re .sub (r'`([^`<]+)\s*<((?!http|mailto)[^>]+)\.rst>`_' , r':doc:`\1 <\2>`' , source [0 ])
43+
44+ def fix_anchors_in_tree (app , doctree , docname ):
45+ """Phase 2: Fix local .rst#anchor links in the resolved tree."""
46+ ext = '.pdf' if app .builder .name == 'latex' else '.html'
47+ for node in doctree .traverse (nodes .reference ):
48+ uri = node .get ('refuri' )
49+ if uri and '.rst#' in uri and not uri .startswith (('http' , 'mailto' )):
50+ node ['refuri' ] = uri .replace ('.rst#' , f'{ ext } #' )
51+
52+ def setup (app ):
53+ # Process text before parsing
54+ app .connect ('source-read' , transform_doc_links )
55+ # Process nodes after tree is built
56+ app .connect ('doctree-resolved' , fix_anchors_in_tree )
57+
3958# Project information
4059project = 'Google sync add-on'
4160author = 'ale5000'
0 commit comments