Skip to content

Commit 27be3a4

Browse files
committed
TL: first step toward cross-reference links
1 parent bf359c2 commit 27be3a4

File tree

3 files changed

+44
-4
lines changed

3 files changed

+44
-4
lines changed

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ Additionally, a _few_ rules are set to enforce code readability, consistency and
1212
Others are specific conventions chosen for the pySDC library, that may follow Python standards (or not ...), detailed in the [naming conventions page](./docs/contrib/03_naming_conventions.md).
1313

1414
Finally, while `pySDC` provides many base functionalities that implement classical flavors of SDC, it also allows problem-specific applications through Object-Oriented Programming (OOP) and the implementation of custom inherited classes.
15-
This follows a specific OOP framework, for which more details are given [here](.(docs/contrib/../../docs/contrib/04_custom_implementations.md)).
15+
This follows a specific OOP framework, for which more details are given [here](./docs/contrib/04_custom_implementations.md).

docs/convert_markdown.py

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import glob
1010
import json
1111
import m2r2
12+
import numpy as np
1213

1314
mdFiles = [
1415
'README.md',
@@ -19,14 +20,53 @@
1920

2021
docSources = 'docs/source'
2122

23+
counter = np.array(0)
24+
2225
with open('docs/emojis.json') as f:
2326
emojis = set(json.load(f).keys())
2427

25-
def convert(md):
26-
rst = m2r2.parse_from_file(md, parse_relative_links=True)
28+
def wrappEmojis(rst):
2729
for emoji in emojis:
2830
rst = rst.replace(emoji, f'|{emoji}|')
31+
return rst
32+
33+
def addSectionRefs(rst, baseName):
34+
sections = {}
35+
lines = rst.splitlines()
36+
# Search for sections in rst file
37+
for i in range(len(lines)-2):
38+
conds = [
39+
len(lines[i+1]) and lines[i+1][0] in ['=', '-', '^', '"'],
40+
lines[i+2] == lines[i-1] == '',
41+
len(lines[i]) == len(lines[i+1])]
42+
if all(conds):
43+
sections[i] = lines[i]
44+
# Add unique references before each section
45+
for i, title in sections.items():
46+
ref = '-'.join([elt for elt in title.lower().split(' ') if elt != ''])
47+
for char in ['#', "'", '^', '°', '!']:
48+
ref = ref.replace(char, '')
49+
ref = f'{baseName}/{ref}'
50+
lines[i] = f'.. _{ref}:\n\n'+lines[i]
51+
# Returns all concatenated lines
52+
return '\n'.join(lines)
53+
54+
def completeRefLinks(rst, baseName):
55+
i = 0
56+
while i != -1:
57+
i = rst.find(':ref:`', i)
58+
if i != -1:
59+
iLink = rst.find('<', i)
60+
rst = rst[:iLink+1]+f'{baseName}/'+rst[iLink+1:]
61+
i += 6
62+
return rst
63+
64+
def convert(md):
2965
baseName = os.path.splitext(md)[0]
66+
rst = m2r2.parse_from_file(md, parse_relative_links=True)
67+
rst = wrappEmojis(rst)
68+
rst = addSectionRefs(rst, baseName)
69+
rst = completeRefLinks(rst, baseName)
3070
with open(f'{docSources}/{baseName}.rst', 'w') as f:
3171
f.write(rst)
3272
print(f'Converted {md} to {docSources}/{baseName}.rst')

docs/source/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@
107107
# If true, the current module name will be prepended to all description
108108
# unit titles (such as .. function::).
109109
#
110-
# add_module_names = True
110+
add_module_names = False
111111

112112
# If true, sectionauthor and moduleauthor directives will be shown in the
113113
# output. They are ignored by default.

0 commit comments

Comments
 (0)