Skip to content

Commit faf9940

Browse files
committed
Improved rst
1 parent 30a6dc6 commit faf9940

File tree

2 files changed

+60
-5
lines changed

2 files changed

+60
-5
lines changed

examples/document.rst

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,47 @@ Allowed field Data Type Description
1818
Allowed children
1919
================
2020

21-
<table>
22-
</table>
21+
=============== ============================== ==============================
22+
Allowed child Data Type Description
23+
=============== ============================== ==============================
24+
**sections** <a href="#section">Section</a> *The sections of the document*
25+
=============== ============================== ==============================
26+
27+
=======
28+
Section
29+
=======
30+
A model of a section of the document
31+
32+
Allowed parameters
33+
==================
34+
35+
=============== =========== ======================
36+
Allowed field Data Type Description
37+
=============== =========== ======================
38+
**id** str *Unique ID of element*
39+
**notes** str *Human readable notes*
40+
=============== =========== ======================
41+
42+
Allowed children
43+
================
44+
45+
=============== ================================== ================
46+
Allowed child Data Type Description
47+
=============== ================================== ================
48+
**paragraphs** <a href="#paragraph">Paragraph</a> *The paragraphs*
49+
=============== ================================== ================
50+
51+
=========
52+
Paragraph
53+
=========
54+
A model of a paragraph
55+
56+
Allowed parameters
57+
==================
58+
59+
=============== =========== ====================
60+
Allowed field Data Type Description
61+
=============== =========== ====================
62+
**contents** str *Paragraph contents*
63+
=============== =========== ====================
2364

modelspec/BaseTypes.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,8 @@ def insert_links(text):
474474
doc_string += "#### Allowed children\n\n<table>\n"
475475
if format == RST_FORMAT:
476476
ap = "Allowed children"
477-
doc_string += "%s\n%s\n\n<table>\n" % (ap,"="*len(ap))
477+
doc_string += "%s\n%s\n\n" % (ap,"="*len(ap))
478+
table_info = []
478479
if format == DICT_FORMAT:
479480
doc_dict[name]["allowed_children"] = {}
480481

@@ -505,6 +506,19 @@ def insert_links(text):
505506
insert_links(self.allowed_children[c][0])
506507
)
507508

509+
if format == RST_FORMAT:
510+
n = "**%s**" % c
511+
t = "%s" % (
512+
'<a href="#%s">%s</a>' % (type_.lower(), type_)
513+
if referencable
514+
else type_,
515+
)
516+
d = "*%s*" % (
517+
insert_links(self.allowed_children[c][0])
518+
)
519+
table_info.append([n,t,d])
520+
521+
508522
inst = self.allowed_children[c][1]()
509523
inst.id = ""
510524
referenced.append(inst)
@@ -515,10 +529,10 @@ def insert_links(text):
515529

516530
if len(self.allowed_children) > 0:
517531
if format == RST_FORMAT:
518-
doc_string += "</table>\n\n"
532+
doc_string += "%s\n\n"%(tabulate(table_info, ['Allowed child','Data Type','Description'], tablefmt="rst"))
519533

520534
for r in referenced:
521-
if format == MARKDOWN_FORMAT:
535+
if format == MARKDOWN_FORMAT or format== RST_FORMAT:
522536
doc_string += r.generate_documentation(format=format)
523537
if format == DICT_FORMAT:
524538
pass

0 commit comments

Comments
 (0)