@@ -189,6 +189,62 @@ def strip_directives_from_html(html_content):
189189 return cleaned
190190
191191
192+ def extract_seealso_from_html (html_content ):
193+ """
194+ Extract %seealso values from HTML content before stripping.
195+
196+ Returns a list of referenced item names, or empty list if none found.
197+ """
198+ # Match %seealso in <p> tags (most common after markdown rendering)
199+ p_pattern = re .compile (
200+ r"<p>\s*%seealso\s+([^<]+)</p>" ,
201+ re .IGNORECASE ,
202+ )
203+
204+ # Match standalone %seealso lines
205+ standalone_pattern = re .compile (
206+ r"^\s*%seealso\s+(.+?)\s*$" ,
207+ re .MULTILINE | re .IGNORECASE ,
208+ )
209+
210+ # Try <p> pattern first
211+ match = p_pattern .search (html_content )
212+ if not match :
213+ match = standalone_pattern .search (html_content )
214+
215+ if match :
216+ # Parse comma-separated list
217+ items_str = match .group (1 ).strip ()
218+ items = [item .strip () for item in items_str .split ("," )]
219+ return [item for item in items if item ]
220+
221+ return []
222+
223+
224+ def generate_seealso_html (seealso_items ):
225+ """
226+ Generate HTML for a "See Also" section with links to other reference pages.
227+ """
228+ if not seealso_items :
229+ return ""
230+
231+ links = []
232+ for item in seealso_items :
233+ # Generate link to the reference page
234+ # Item could be "Graph.add_edge" or just "add_edge"
235+ html_filename = f"{ item } .html"
236+ links .append (f'<a href="{ html_filename } ">{ item } </a>' )
237+
238+ links_html = ", " .join (links )
239+
240+ return f"""
241+ <div class="see-also" style="margin-top: 1.5rem; padding-top: 1rem; border-top: 1px solid #dee2e6;">
242+ <h3 style="font-size: 0.9rem; font-weight: 600; color: #6c757d; margin-bottom: 0.5rem;">See Also</h3>
243+ <p style="margin: 0;">{ links_html } </p>
244+ </div>
245+ """
246+
247+
192248# Process all HTML files in the `_site/reference/` directory (except `index.html`)
193249# and apply the specified transformations
194250html_files = [f for f in glob .glob ("_site/reference/*.html" ) if not f .endswith ("index.html" )]
@@ -204,7 +260,10 @@ def strip_directives_from_html(html_content):
204260 with open (html_file , "r" ) as file :
205261 content = file .read ()
206262
207- # Strip @directive: lines from rendered HTML (safety net for docstring directives)
263+ # Extract %seealso before stripping directives
264+ seealso_items = extract_seealso_from_html (content )
265+
266+ # Strip %directive lines from rendered HTML (safety net for docstring directives)
208267 content = strip_directives_from_html (content )
209268
210269 # Format signatures with multiple arguments onto separate lines
@@ -420,8 +479,14 @@ def strip_directives_from_html(html_content):
420479 # Turn all h2 tags into h3 tags
421480 content = [line .replace ("<h2" , "<h3" ).replace ("</h2>" , "</h3>" ) for line in content ]
422481
423- # Place a horizontal rule at the end of each reference page
482+ # Inject "See Also" section if %seealso was found
424483 content_str = "" .join (content )
484+ if seealso_items :
485+ seealso_html = generate_seealso_html (seealso_items )
486+ # Insert before </main>
487+ content_str = content_str .replace ("</main>" , f"{ seealso_html } </main>" )
488+
489+ # Place a horizontal rule at the end of each reference page
425490 main_end_pattern = r"</main>"
426491 main_end_replacement = '</main>\n <hr style="padding: 0; margin: 0;">\n '
427492 content_str = re .sub (main_end_pattern , main_end_replacement , content_str )
0 commit comments