Initial commit
This commit is contained in:
commit
04e73e4d10
|
@ -0,0 +1,3 @@
|
|||
venv/
|
||||
files/
|
||||
out/
|
|
@ -0,0 +1,45 @@
|
|||
#!python
|
||||
import os
|
||||
import shutil
|
||||
from markdown2 import markdown
|
||||
|
||||
input_ = 'files'
|
||||
output = 'out'
|
||||
templates = 'templates'
|
||||
|
||||
|
||||
def render_template(**kwargs):
|
||||
expanded = template[:]
|
||||
|
||||
for var, val in kwargs.items():
|
||||
expanded = expanded.replace('${%s}' % var, val)
|
||||
|
||||
return expanded
|
||||
|
||||
|
||||
with open(templates + '/base.html', 'r') as template:
|
||||
template = template.read()
|
||||
|
||||
for root, dirs, files in os.walk(input_, topdown=True):
|
||||
outroot = output + root[len(input_):]
|
||||
|
||||
os.makedirs(outroot, exist_ok=True)
|
||||
|
||||
shutil.copy(templates + '/stylesheet.css', outroot + '/stylesheet.css')
|
||||
|
||||
for file in files:
|
||||
if file.endswith('.md'):
|
||||
basename = file[:-3]
|
||||
outfile = outroot + '/' + basename + '.html'
|
||||
infile = root + '/' + file
|
||||
|
||||
with open(infile, 'r') as f:
|
||||
content = f.read()
|
||||
|
||||
with open(outfile, 'w') as f:
|
||||
content = markdown(content)
|
||||
|
||||
new_file = render_template(title=basename,
|
||||
content=content)
|
||||
|
||||
f.write(new_file)
|
|
@ -0,0 +1,40 @@
|
|||
# Header 1
|
||||
## Header 2
|
||||
### Header 3
|
||||
#### Header 4
|
||||
##### Header 5
|
||||
###### Header 6
|
||||
|
||||
This is a paragraph.
|
||||
|
||||
This is another one. They are separated by 2 new lines.
|
||||
So this one is the same paragraph.
|
||||
And to have a line break, leave 2 trailing whitespaces, like
|
||||
in the previous line.
|
||||
|
||||
And there is **bold text**. And *italic*
|
||||
|
||||
> Blockquoted.
|
||||
>
|
||||
> With multiple paragraphs.
|
||||
>> And a nested quote.
|
||||
|
||||
1. Ordered list
|
||||
2. Very orderly
|
||||
3. And nice
|
||||
|
||||
- Unordered list
|
||||
- Messy
|
||||
- But nice too
|
||||
|
||||
`inline code here`
|
||||
|
||||
```
|
||||
Block code
|
||||
```
|
||||
|
||||
![Image alt description](/url/to/image)
|
||||
|
||||
[Links are similar](https://linksomewhere.com)
|
||||
|
||||
Inline <em>HTML</em> is possible
|
|
@ -0,0 +1 @@
|
|||
markdown2
|
|
@ -0,0 +1,11 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8"/>
|
||||
<link rel="stylesheet" href="stylesheet.css"/>
|
||||
<title>${title}</title>
|
||||
</head>
|
||||
<body>
|
||||
${content}
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,3 @@
|
|||
body {
|
||||
background-color: blue
|
||||
}
|
Loading…
Reference in New Issue