def render_markdown(md_file_path): """ Renders the markdown file with the given filename """ content = None try: content = open(md_file_path, 'r').read() except: # Some error occurred, log it and return logging.info('Error occurred rendering markdown file at: ' + md_file_path) print 'Rendering failed, see logs for details' return # Setup and submit request params = {'text': content, 'mode': 'markdown'} headers = {'Authorization': 'Basic {:s}'.format(base64.b64encode(auth.AUTH_INFO))} response = requests.post(settings.GITHUB_API_URL + '/markdown', data=json.dumps(params), headers=headers) # Change to .html file md_file_path = md_file_path.replace('.md', '.html') # Remove source directory from write path md_file_path = md_file_path.replace(settings.SOURCE_PATH, './') # Write contents to destination path write_file = open(os.path.join(settings.RENDER_PATH, md_file_path), 'w') # TODO: Replace with template specific to notes template = TEMPLATE_ENV.get_template('note.html') result = template.render(content=response.text) write_file.write(result) # Return path to file created return md_file_path
def make_table_of_contents(rendered): """ Renders the table of contents page """ outfile = open(os.path.join(settings.RENDER_PATH, 'index.html'), 'w') content = '<h1>Table of Contents</h1>' # Start recursive writing of directory tree from current directory content += '<ul id=\'contents-list\'>' content += write_out_directory('.', rendered, './') content += '</ul>' index_template = TEMPLATE_ENV.get_template('index.html'); rendered = index_template.render(content=content) outfile.write(rendered); outfile.close()