77import signal
88from datetime import date
99from pathlib import Path
10- import markdown
1110
1211import scripts .utils as utils
1312
@@ -67,48 +66,52 @@ def parse_functions(self):
6766 try :
6867 function = utils .load_and_validate_yaml (file_path , self .schema_function )
6968 if function :
70- self .remove_function_repeated_defs (function )
69+ function = self .remove_function_repeated_defs (function )
7170
7271 function ['real_path' ] = file_path
7372 # Get name of parent folder
7473 function ["folder" ] = os .path .basename (os .path .dirname (file_path ))
74+
75+ function_name = self .get_function_name (function )
76+ function ["name" ] = function_name
77+ function_type_name = self .get_function_type_name (function )
78+ function ["type_name" ] = function_type_name
79+
80+ function = self .parse_function_examples (function )
81+ function = self .parse_function_preview_images (function )
7582
83+ example_number = 1
7684 for type_name in ['shared' , 'client' , 'server' ]:
7785 type_info = function .get (type_name , {})
7886 if not type_info :
7987 continue
88+
89+ if 'description' in type_info :
90+ type_info ['description_html' ] = utils .to_html (type_info ['description' ])
91+
8092 if 'examples' in type_info :
81- function ["has_example" ] = True
8293 for example in type_info ['examples' ]:
94+ example ["number" ] = example_number
95+ example_number += 1
8396 if 'description' in example :
84- example ['description_html' ] = markdown . markdown (example ['description' ])
97+ example ['description_html' ] = utils . to_html (example ['description' ])
8598
8699 if 'issues' in type_info :
87100 function ["has_issue" ] = True
88101 for issue in type_info ['issues' ]:
89- issue ['description_html' ] = markdown .markdown (issue ['description' ])
90-
91- if 'description' in type_info :
92- type_info ['description_html' ] = markdown .markdown (type_info ['description' ])
102+ issue ['description_html' ] = utils .to_html (issue ['description' ], single_paragraph = True )
93103
94104 if ('returns' in type_info ) and ('description' in type_info ['returns' ]):
95- type_info ['returns' ]['description_html' ] = markdown . markdown (type_info ['returns' ]['description' ])
105+ type_info ['returns' ]['description_html' ] = utils . to_html (type_info ['returns' ]['description' ], single_paragraph = True )
96106
97107 if 'parameters' in type_info :
98108 for parameter in type_info ['parameters' ]:
99- parameter ['description_html' ] = markdown .markdown (parameter ['description' ])
100-
101- function_name = self .get_function_name (function )
102- function ["name" ] = function_name
103- function_type_name = self .get_function_type_name (function )
104- function ["type_name" ] = function_type_name
105-
106- self .parse_function_examples (function )
107- self .parse_function_preview_images (function )
109+ parameter ['description_html' ] = utils .to_html (parameter ['description' ], single_paragraph = True )
108110
109111 self .functions .append (function )
110112 except Exception as e :
111- raise WikiBuilderError (f'Error loading function { file_path } : { e } ' )
113+ self .logger .exception (e )
114+ raise WikiBuilderError (f'Error loading function { file_path } ' )
112115
113116 def get_function_type (self , function ):
114117 return function .get ('shared' ) or function .get ('client' ) or function .get ('server' )
@@ -122,16 +125,16 @@ def get_function_name(self, function):
122125 def remove_function_repeated_defs (self , function ):
123126 # If a function is shared, remove client/server definitions that are the same as the shared one
124127 shared = function .get ('shared' )
125- if not shared :
126- return
127-
128- for type_name in [ 'client' , 'server' ] :
129- type_info = function . get ( type_name )
130- if not type_info :
131- continue
132- for key in shared . keys ():
133- if key in type_info and shared [ key ] == type_info [ key ]:
134- del type_info [ key ]
128+ if shared :
129+ for type_name in [ 'client' , 'server' ]:
130+ type_info = function . get ( type_name )
131+ if not type_info :
132+ continue
133+ for key in shared . keys () :
134+ if key in type_info and shared [ key ] == type_info [ key ]:
135+ del type_info [ key ]
136+
137+ return function
135138
136139 def resolve_relative_or_repo_absolute_path (self , folder , path ):
137140 if path .startswith ('/' ):
@@ -144,8 +147,12 @@ def parse_function_examples(self, function):
144147 type_info = function .get (type_name , {})
145148 if not type_info :
146149 continue
147- examples [type_name ] = []
148- for example in type_info .get ('examples' , []):
150+ type_examples = type_info .get ('examples' )
151+ if not type_examples :
152+ continue
153+ function ["has_example" ] = True
154+ examples = []
155+ for example in type_examples :
149156 example_path = example .get ('path' )
150157 real_path = self .resolve_relative_or_repo_absolute_path (os .path .dirname (function .get ('real_path' )), example_path )
151158 if not os .path .exists (real_path ):
@@ -154,12 +161,14 @@ def parse_function_examples(self, function):
154161 with open (real_path , 'r' ) as file :
155162 example_code = file .read ()
156163
157- examples [ type_name ] .append ({
164+ examples .append ({
158165 'path' : example_path ,
159- 'description' : example .get ('description' ),
166+ 'description' : example .get ('description' , '' ),
160167 'code' : example_code
161168 })
162- type_info ['examples' ] = examples [type_name ]
169+ type_info ['examples' ] = examples
170+
171+ return function
163172
164173 def parse_function_preview_images (self , function ):
165174 preview_images = {}
@@ -195,6 +204,8 @@ def parse_function_preview_images(self, function):
195204 })
196205 type_info ['preview_images' ] = preview_images [type_name ]
197206
207+ return function
208+
198209 def render_page (self , title , content ):
199210 return self .layout_template .render (
200211 wiki_version = self .wiki_version ,
@@ -243,7 +254,7 @@ def create_article(self, article_name, articles_folder='', custom_web_path=False
243254 article ['content' ] = content_file .read ()
244255
245256 article_template = self .input_env .get_template ('article.html' )
246- article ["content_html" ] = markdown . markdown (article ['content' ])
257+ article ["content_html" ] = utils . to_html (article ['content' ])
247258 html_content = self .render_page (
248259 article ['title' ],
249260 article_template .render (article = article )
0 commit comments