# Path: rophako/utils.py
# def render_markdown(body, html_escape=True, extensions=None, blacklist=None):
#     """Render a block of Markdown text.
# 
#     This will default to escaping literal HTML characters. Set
#     `html_escape=False` to trust HTML.
# 
#     * extensions should be a set() of extensions to add.
#     * blacklist should be a set() of extensions to blacklist."""
# 
#     args = dict(
#         lazy_ol=False, # If a numbered list starts at e.g. 4, show the <ol> there
#         extensions=[
#             "fenced_code",  # GitHub style code blocks
#             "tables",       # http://michelf.ca/projects/php-markdown/extra/#table
#             "smart_strong", # Handles double__underscore better.
#             "codehilite",   # Code highlighting with Pygment!
#             "nl2br",        # Line breaks inside a paragraph become <br>
#             "sane_lists",   # Make lists less surprising
#         ],
#         extension_configs={
#             "codehilite": {
#                 "linenums": False,
#             }
#         }
#     )
#     if html_escape:
#         args["safe_mode"] = "escape"
# 
#     # Additional extensions?
#     if extensions is not None:
#         for ext in extensions:
#             args["extensions"].append(ext)
#     if blacklist is not None:
#         for ext in blacklist:
#             args["extensions"].remove(str(ext))
# 
#     return u'<div class="markdown">{}</div>'.format(
#         markdown.markdown(body, **args)
#     )
# 
# Path: rophako/log.py
# class LogHandler(logging.Handler):
#     def emit(self, record):


from flask import url_for
from rophako.utils import render_markdown
from rophako.log import logger
import time
import re
import hashlib
import rophako.jsondb as JsonDB
    name = name.strip("/") # Remove any surrounding slashes.

    # Get the old page first.
    page = get_page(name)
    if not page:
        # Initialize the page.
        page = dict(
            revisions=[],
        )

    # The new revision to be added.
    rev = dict(
        id=hashlib.md5(str(int(time.time())).encode("utf-8")).hexdigest(),
        time=int(time.time()),
        author=author,
        body=body,
        note=note or "Updated the page.",
    )

    # Updating the history?
    if history:
        page["revisions"].insert(0, rev)
    else:
        # Replacing the original item.
        if len(page["revisions"]):
            page["revisions"][0] = rev
        else:
            page["revisions"].append(rev)

    # Write it.

# Path: rophako/utils.py
# def render_markdown(body, html_escape=True, extensions=None, blacklist=None):
#     """Render a block of Markdown text.
# 
#     This will default to escaping literal HTML characters. Set
#     `html_escape=False` to trust HTML.
# 
#     * extensions should be a set() of extensions to add.
#     * blacklist should be a set() of extensions to blacklist."""
# 
#     args = dict(
#         lazy_ol=False, # If a numbered list starts at e.g. 4, show the <ol> there
#         extensions=[
#             "fenced_code",  # GitHub style code blocks
#             "tables",       # http://michelf.ca/projects/php-markdown/extra/#table
#             "smart_strong", # Handles double__underscore better.
#             "codehilite",   # Code highlighting with Pygment!
#             "nl2br",        # Line breaks inside a paragraph become <br>
#             "sane_lists",   # Make lists less surprising
#         ],
#         extension_configs={
#             "codehilite": {
#                 "linenums": False,
#             }
#         }
#     )
#     if html_escape:
#         args["safe_mode"] = "escape"
# 
#     # Additional extensions?
#     if extensions is not None:
#         for ext in extensions:
#             args["extensions"].append(ext)
#     if blacklist is not None:
#         for ext in blacklist:
#             args["extensions"].remove(str(ext))
# 
#     return u'<div class="markdown">{}</div>'.format(
#         markdown.markdown(body, **args)
#     )
# 
# Path: rophako/log.py
# class LogHandler(logging.Handler):
#     def emit(self, record):


# Path: rophako/model/wiki.py
from flask import url_for
from rophako.utils import render_markdown
from rophako.log import logger
import time
import re
import hashlib
import rophako.jsondb as JsonDB

    name = name.strip("/") # Remove any surrounding slashes.

    # Get the old page first.
    page = get_page(name)
    if not page:
        # Initialize the page.
        page = dict(
            revisions=[],
        )

    # The new revision to be added.
    rev = dict(
        id=hashlib.md5(str(int(time.time())).encode("utf-8")).hexdigest(),
        time=int(time.time()),
        author=author,
        body=body,
        note=note or "Updated the page.",
    )

    # Updating the history?
    if history:
        page["revisions"].insert(0, rev)
    else:
        # Replacing the original item.
        if len(page["revisions"]):
            page["revisions"][0] = rev
        else:
            page["revisions"].append(rev)

    # Write it.

    logger.info("Write to Wiki page {}".format(name))