@@ -85,7 +85,7 @@ def sanitize_name(name):
85
85
return '__doc_' + name
86
86
87
87
88
- def process_comment (comment ):
88
+ def process_comment (comment , fmt = 'rst' ):
89
89
result = ''
90
90
91
91
# Remove C++ comment syntax
@@ -121,17 +121,22 @@ def process_comment(comment):
121
121
s = re .sub (r'[\\@]em\s+%s' % cpp_group , r'*\1*' , s )
122
122
s = re .sub (r'[\\@]b\s+%s' % cpp_group , r'**\1**' , s )
123
123
s = re .sub (r'[\\@]ingroup\s+%s' % cpp_group , r'' , s )
124
- s = re .sub (r'[\\@]param%s?\s+%s' % (param_group , cpp_group ),
125
- r'\n\n$Parameter ``\2``:\n\n' , s )
124
+ if fmt == 'rst' :
125
+ s = re .sub (r'[\\@]param%s?\s+%s' % (param_group , cpp_group ),
126
+ r'\n\n$:param \2:\n\n' , s )
127
+ else :
128
+ s = re .sub (r'[\\@]param%s?\s+%s' % (param_group , cpp_group ),
129
+ r'\n\n$Parameter ``\2``:\n\n' , s )
126
130
s = re .sub (r'[\\@]tparam%s?\s+%s' % (param_group , cpp_group ),
127
131
r'\n\n$Template parameter ``\2``:\n\n' , s )
128
132
129
133
# Remove class and struct tags
130
134
s = re .sub (r'[\\@](class|struct)\s+.*' , '' , s )
131
135
136
+
132
137
for in_ , out_ in {
133
- 'returns' : 'Returns' ,
134
- 'return' : 'Returns' ,
138
+ 'returns' : ':return' if fmt == 'rst' else ' Returns' ,
139
+ 'return' : ':return' if fmt == 'rst' else ' Returns' ,
135
140
'authors' : 'Authors' ,
136
141
'author' : 'Author' ,
137
142
'copyright' : 'Copyright' ,
@@ -140,15 +145,15 @@ def process_comment(comment):
140
145
'sa' : 'See also' ,
141
146
'see' : 'See also' ,
142
147
'extends' : 'Extends' ,
143
- 'throws' : 'Throws' ,
144
- 'throw' : 'Throws'
148
+ 'throws' : ':raise' if fmt == 'rst' else ' Throws' ,
149
+ 'throw' : ':raise' if fmt == 'rst' else ' Throws'
145
150
}.items ():
146
151
s = re .sub (r'[\\@]%s\s*' % in_ , r'\n\n$%s:\n\n' % out_ , s )
147
152
148
153
s = re .sub (r'[\\@]details\s*' , r'\n\n' , s )
149
154
s = re .sub (r'[\\@]brief\s*' , r'' , s )
150
155
s = re .sub (r'[\\@]short\s*' , r'' , s )
151
- s = re .sub (r'[\\@]ref\s*' , r'' , s )
156
+ # s = re.sub(r'[\\@]ref\s*', r'', s)
152
157
153
158
s = re .sub (r'[\\@]code\s?(.*?)\s?[\\@]endcode' ,
154
159
r"```\n\1\n```\n" , s , flags = re .DOTALL )
@@ -180,13 +185,17 @@ def process_comment(comment):
180
185
wrapper = textwrap .TextWrapper ()
181
186
wrapper .expand_tabs = True
182
187
wrapper .replace_whitespace = True
188
+ # wrapper.replace_whitespace = False
183
189
wrapper .drop_whitespace = True
190
+ # wrapper.drop_whitespace = False
184
191
wrapper .width = docstring_width
185
192
wrapper .initial_indent = wrapper .subsequent_indent = ''
186
193
187
194
result = ''
188
195
in_code_segment = False
189
196
for x in re .split (r'(```)' , s ):
197
+
198
+
190
199
if x == '```' :
191
200
if not in_code_segment :
192
201
result += '```\n '
@@ -197,6 +206,9 @@ def process_comment(comment):
197
206
result += x .strip ()
198
207
else :
199
208
for y in re .split (r'(?: *\n *){2,}' , x ):
209
+ r = re .search (r"^(\d+\.|\-#?|\*|\+)\s+" , y )
210
+ if r :
211
+ wrapper .subsequent_indent = ' ' * r .end ()
200
212
wrapped = wrapper .fill (re .sub (r'\s+' , ' ' , y ).strip ())
201
213
if len (wrapped ) > 0 and wrapped [0 ] == '$' :
202
214
result += wrapped [1 :] + '\n '
0 commit comments