-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathview_local
executable file
·39 lines (29 loc) · 1008 Bytes
/
view_local
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
#!/usr/bin/python
from sys import argv
from os import path
if '-no-incremental' in argv:
remove_incremental = True
argv.remove ('-no-incremental')
else:
remove_incremental = False
if len(argv) < 2 or not argv[1].endswith ('.md'):
raise ValueError ('expected markdown file with .md suffix')
html=''
markdown=''
with open ('_layouts/presentation.html') as fd:
html = fd.read()
with open(argv[1]) as fd:
npagebreak = 0
for line in fd.readlines():
if remove_incremental and line.strip() == '--':
continue
if npagebreak >= 2:
markdown += line
elif line.startswith ('title:'):
title = line.split(maxsplit=1)[1].strip().strip('"')
elif line.startswith ('---'):
npagebreak +=1
out = argv[1][:-3]+'.html'
with open (out, 'w') as fd:
fd.write (html.replace ('{{ page.title | strip_html }}', title).replace('{{ page.content }}', markdown))
print ("ready to view at file:///" + path.abspath (out))