@@ -120,7 +120,9 @@ def extract_operator_description_update(content: str) -> str:
120120 The updated description to use for the operator.
121121 """
122122 match = re .search (r"## Description\s*(.*?)\s*(?=## |\Z)" , content , re .DOTALL )
123- return match .group (0 ) + os .linesep if match else None
123+ description = match .group (0 ) + os .linesep if match else None
124+ # Handle unicode characters
125+ return description .encode ("unicode-escape" ).decode ()
124126
125127
126128def replace_operator_description (original_documentation : str , new_description : str ):
@@ -293,9 +295,11 @@ def fetch_doc_info(server: dpf.AnyServerType, operator_name: str) -> dict:
293295 "changelog" : changelog_entries , # Include all changelog entries
294296 }
295297
298+ op_description = latex_to_dollars (spec .description )
299+
296300 return {
297301 "operator_name" : op_friendly_name ,
298- "operator_description" : spec . description ,
302+ "operator_description" : op_description ,
299303 "inputs" : input_info ,
300304 "outputs" : output_info ,
301305 "configurations" : configurations_info ,
@@ -304,6 +308,19 @@ def fetch_doc_info(server: dpf.AnyServerType, operator_name: str) -> dict:
304308 }
305309
306310
311+ def latex_to_dollars (text : str ) -> str :
312+ r"""Convert LaTeX math delimiters from \\[.\\] to $$.$$ and from \\(.\\) to $.$ in a given text.
313+
314+ Parameters
315+ ----------
316+ text:
317+ The input text containing LaTeX math delimiters.
318+ """
319+ return (
320+ text .replace (r"\\[" , "$$" ).replace (r"\\]" , "$$" ).replace (r"\\(" , "$" ).replace (r"\\)" , "$" )
321+ )
322+
323+
307324def get_plugin_operators (server : dpf .AnyServerType , plugin_name : str ) -> list [str ]:
308325 """Get the list of operators for a given plugin.
309326
@@ -348,7 +365,7 @@ def generate_operator_doc(
348365 """
349366 operator_info = fetch_doc_info (server , operator_name )
350367 scripting_name = operator_info ["scripting_info" ]["scripting_name" ]
351- category = operator_info ["scripting_info" ]["category" ]
368+ category : str = operator_info ["scripting_info" ]["category" ]
352369 if scripting_name :
353370 file_name = scripting_name
354371 else :
@@ -391,7 +408,10 @@ def update_toc_tree(docs_path: Path):
391408 operators = [] # Reset operators for each category
392409 for file in folder .iterdir ():
393410 if (
394- file .is_file () and file .suffix == ".md" and not file .name .endswith ("_upd.md" )
411+ file .is_file ()
412+ and file .suffix == ".md"
413+ and not file .name .endswith ("_upd.md" )
414+ and not file .name .endswith ("_category.md" )
395415 ): # Ensure 'file' is a file with .md extension
396416 file_name = file .name
397417 file_path = f"{ category } /{ file_name } "
@@ -419,6 +439,60 @@ def update_toc_tree(docs_path: Path):
419439 file .write (new_toc )
420440
421441
442+ def update_categories (docs_path : Path ):
443+ """Update the category index files for the operator specifications.
444+
445+ Parameters
446+ ----------
447+ docs_path:
448+ Path to the root of the DPF documentation sources.
449+
450+ """
451+ specs_path = docs_path / Path ("operator-specifications" )
452+ for folder in specs_path .iterdir ():
453+ if folder .is_dir (): # Ensure 'folder' is a directory
454+ category = folder .name
455+ operators = [] # Reset operators for each category
456+ for file in folder .iterdir ():
457+ if (
458+ file .is_file ()
459+ and file .suffix == ".md"
460+ and not file .name .endswith ("_upd.md" )
461+ and not file .name .endswith ("_category.md" )
462+ ): # Ensure 'file' is a file with .md extension
463+ file_name = file .name
464+ operator_name = file_name .replace ("_" , " " ).replace (".md" , "" )
465+ operators .append ({"operator_name" : operator_name , "file_path" : file_name })
466+ # Update category index file
467+ category_file_path = folder / f"{ category } _category.md"
468+ with category_file_path .open (mode = "w" ) as cat_file :
469+ cat_file .write (f"# { category .capitalize ()} operators\n \n " )
470+ for operator in operators :
471+ cat_file .write (f"- [{ operator ['operator_name' ]} ]({ operator ['file_path' ]} )\n " )
472+
473+
474+ def update_operator_index (docs_path : Path ):
475+ """Update the main index file for all operator specifications.
476+
477+ Parameters
478+ ----------
479+ docs_path:
480+ Path to the root of the DPF documentation sources.
481+
482+ """
483+ specs_path = docs_path / Path ("operator-specifications" )
484+ index_file_path = specs_path / "operator-specifications.md"
485+ with index_file_path .open (mode = "w" ) as index_file :
486+ index_file .write ("# Operator Specifications\n \n " )
487+ for folder in specs_path .iterdir ():
488+ if folder .is_dir (): # Ensure 'folder' is a directory
489+ category = folder .name
490+ index_file .write (
491+ f"- [{ category .capitalize ()} operators]({ category } /{ category } _category.md)\n \n "
492+ )
493+ index_file .write ("\n " )
494+
495+
422496def generate_operators_doc (
423497 output_path : Path ,
424498 ansys_path : Path = None ,
@@ -461,6 +535,10 @@ def generate_operators_doc(
461535 generate_operator_doc (server , operator_name , include_private , output_path )
462536 # Generate the toc tree
463537 update_toc_tree (output_path )
538+ # Generate the category index files
539+ update_categories (output_path )
540+ # Generate the main index file for all categories
541+ update_operator_index (output_path )
464542 # Use update files in output_path
465543 update_operator_descriptions (output_path )
466544
0 commit comments