-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmd_to_html.py
51 lines (38 loc) · 1.34 KB
/
md_to_html.py
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
#! /usr/bin/env python
#coding=utf8
'''
Injects html generated from index.md to index.html
'''
import re
from datetime import date
import mistune
from mistune import create_markdown
#renderer = mistune.Renderer(hard_wrap=False)
#markdown = mistune.Markdown(renderer=renderer)
markdown = create_markdown(renderer=mistune.HTMLRenderer(escape=False))
# Read index.md and convert to html
with open('index.md', 'r') as f:
text = f.read()
preamble = re.sub('## Share your experience.*', '', text, flags=re.S)
preamble = markdown(preamble)
share = re.sub('.*Choose columns to show', '', text, flags=re.S)
share = markdown(share)
# Inject it into index.html
with open('index.html', 'r+') as f:
text = f.read()
# Inject preamble
text = re.sub(
'<div class="preamble">(.*?)div>',
'<div class="preamble">{}</div>'.format(preamble),
text, flags=re.S)
# Inject 'share your experience' after the table
text = re.sub(
'<div class="isso-comments">(.*?)<section id="isso-thread">',
'<div class="isso-comments">{}<section id="isso-thread">'.format(share),
text, flags=re.S)
# Update date in index.html footer
text = re.sub('Last updated:.*','Last updated: {} <br>'.format(date.today()), text)
f.seek(0)
f.write(text)
f.truncate()
print('index.html has been updated')