Skip to content

Commit 559f52e

Browse files
committed
Supports :code: and hardcoded handling of plurals
1 parent cd2b845 commit 559f52e

File tree

6 files changed

+53
-31
lines changed

6 files changed

+53
-31
lines changed

examples/document.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ A model for documents.
3838
</table>
3939

4040
## Section
41-
A model of a section of the <a href="#document">Document</a>. Will contain one <a href="#paragraph">Paragraph</a> or more.
41+
A model of a section of the <a href="#document">Document</a>. Will contain one <a href="#paragraph">Paragraph</a> or more, i.e the <a href="#paragraph">Paragraph</a>(s) in the section, probably related to the <b>title</b> of the `Document <#document>`_.
4242

4343
### Allowed parameters
4444
<table>

examples/document.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class Paragraph(Base):
2222
class Section(Base):
2323
"""
2424
A model of a section of the :class:`Document`.
25-
Will contain one :class:`Paragraph` or more.
25+
Will contain one :class:`Paragraph` or more, i.e the :class:`Paragraph`(s) in the section, probably related to the :code:`title` of the `Document <#document>`_.
2626
2727
Args:
2828
id: The id of the section

examples/document.rst

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,42 +5,42 @@ A model for documents.
55

66
**Allowed parameters**
77

8-
=============== =========== ====================================
8+
=============== =========== ==================================
99
Allowed field Data Type Description
10-
=============== =========== ====================================
11-
**id** str *The unique id of the document*
12-
**title** str *Document title*
13-
**ISBN** int *International Standard Book Number*
14-
=============== =========== ====================================
10+
=============== =========== ==================================
11+
**id** str The unique id of the document
12+
**title** str Document title
13+
**ISBN** int International Standard Book Number
14+
=============== =========== ==================================
1515

1616
**Allowed children**
1717

18-
=============== ===================== ==============================
18+
=============== ===================== ============================
1919
Allowed child Data Type Description
20-
=============== ===================== ==============================
21-
**sections** `Section <#section>`_ *The sections of the document*
22-
=============== ===================== ==============================
20+
=============== ===================== ============================
21+
**sections** `Section <#section>`_ The sections of the document
22+
=============== ===================== ============================
2323

2424
=======
2525
Section
2626
=======
27-
A model of a section of the `Document <#document>`_. Will contain one `Paragraph <#paragraph>`_ or more.
27+
A model of a section of the `Document <#document>`_. Will contain one `Paragraph <#paragraph>`_ or more, i.e the `Paragraph(s) <#paragraph>`_ in the section, probably related to the **title** of the `Document <#document>`_.
2828

2929
**Allowed parameters**
3030

31-
=============== =========== =======================
31+
=============== =========== =====================
3232
Allowed field Data Type Description
33-
=============== =========== =======================
34-
**id** str *The id of the section*
35-
=============== =========== =======================
33+
=============== =========== =====================
34+
**id** str The id of the section
35+
=============== =========== =====================
3636

3737
**Allowed children**
3838

39-
=============== ========================= ================
39+
=============== ========================= ==============
4040
Allowed child Data Type Description
41-
=============== ========================= ================
42-
**paragraphs** `Paragraph <#paragraph>`_ *The paragraphs*
43-
=============== ========================= ================
41+
=============== ========================= ==============
42+
**paragraphs** `Paragraph <#paragraph>`_ The paragraphs
43+
=============== ========================= ==============
4444

4545
=========
4646
Paragraph
@@ -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 `Section <#section>`_s.*
56-
=============== =========== ===============================================================
54+
=============== =========== =============================================================
55+
**contents** str Paragraph contents, which make up the `Sections <#section>`_.
56+
=============== =========== =============================================================

examples/document.specification.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
}
2424
},
2525
"Section": {
26-
"definition": "A model of a section of the :class:`Document`. Will contain one :class:`Paragraph` or more.",
26+
"definition": "A model of a section of the :class:`Document`. Will contain one :class:`Paragraph` or more, i.e the :class:`Paragraph`(s) in the section, probably related to the :code:`title` of the `Document <#document>`_.",
2727
"allowed_parameters": {
2828
"id": {
2929
"type": "str",

examples/document.specification.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ Document:
1616
description: The sections of the document
1717
Section:
1818
definition: A model of a section of the :class:`Document`. Will contain one :class:`Paragraph`
19-
or more.
19+
or more, i.e the :class:`Paragraph`(s) in the section, probably related to
20+
the :code:`title` of the `Document <#document>`_.
2021
allowed_parameters:
2122
id:
2223
type: str

src/modelspec/base_types.py

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,12 @@ def insert_links(text, format=MARKDOWN_FORMAT):
594594
pre = text2[0:ind]
595595
ref = text2[ind + len(code_ref) : ind2]
596596
post = text2[ind2 + 1 :]
597-
text2 = f"{pre}<b>{ref}</b>{post}"
597+
598+
if format == MARKDOWN_FORMAT:
599+
text2 = f"{pre}<b>{ref}</b>{post}"
600+
elif format == RST_FORMAT:
601+
text2 = f"{pre}**{ref}**{post}"
602+
598603
# print(" > Converted to: %s" % text2)
599604
text = text2
600605

@@ -612,7 +617,23 @@ def insert_links(text, format=MARKDOWN_FORMAT):
612617
if format == MARKDOWN_FORMAT:
613618
text2 = f'{pre}<a href="#{ref.lower()}">{ref}</a>{post}'
614619
elif format == RST_FORMAT:
615-
text2 = f"{pre}`{ref} <#{ref.lower()}>`_{post}"
620+
rr = ref
621+
pp = post
622+
623+
######################################
624+
# Some hardcoded fixes for plurals...
625+
if pp.startswith("s "):
626+
rr += "s"
627+
pp = pp[1:]
628+
if pp.startswith("s."):
629+
rr += "s"
630+
pp = pp[1:]
631+
if pp.startswith("(s)"):
632+
rr += "(s)"
633+
pp = pp[3:]
634+
######################################
635+
636+
text2 = f"{pre}`{rr} <#{ref.lower()}>`_{pp}"
616637

617638
# print(" > Converted to: %s" % text2)
618639
text = text2
@@ -694,7 +715,7 @@ def insert_links(text, format=MARKDOWN_FORMAT):
694715
if referencable
695716
else type_str,
696717
)
697-
d = "*%s*" % (insert_links(description, format=RST_FORMAT))
718+
d = "%s" % (insert_links(description, format=RST_FORMAT))
698719
table_info.append([n, t, d])
699720

700721
if referencable:
@@ -755,7 +776,7 @@ def insert_links(text, format=MARKDOWN_FORMAT):
755776
if referencable
756777
else type_str,
757778
)
758-
d = "*%s*" % (insert_links(description, format=RST_FORMAT))
779+
d = "%s" % (insert_links(description, format=RST_FORMAT))
759780
table_info.append([n, t, d])
760781

761782
# Get the contained type

0 commit comments

Comments
 (0)