This repository was archived by the owner on Sep 18, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgenPDF.py
More file actions
executable file
·56 lines (49 loc) · 1.44 KB
/
Copy pathgenPDF.py
File metadata and controls
executable file
·56 lines (49 loc) · 1.44 KB
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
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/python
import os
import glob
import re
import string
ignoreList = [
r'.+\.(md|svg|png|pdf|log|fls|aux|gz|lock|fdb_latexmk|dvi|tex)',
r'.+(node_modules|build|dist|_minted-source-list|\.git).+',
r'.*(server.*|solver.*)',
r'.*board\.json'
]
highlight = {
'javascript': r'.+\.(ts|js|tsx|json)',
'bash': r'.+\.(sh)',
'yaml': r'.+\.yml',
'html': r'.+\.html',
'css': r'.+\.(css|scss)',
'python': r'.+\.(py)',
}
def genListRec(path):
for ignore in ignoreList:
if re.match(ignore, path):
return ''
script = ''
if os.path.isdir(path):
for entry in glob.glob(path + '/*') + glob.glob(path + '/.*'):
script += genListRec(entry)
return script
lang = 'text'
for hlang, pat in highlight.items():
if re.match(pat, path):
lang = hlang
path = path.replace('_', r'\_')
return string.Template(r'''
\section{$path}
\inputminted[linenos, obeytabs=true, tabsize=2, breaklines]{$lang}{$path}
\newpage
''').substitute({ 'lang': lang, 'path': path })
if __name__ == '__main__':
script = string.Template(r'''
\documentclass[dvipdfmx]{jsarticle}
\usepackage{minted}
\begin{document}
$script
\end{document}
''').substitute({ 'script': genListRec('./') })
with open('source-list.tex', 'w') as tex:
tex.write(script)
os.system('latexmk ./source-list.tex')