Skip to content

Commit 90da0ab

Browse files
committed
formated rst URLs
1 parent 79f4663 commit 90da0ab

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

examples/document.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Allowed child Data Type Description
2424
=======
2525
Section
2626
=======
27-
A model of a section of the <a href="#document">Document</a>. Will contain one <a href="#paragraph">Paragraph</a> or more
27+
A model of a section of the `Document <#document>`_ . Will contain one `Paragraph <#paragraph>`_ or more
2828

2929
**Allowed parameters**
3030

@@ -49,8 +49,8 @@ A model of a paragraph
4949

5050
**Allowed parameters**
5151

52-
=============== =========== =================================================
52+
=============== =========== ===================================================
5353
Allowed field Data Type Description
54-
=============== =========== =================================================
55-
**contents** str *Paragraph contents, which make up the Sections.*
56-
=============== =========== =================================================
54+
=============== =========== ===================================================
55+
**contents** str *Paragraph contents, which make up the _Section_s.*
56+
=============== =========== ===================================================

src/modelspec/base_types.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -602,28 +602,28 @@ def insert_links(text, format=MARKDOWN_FORMAT):
602602
if ref[0] == "~":
603603
ref = ref[1:]
604604
post = text2[ind2 + 1 :]
605-
text2 = f'{pre}<a href="#{ref.lower()}">{ref}</a>{post}'
605+
if format == MARKDOWN_FORMAT:
606+
text2 = f'{pre}<a href="#{ref.lower()}">{ref}</a>{post}'
607+
elif format == RST_FORMAT:
608+
text2 = f"{pre}`{ref} <#{ref.lower()}>`_ {post}"
609+
606610
# print(" > Converted to: %s" % text2)
607611
text = text2
608612

609613
if "_" not in text:
610614
return text
611615
if '"' in text:
612616
return text # Assume it's a quoted string containing an underscore...
617+
if format == RST_FORMAT:
618+
return text # No need to remove underscore for RST format
619+
613620
split = text.split("_")
614621
text2 = ""
615622
for i in range(int(len(split) / 2.0)):
616623
pre = split[i * 2]
617624
type = split[i * 2 + 1]
618-
if format == MARKDOWN_FORMAT:
619-
text2 += f'{pre}<a href="#{type.lower()}">{type}</a>'
620-
elif format == RST_FORMAT:
621-
# text2 += ('%s'+rst_url_format) % (pre, type, '#'+type.lower # problem with handling links ending with s e.g. _Graph_s
625+
text2 += f'{pre}<a href="#{type.lower()}">{type}</a>'
622626

623-
text2 += ("%s%s") % (
624-
pre,
625-
type,
626-
) # temp hack... problem with handling links ending with s e.g. _Graph_s
627627
if int(len(split) / 2.0) != len(split) / 2.0:
628628
text2 += split[-1]
629629
return text2

0 commit comments

Comments
 (0)