7
7
import signal
8
8
from datetime import date
9
9
from pathlib import Path
10
- import markdown
11
10
12
11
import scripts .utils as utils
13
12
@@ -67,48 +66,52 @@ def parse_functions(self):
67
66
try :
68
67
function = utils .load_and_validate_yaml (file_path , self .schema_function )
69
68
if function :
70
- self .remove_function_repeated_defs (function )
69
+ function = self .remove_function_repeated_defs (function )
71
70
72
71
function ['real_path' ] = file_path
73
72
# Get name of parent folder
74
73
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 )
75
82
83
+ example_number = 1
76
84
for type_name in ['shared' , 'client' , 'server' ]:
77
85
type_info = function .get (type_name , {})
78
86
if not type_info :
79
87
continue
88
+
89
+ if 'description' in type_info :
90
+ type_info ['description_html' ] = utils .to_html (type_info ['description' ])
91
+
80
92
if 'examples' in type_info :
81
- function ["has_example" ] = True
82
93
for example in type_info ['examples' ]:
94
+ example ["number" ] = example_number
95
+ example_number += 1
83
96
if 'description' in example :
84
- example ['description_html' ] = markdown . markdown (example ['description' ])
97
+ example ['description_html' ] = utils . to_html (example ['description' ])
85
98
86
99
if 'issues' in type_info :
87
100
function ["has_issue" ] = True
88
101
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 )
93
103
94
104
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 )
96
106
97
107
if 'parameters' in type_info :
98
108
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 )
108
110
109
111
self .functions .append (function )
110
112
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 } ' )
112
115
113
116
def get_function_type (self , function ):
114
117
return function .get ('shared' ) or function .get ('client' ) or function .get ('server' )
@@ -122,16 +125,16 @@ def get_function_name(self, function):
122
125
def remove_function_repeated_defs (self , function ):
123
126
# If a function is shared, remove client/server definitions that are the same as the shared one
124
127
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
135
138
136
139
def resolve_relative_or_repo_absolute_path (self , folder , path ):
137
140
if path .startswith ('/' ):
@@ -144,8 +147,12 @@ def parse_function_examples(self, function):
144
147
type_info = function .get (type_name , {})
145
148
if not type_info :
146
149
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 :
149
156
example_path = example .get ('path' )
150
157
real_path = self .resolve_relative_or_repo_absolute_path (os .path .dirname (function .get ('real_path' )), example_path )
151
158
if not os .path .exists (real_path ):
@@ -154,12 +161,14 @@ def parse_function_examples(self, function):
154
161
with open (real_path , 'r' ) as file :
155
162
example_code = file .read ()
156
163
157
- examples [ type_name ] .append ({
164
+ examples .append ({
158
165
'path' : example_path ,
159
- 'description' : example .get ('description' ),
166
+ 'description' : example .get ('description' , '' ),
160
167
'code' : example_code
161
168
})
162
- type_info ['examples' ] = examples [type_name ]
169
+ type_info ['examples' ] = examples
170
+
171
+ return function
163
172
164
173
def parse_function_preview_images (self , function ):
165
174
preview_images = {}
@@ -195,6 +204,8 @@ def parse_function_preview_images(self, function):
195
204
})
196
205
type_info ['preview_images' ] = preview_images [type_name ]
197
206
207
+ return function
208
+
198
209
def render_page (self , title , content ):
199
210
return self .layout_template .render (
200
211
wiki_version = self .wiki_version ,
@@ -243,7 +254,7 @@ def create_article(self, article_name, articles_folder='', custom_web_path=False
243
254
article ['content' ] = content_file .read ()
244
255
245
256
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' ])
247
258
html_content = self .render_page (
248
259
article ['title' ],
249
260
article_template .render (article = article )
0 commit comments