21 current_mode = Mode.Text
26 currently_in_raw_data_box: Jupyter's markdown export does not preserve raw
27 data cells. But we use them quite frequently. So we follow the convention
28 that raw data cells should be indented. And then we automatically
29 filter those lines out, and add the markup box around them.
33 if "\\begin{equation" in line
and current_mode == Mode.Text:
34 current_mode = Mode.EquationSystem
35 line =
""" @f{eqnarray*}{
37 elif "\\end{equation" in line:
38 current_mode = Mode.Text
53 elif current_mode == Mode.Text:
54 line = line.replace(
"$$",
"\n @f$ ")
62 Takes the markdown produced by nbconvert into something that plays along
63 nicely with our Doxygen.
65 filename: File without extension
67 ouput_file_name = filename +
".dox"
68 output_file = open(ouput_file_name,
"w")
70 output_file.write(
"/**\n")
74 have_created_header =
False
75 with open(filename +
".md")
as file:
77 if line.startswith(
"#")
and not have_created_header:
78 line = line.replace(
"#",
"")
79 path = filename.replace(
"./",
"").replace(
"/",
"_").replace(
".",
"_")
80 output_file.write(
"@page " + path +
" " + line)
83 <div style="color:Black ; background-color: #fcc ; padding: 10px; border: 1px solid green;">
84 This documentation is autogenerated from {}.ipynb. Once you clone the Peano repository, please work against this notebook or study
85 Peano's @ref page_tutorials_overview "generic description how to generate web documentation from Jupyter notebooks".
91 have_created_header =
True
92 elif "@subpage" in line:
93 new_subpage = line.split(
"@subpage")[1].strip().split(
" ")[0]
94 subpages.append(new_subpage)
95 output_file.write(line.replace(
"@subpage",
"@ref"))
96 elif "\\subpage" in line:
97 new_subpage = line.split(
"\\subpage")[1].strip().split(
" ")[0]
98 subpages.append(new_subpage)
99 output_file.write(line.replace(
"\\subpage",
"@ref"))
103 subpages = list(dict.fromkeys(subpages))
104 for subpage
in subpages:
105 if subpage.endswith(
"."):
106 subpage = subpage[0:-1]
114 print(
"Add subpage {}".format(subpage))
115 output_file.write(
"*/ \n ")
118 for dirpath, dirnames, filenames
in os.walk(
"."):
119 for filename
in [f
for f
in filenames
if f.endswith(
".ipynb")]:
120 notebook_filename = os.path.join(dirpath, filename)
121 if ".ipynb" in dirpath:
122 print(
"Ignore {}".format(notebook_filename))
124 print(
"Convert {} into markdown".format(notebook_filename))
126 [
"jupyter",
"nbconvert",
"--to",
"markdown", notebook_filename]
128 name_without_extension = notebook_filename.replace(
".ipynb",
"")
129 print(
"Postprocess markdown file {}.md".format(name_without_extension))
131 print(
"Delete markdown file")
132 subprocess.run([
"rm", name_without_extension +
".md"])
def postprocess_notebook_markdown(str filename)
Takes the markdown produced by nbconvert into something that plays along nicely with our Doxygen.
def postprocess_markdown_line(line)
currently_in_raw_data_box: Jupyter's markdown export does not preserve raw data cells.