3 # set correct links (pandoc did not deal with github links properly)
9 regex_pdf_links1
= re
.compile(r
'`(.*)\<g3doc\/(.*)\.pdf\>`__',
10 re
.M | re
.X
) # Multiline and Verbose
11 regex_md_links
= re
.compile(r
'`(.*)\<g3doc\/(.*)\.md\>`__',
12 re
.M | re
.X
) # Multiline and Verbose
13 regex_md_links2
= re
.compile(r
'`(.*)\n(.*)\<g3doc\/(.*)\.md\>`__',
14 re
.M | re
.X
) # Multiline and Verbose
15 regex_pdf_links2
= re
.compile(r
'`(.*)\n\s+(.*)\<g3doc\/(.*)\.pdf\>`__',
16 re
.M | re
.X
) # Multiline and Verbose
18 def remove_links_to_index2(data
):
19 # remove liks to the index, they are useless in py4web docs
21 print(re
.search(regex_pdf_links2
, data
))
22 return re
.sub(regex_pdf_links2
,
23 r
':download:`\1 \2<g3doc/\3.pdf>`',
26 def remove_links_to_index(data
):
27 # remove liks to the index, they are useless in py4web docs
29 print(re
.search(regex_pdf_links1
, data
))
30 return re
.sub(regex_pdf_links1
,
31 r
':download:`\1<g3doc/\2.pdf>`',
34 def rewrite_md_links(data
):
35 # remove liks to the index, they are useless in py4web docs
37 print(re
.search(regex_md_links
, data
))
38 data
= re
.sub(regex_md_links
,
41 data
= re
.sub(regex_md_links2
,
42 r
'`\1 \2<\3.html>`__',
50 'design_philosophy.md',
53 'release_testing_process.md'
57 print(f
" Working on file {file}")
58 file = os
.path
.join('g3doc', file)
59 data
= open(file, 'r').read()
60 write_files(file, data
)
62 def write_files(file, data
):
63 for extension
in ['rst']:
65 md_dir
= os
.path
.join(os
.getcwd(), 'g3doc')
66 if not os
.path
.isdir(ext_dir
):
68 ext_file
= os
.path
.join(ext_dir
, os
.path
.splitext(os
.path
.basename(file))[0] + "." + extension
)
69 md_file
= os
.path
.join(md_dir
, os
.path
.splitext(os
.path
.basename(file))[0] + ".md")
70 print(f
'writing {ext_file}')
71 if os
.path
.exists(ext_file
):
73 with
open(ext_file
, 'w') as handler
:
74 write_format(extension
, ext_file
, handler
, md_file
, data
)
77 def write_format(extension
, ext_file
, handler
, md_file
, data
):
80 elif extension
=='rst':
82 subprocess
.call(['pandoc', '-s', md_file
, '-f', 'markdown', '-t', 'rst', '-o', ext_file
])
83 data
= open(ext_file
, 'r').read()
84 data
= remove_links_to_index(data
)
85 data
= remove_links_to_index2(data
)
86 data
= rewrite_md_links(data
)
88 # Open a file for writing
89 # with open('tmp.txt', 'w') as f:
90 # Call the subprocess and redirect the output to the file
91 # subprocess.call(['awk', '{ gsub(/<g3doc\//, "<"); print }', ext_file], stdout=f)
92 # os.system('mv tmp.txt ' + ext_file)
94 except FileNotFoundError
:
95 print("\n **** ERROR ****: you need the Pandoc module installed!")
97 elif extension
=='html':
99 subprocess
.call(['pandoc', '-s', md_file
, '-f', 'markdown', '-t', 'html', '-o', ext_file
, '--highlight-style=kate'])
100 except FileNotFoundError
:
101 print("\n **** ERROR ****: you need the Pandoc module installed!")
105 if __name__
== "__main__":
106 for doc
in docs_on_pages
: