@@ -76,7 +76,7 @@ def convert_rst_link_to_md(rst):
76
76
return re .sub (expr , r"[](\1)" , rst , flags = re .MULTILINE )
77
77
78
78
79
- # to_md -----------------------------------------------------------------------
79
+ # render -----------------------------------------------------------------------
80
80
# griffe function dataclass structure:
81
81
# Object:
82
82
# kind: Kind {"module", "class", "function", "attribute"}
@@ -155,7 +155,7 @@ class MdRenderer(Renderer):
155
155
>>> from quartodoc import MdRenderer, get_object
156
156
>>> renderer = MdRenderer(header_level=2)
157
157
>>> f = get_object("quartodoc", "get_object")
158
- >>> print(renderer.to_md (f)[:81])
158
+ >>> print(renderer.render (f)[:81])
159
159
## get_object
160
160
`get_object(module: str, object_name: str, parser: str = 'numpy')`
161
161
@@ -201,25 +201,25 @@ def _fetch_object_dispname(self, el: "dc.Alias | dc.Object"):
201
201
raise ValueError (f"Unsupported display_name: `{ self .display_name } `" )
202
202
203
203
@dispatch
204
- def to_md (self , el ):
204
+ def render (self , el ):
205
205
raise NotImplementedError (f"Unsupported type: { type (el )} " )
206
206
207
207
@dispatch
208
- def to_md (self , el : str ):
208
+ def render (self , el : str ):
209
209
return el
210
210
211
211
# TODO: remove, as this is now handled by _render_annotation
212
212
# @dispatch
213
- # def to_md (self, el: Union[Expression, Name]):
213
+ # def render (self, el: Union[Expression, Name]):
214
214
# # these are used often for annotations, and full returns it as a string
215
215
# return el.full
216
216
217
217
@dispatch
218
- def to_md (self , el : Union [dc .Object , dc .Alias ]):
218
+ def render (self , el : Union [dc .Object , dc .Alias ]):
219
219
# TODO: replace hard-coded header level
220
220
221
221
_str_dispname = self ._fetch_object_dispname (el )
222
- _str_pars = self .to_md (el .parameters )
222
+ _str_pars = self .render (el .parameters )
223
223
str_sig = f"`{ _str_dispname } ({ _str_pars } )`"
224
224
225
225
_anchor = f"{{ #{ _str_dispname } }}"
@@ -232,7 +232,7 @@ def to_md(self, el: Union[dc.Object, dc.Alias]):
232
232
for section in el .docstring .parsed :
233
233
new_el = docstring_section_narrow (section )
234
234
title = new_el .kind .value
235
- body = self .to_md (new_el )
235
+ body = self .render (new_el )
236
236
237
237
if title != "text" :
238
238
header = f"{ '#' * (self .header_level + 1 )} { title .title ()} "
@@ -248,17 +248,17 @@ def to_md(self, el: Union[dc.Object, dc.Alias]):
248
248
return "\n \n " .join (parts )
249
249
250
250
@dispatch
251
- def to_md (self , el : dc .Attribute ):
251
+ def render (self , el : dc .Attribute ):
252
252
raise NotImplementedError ()
253
253
254
254
# signature parts -------------------------------------------------------------
255
255
256
256
@dispatch
257
- def to_md (self , el : dc .Parameters ):
258
- return ", " .join (map (self .to_md , el ))
257
+ def render (self , el : dc .Parameters ):
258
+ return ", " .join (map (self .render , el ))
259
259
260
260
@dispatch
261
- def to_md (self , el : dc .Parameter ):
261
+ def render (self , el : dc .Parameter ):
262
262
# TODO: missing annotation
263
263
splats = {dc .ParameterKind .var_keyword , dc .ParameterKind .var_positional }
264
264
has_default = el .default and el .kind not in splats
@@ -280,24 +280,24 @@ def to_md(self, el: dc.Parameter):
280
280
# note this can be a number of things. for example, opening docstring text,
281
281
# or a section with a header not included in the numpydoc standard
282
282
@dispatch
283
- def to_md (self , el : ds .DocstringSectionText ):
283
+ def render (self , el : ds .DocstringSectionText ):
284
284
new_el = docstring_section_narrow (el )
285
285
if isinstance (new_el , ds .DocstringSectionText ):
286
286
# ensures we don't recurse forever
287
287
return el .value
288
288
289
- return self .to_md (new_el )
289
+ return self .render (new_el )
290
290
291
291
# parameters ----
292
292
293
293
@dispatch
294
- def to_md (self , el : ds .DocstringSectionParameters ):
295
- rows = list (map (self .to_md , el .value ))
294
+ def render (self , el : ds .DocstringSectionParameters ):
295
+ rows = list (map (self .render , el .value ))
296
296
header = ["Name" , "Type" , "Description" , "Default" ]
297
297
return tabulate (rows , header , tablefmt = "github" )
298
298
299
299
@dispatch
300
- def to_md (self , el : ds .DocstringParameter ) -> Tuple [str ]:
300
+ def render (self , el : ds .DocstringParameter ) -> Tuple [str ]:
301
301
# TODO: if default is not, should return the word "required" (unescaped)
302
302
default = "required" if el .default is None else escape (el .default )
303
303
@@ -307,56 +307,56 @@ def to_md(self, el: ds.DocstringParameter) -> Tuple[str]:
307
307
# attributes ----
308
308
309
309
@dispatch
310
- def to_md (self , el : ds .DocstringSectionAttributes ):
310
+ def render (self , el : ds .DocstringSectionAttributes ):
311
311
header = ["Name" , "Type" , "Description" ]
312
- rows = list (map (self .to_md , el .value ))
312
+ rows = list (map (self .render , el .value ))
313
313
314
314
return tabulate (rows , header , tablefmt = "github" )
315
315
316
316
@dispatch
317
- def to_md (self , el : ds .DocstringAttribute ):
317
+ def render (self , el : ds .DocstringAttribute ):
318
318
annotation = self ._render_annotation (el .annotation )
319
- return el .name , self .to_md (annotation ), el .description
319
+ return el .name , self .render (annotation ), el .description
320
320
321
321
# see also ----
322
322
323
323
@dispatch
324
- def to_md (self , el : DocstringSectionSeeAlso ):
324
+ def render (self , el : DocstringSectionSeeAlso ):
325
325
# TODO: attempt to parse See Also sections
326
326
return convert_rst_link_to_md (el .value )
327
327
328
328
# examples ----
329
329
330
330
@dispatch
331
- def to_md (self , el : ds .DocstringSectionExamples ):
331
+ def render (self , el : ds .DocstringSectionExamples ):
332
332
# its value is a tuple: DocstringSectionKind["text" | "examples"], str
333
333
data = map (tuple_to_data , el .value )
334
- return "\n \n " .join (list (map (self .to_md , data )))
334
+ return "\n \n " .join (list (map (self .render , data )))
335
335
336
336
@dispatch
337
- def to_md (self , el : ExampleCode ):
337
+ def render (self , el : ExampleCode ):
338
338
return f"""```python
339
339
{ el .value }
340
340
```"""
341
341
342
342
# returns ----
343
343
344
344
@dispatch
345
- def to_md (self , el : Union [ds .DocstringSectionReturns , ds .DocstringSectionRaises ]):
346
- rows = list (map (self .to_md , el .value ))
345
+ def render (self , el : Union [ds .DocstringSectionReturns , ds .DocstringSectionRaises ]):
346
+ rows = list (map (self .render , el .value ))
347
347
header = ["Type" , "Description" ]
348
348
return tabulate (rows , header , tablefmt = "github" )
349
349
350
350
@dispatch
351
- def to_md (self , el : Union [ds .DocstringReturn , ds .DocstringRaise ]):
351
+ def render (self , el : Union [ds .DocstringReturn , ds .DocstringRaise ]):
352
352
# similar to DocstringParameter, but no name or default
353
353
annotation = self ._render_annotation (el .annotation )
354
354
return (annotation , el .description )
355
355
356
356
# unsupported parts ----
357
357
358
358
@dispatch
359
- def to_md (self , el : ExampleText ):
359
+ def render (self , el : ExampleText ):
360
360
return el .value
361
361
362
362
@dispatch .multi (
@@ -367,5 +367,5 @@ def to_md(self, el: ExampleText):
367
367
(ds .DocstringReceive ,),
368
368
(ds .DocstringAttribute ,),
369
369
)
370
- def to_md (self , el ):
370
+ def render (self , el ):
371
371
raise NotImplementedError (f"{ type (el )} " )
0 commit comments