6
6
verbose = False
7
7
8
8
MARKDOWN_FORMAT = "markdown"
9
+ RST_FORMAT = "rst"
10
+
9
11
DICT_FORMAT = "dict"
10
12
11
13
@@ -369,7 +371,7 @@ def generate_documentation(self, format=MARKDOWN_FORMAT):
369
371
Work in progress...
370
372
"""
371
373
372
- if format == MARKDOWN_FORMAT :
374
+ if format == MARKDOWN_FORMAT or format == RST_FORMAT :
373
375
doc_string = ""
374
376
if format == DICT_FORMAT :
375
377
doc_dict = {}
@@ -392,18 +394,27 @@ def insert_links(text):
392
394
return text2
393
395
394
396
name = self .__class__ .__name__
397
+
395
398
if format == MARKDOWN_FORMAT :
396
- doc_string += "## %s\n " % name
399
+ doc_string += "## %s\n \n " % name
397
400
if self ._definition is not None :
398
- doc_string += "%s\n " % insert_links (self ._definition )
399
- if format == DICT_FORMAT :
401
+ doc_string += "%s\n \n " % insert_links (self ._definition )
402
+ elif format == RST_FORMAT :
403
+ doc_string += "%s\n %s\n %s\n " % ("=" * len (name ),name ,"=" * len (name ))
404
+ if self ._definition is not None :
405
+ doc_string += "%s\n \n " % insert_links (self ._definition )
406
+
407
+ elif format == DICT_FORMAT :
400
408
doc_dict [name ] = {}
401
409
if self ._definition is not None :
402
410
doc_dict [name ]["definition" ] = self ._definition
403
411
404
412
if len (self .allowed_fields ) > 0 :
405
413
if format == MARKDOWN_FORMAT :
406
- doc_string += "#### Allowed parameters\n <table>"
414
+ doc_string += "### Allowed parameters\n <table>\n "
415
+ if format == RST_FORMAT :
416
+ ap = "Allowed parameters"
417
+ doc_string += "%s\n %s\n \n " % (ap ,"=" * len (ap ))
407
418
if format == DICT_FORMAT :
408
419
doc_dict [name ]["allowed_parameters" ] = {}
409
420
@@ -424,28 +435,47 @@ def insert_links(text):
424
435
] = self .allowed_fields [f ][0 ]
425
436
426
437
if format == MARKDOWN_FORMAT :
427
- doc_string += "<tr><td><b>%s</b></td><td>%s</td>" % (
438
+ doc_string += " <tr>\n <td><b>%s</b></td>\n <td>%s</td>" % (
428
439
f ,
429
440
'<a href="#%s">%s</a>' % (type_ .lower (), type_ )
430
441
if referencable
431
442
else type_ ,
432
443
)
433
- doc_string += "<td><i>%s</i></td></tr>\n \n " % (
444
+ doc_string += "\n <td><i>%s</i></td>\n </tr>\n \n " % (
445
+ insert_links (self .allowed_fields [f ][0 ])
446
+ )
447
+ if format == RST_FORMAT :
448
+ n = "<b>%s</b>" % f
449
+ t = "%s" % (
450
+ '<a href="#%s">%s</a>' % (type_ .lower (), type_ )
451
+ if referencable
452
+ else type_ ,
453
+ )
454
+ d = "<i>%s</i>" % (
434
455
insert_links (self .allowed_fields [f ][0 ])
435
456
)
436
457
458
+ doc_string += "%s %s %s\n " % ("=" * len (n ),"=" * len (t ),"=" * len (d ))
459
+ doc_string += "%s %s %s\n " % (n ,t ,d )
460
+ doc_string += "%s %s %s\n " % ("=" * len (n ),"=" * len (t ),"=" * len (d ))
461
+
437
462
if referencable :
438
463
inst = self .allowed_fields [f ][1 ]()
439
464
inst .id = ""
440
465
referenced .append (inst )
441
466
442
467
if len (self .allowed_fields ) > 0 :
443
468
if format == MARKDOWN_FORMAT :
444
- doc_string += "\n </table>\n \n "
469
+ doc_string += "</table>\n \n "
470
+ if format == RST_FORMAT :
471
+ doc_string += "</table>\n \n "
445
472
446
473
if len (self .allowed_children ) > 0 :
447
474
if format == MARKDOWN_FORMAT :
448
- doc_string += "#### Allowed children\n <table>"
475
+ doc_string += "#### Allowed children\n \n <table>\n "
476
+ if format == RST_FORMAT :
477
+ ap = "Allowed children"
478
+ doc_string += "%s\n %s\n \n <table>\n " % (ap ,"=" * len (ap ))
449
479
if format == DICT_FORMAT :
450
480
doc_dict [name ]["allowed_children" ] = {}
451
481
@@ -466,13 +496,13 @@ def insert_links(text):
466
496
] = self .allowed_children [c ][0 ]
467
497
468
498
if format == MARKDOWN_FORMAT :
469
- doc_string += "<tr><td><b>%s</b></td><td>%s</td>" % (
499
+ doc_string += " <tr>\n <td><b>%s</b></td>\n <td>%s</td>" % (
470
500
c ,
471
501
'<a href="#%s">%s</a>' % (type_ .lower (), type_ )
472
502
if referencable
473
503
else type_ ,
474
504
)
475
- doc_string += "<td><i>%s</i></td></tr>\n \n " % (
505
+ doc_string += "\n <td><i>%s</i></td>\n </tr>\n \n " % (
476
506
insert_links (self .allowed_children [c ][0 ])
477
507
)
478
508
@@ -482,7 +512,11 @@ def insert_links(text):
482
512
483
513
if len (self .allowed_children ) > 0 :
484
514
if format == MARKDOWN_FORMAT :
485
- doc_string += "\n </table>\n \n "
515
+ doc_string += "</table>\n \n "
516
+
517
+ if len (self .allowed_children ) > 0 :
518
+ if format == RST_FORMAT :
519
+ doc_string += "</table>\n \n "
486
520
487
521
for r in referenced :
488
522
if format == MARKDOWN_FORMAT :
@@ -491,7 +525,7 @@ def insert_links(text):
491
525
pass
492
526
doc_dict .update (r .generate_documentation (format = format ))
493
527
494
- if format == MARKDOWN_FORMAT :
528
+ if format == MARKDOWN_FORMAT or format == RST_FORMAT :
495
529
return doc_string
496
530
if format == DICT_FORMAT :
497
531
return doc_dict
0 commit comments