Skip to content

Commit 1e99136

Browse files
committed
Imprived rst
1 parent faf9940 commit 1e99136

File tree

2 files changed

+22
-17
lines changed

2 files changed

+22
-17
lines changed

examples/document.rst

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

21-
=============== ============================== ==============================
22-
Allowed child Data Type Description
23-
=============== ============================== ==============================
24-
**sections** <a href="#section">Section</a> *The sections of the document*
25-
=============== ============================== ==============================
21+
=============== ==================== ==============================
22+
Allowed child Data Type Description
23+
=============== ==================== ==============================
24+
**sections** `section <Section>`_ *The sections of the document*
25+
=============== ==================== ==============================
2626

2727
=======
2828
Section
@@ -42,11 +42,11 @@ Allowed field Data Type Description
4242
Allowed children
4343
================
4444

45-
=============== ================================== ================
46-
Allowed child Data Type Description
47-
=============== ================================== ================
48-
**paragraphs** <a href="#paragraph">Paragraph</a> *The paragraphs*
49-
=============== ================================== ================
45+
=============== ======================== ================
46+
Allowed child Data Type Description
47+
=============== ======================== ================
48+
**paragraphs** `paragraph <Paragraph>`_ *The paragraphs*
49+
=============== ======================== ================
5050

5151
=========
5252
Paragraph

modelspec/BaseTypes.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,9 @@ def generate_documentation(self, format=MARKDOWN_FORMAT):
379379

380380
print(" - %s (%s)" % (self.__class__.__name__, self._definition))
381381

382-
def insert_links(text):
382+
rst_url_format = '`%s <%s>`_'
383+
384+
def insert_links(text, format=MARKDOWN_FORMAT):
383385
if not "_" in text:
384386
return text
385387
if '"' in text:
@@ -389,7 +391,10 @@ def insert_links(text):
389391
for i in range(int(len(split) / 2.0)):
390392
pre = split[i * 2]
391393
type = split[i * 2 + 1]
392-
text2 += '%s<a href="#%s">%s</a>' % (pre, type.lower(), type)
394+
if format==MARKDOWN_FORMAT:
395+
text2 += '%s<a href="#%s">%s</a>' % (pre, type.lower(), type)
396+
elif format==RST_FORMAT:
397+
text2 += ('%s'+rst_url_format) % (pre, type, type.lower())
393398
if int(len(split) / 2.0) != len(split) / 2.0:
394399
text2 += split[-1]
395400
return text2
@@ -403,7 +408,7 @@ def insert_links(text):
403408
elif format == RST_FORMAT:
404409
doc_string += "%s\n%s\n%s\n" % ("="*len(name),name,"="*len(name))
405410
if self._definition is not None:
406-
doc_string += "%s\n\n" % insert_links(self._definition)
411+
doc_string += "%s\n\n" % insert_links(self._definition, format = RST_FORMAT)
407412

408413
elif format == DICT_FORMAT:
409414
doc_dict[name] = {}
@@ -449,12 +454,12 @@ def insert_links(text):
449454
if format == RST_FORMAT:
450455
n = "**%s**" % f
451456
t = "%s" % (
452-
'<a href="#%s">%s</a>' % (type_.lower(), type_)
457+
rst_url_format % (type_, type_.lower())
453458
if referencable
454459
else type_,
455460
)
456461
d = "*%s*" % (
457-
insert_links(self.allowed_fields[f][0])
462+
insert_links(self.allowed_fields[f][0], format = RST_FORMAT)
458463
)
459464
table_info.append([n,t,d])
460465

@@ -509,12 +514,12 @@ def insert_links(text):
509514
if format == RST_FORMAT:
510515
n = "**%s**" % c
511516
t = "%s" % (
512-
'<a href="#%s">%s</a>' % (type_.lower(), type_)
517+
rst_url_format % (type_.lower(), type_)
513518
if referencable
514519
else type_,
515520
)
516521
d = "*%s*" % (
517-
insert_links(self.allowed_children[c][0])
522+
insert_links(self.allowed_children[c][0], format = RST_FORMAT)
518523
)
519524
table_info.append([n,t,d])
520525

0 commit comments

Comments
 (0)