-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreadme.py
46 lines (36 loc) · 1.09 KB
/
readme.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import subprocess
def ipynb_to_markdown():
cp = subprocess.run(
[
"jupyter",
"nbconvert",
"readme.ipynb",
"--to",
"markdown",
]
)
print(cp.returncode)
return
def add_image_references():
with open("readme.md") as f:
source = f.readlines()
i = iter(source)
image_count = 0
with open("readme.md", "w") as f:
while (l := next(i, None)) is not None:
f.write(l)
if l == "```\n":
f.write(
next(i)
) # read the empty line after triple backtick code block closing
image_count += 1
f.write(
f"![image_{image_count}](https://raw.githubusercontent.com/marcelloDC/selfdocprint/main/images/output_image_{image_count}.png)\n\n"
)
def main():
"""A script to convert readme.ipynb to readme.md and add
image references for output images in readme.md."""
ipynb_to_markdown()
add_image_references()
if __name__ == "__main__":
main()