Skip to content

Commit 3b04f80

Browse files
authored
Merge pull request #18 from parikshit14/bug/rst-url-link
formated rst URLs
2 parents 073841e + c5b89e6 commit 3b04f80

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed

examples/document.rst

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ 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
28+
2829

2930
**Allowed parameters**
3031

@@ -49,8 +50,8 @@ A model of a paragraph.
4950

5051
**Allowed parameters**
5152

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

src/modelspec/base_types.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -609,28 +609,28 @@ def insert_links(text, format=MARKDOWN_FORMAT):
609609
if ref[0] == "~":
610610
ref = ref[1:]
611611
post = text2[ind2 + 1 :]
612-
text2 = f'{pre}<a href="#{ref.lower()}">{ref}</a>{post}'
612+
if format == MARKDOWN_FORMAT:
613+
text2 = f'{pre}<a href="#{ref.lower()}">{ref}</a>{post}'
614+
elif format == RST_FORMAT:
615+
text2 = f"{pre}`{ref} <#{ref.lower()}>`_ {post}"
616+
613617
# print(" > Converted to: %s" % text2)
614618
text = text2
615619

616620
if "_" not in text:
617621
return text
618622
if '"' in text:
619623
return text # Assume it's a quoted string containing an underscore...
624+
if format == RST_FORMAT:
625+
return text # No need to remove underscore for RST format
626+
620627
split = text.split("_")
621628
text2 = ""
622629
for i in range(int(len(split) / 2.0)):
623630
pre = split[i * 2]
624631
type = split[i * 2 + 1]
625-
if format == MARKDOWN_FORMAT:
626-
text2 += f'{pre}<a href="#{type.lower()}">{type}</a>'
627-
elif format == RST_FORMAT:
628-
# text2 += ('%s'+rst_url_format) % (pre, type, '#'+type.lower # problem with handling links ending with s e.g. _Graph_s
632+
text2 += f'{pre}<a href="#{type.lower()}">{type}</a>'
629633

630-
text2 += ("%s%s") % (
631-
pre,
632-
type,
633-
) # temp hack... problem with handling links ending with s e.g. _Graph_s
634634
if int(len(split) / 2.0) != len(split) / 2.0:
635635
text2 += split[-1]
636636
return text2

0 commit comments

Comments
 (0)