insert_demo.py
1 """Insert the demo into the codemirror site.""" 2 import os 3 import fileinput 4 import shutil 5 6 proselint_path = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) 7 8 code_mirror_path = os.path.join( 9 proselint_path, 10 "plugins", 11 "webeditor") 12 13 code_mirror_demo_path = os.path.join(code_mirror_path, "index.html") 14 15 live_write_path = os.path.join(proselint_path, "site", "write") 16 17 if os.path.exists(live_write_path): 18 shutil.rmtree(live_write_path) 19 shutil.copytree(code_mirror_path, live_write_path) 20 21 demo_path = os.path.join(proselint_path, "proselint", "demo.md") 22 23 with open(demo_path, "r") as f: 24 demo = f.read() 25 26 for line in fileinput.input( 27 os.path.join(live_write_path, "index.html"), inplace=True): 28 29 if "##DEMO_PLACEHOLDER##" in line: 30 print(demo) 31 else: 32 print(line)