Exemplo n.º 1
0
def main(source_dir, output_dir):
    # Directories to copy, of the form [(<source_path>, <output_path>), ...]
    to_copy = [('style', 'style'), ('images', 'images'), ('scripts', 'assets')] 

    # Directories used to build the page
    template_dir = os.path.join(source_dir, 'templates')
    page_dir = os.path.join(source_dir, 'pages')

    # Copy assets to output
    for src, dst in to_copy:
        src = os.path.join(source_dir, src)
        dst = os.path.join(output_dir, dst)
        copytree(src, dst)

    # Render pages
    env = Environment(loader=FileSystemLoader(template_dir), trim_blocks=True)
    template = env.get_template('page_template.html')
    for src in gen_find('*.md', page_dir):
        # Get the file's base name
        filename = os.path.basename(src)
        base, _ = os.path.splitext(filename)
        dst = os.path.join(output_dir, base + '.html')

        # Render the page body with customized markdown
        body = render_markdown(open(src, 'r').read())
        rendered = template.render(body=body, 
                                   mathjax_url=mathjax_url, 
                                   livejs_url=livejs_url)

        # Progress update
        print(src, ' ---> ', dst)
        with open(dst, 'w') as f:
            f.write(rendered)
Exemplo n.º 2
0
import sys
from render_markdown import render_markdown

# line = \
# """
# Let $G_{t}^{n}$ (sometimes written as $G_{t}^{(k)}$) denote the n-step return 
# following time step $t$. 
# """

# print(render_markdown(line))


if __name__ == "__main__":
    for path in sys.argv[1:]:
        print(path)
        print(render_markdown(open(path, 'r').read()))