def edit_page(name): content = "" action = "Create" if util.page_exists(PAGES_DIR, name): page = codecs.open(os.path.join(PAGES_DIR, name), "r", "utf8") content = "".join(page.readlines()) page.close() action = "Edit" return template("edit.html", name=name, content=content, action=action)
def page(name): if util.page_exists(PAGES_DIR, name): page = open(os.path.join(PAGES_DIR, name), "r") document = markdown2.markdown(unicode("".join(page.readlines()), "utf-8", "ignore")) return template("page.html", name=name, content=document) elif name == "start": start_text = """\ ##A Mercurial Wiki## This is a wiki built on top of Mercurial. You can use the [markdown markup](https://github.com/trentm/python-markdown2) to layout your wiki pages. Start creating some content!""" util.write_to_file(REPO_DIR, PAGES_DIR, os.path.join(PAGES_DIR, name), start_text) util.commit_to_repo(REPO_DIR, [os.path.join(PAGES_DIR, name)], name) document = markdown2.markdown(start_text) return template("page.html", name=name, content=document) else: redirect("/edit/" + name)