def compile_presentation(note, outdir): n = note # Create output directory if necessary. outdir = path.join(outdir, n.title) if not path.exists(outdir): os.makedirs(outdir) # Copy over any images. for img in n.images: img_path = path.join(outdir, img) img_dir = path.dirname(img_path) if not path.exists(img_dir): os.makedirs(img_dir) shutil.copy(path.join(n.notebook.path.abs, img), img_path) # Render the presentation. html = md2html.compile_markdown(n.content) content = templ.render(html=html) # Save it. with open(path.join(outdir, n.title) + '.html', 'w') as out: out.write(content.encode('utf-8'))
def n(path): path = urllib.unquote(path) note = Note(path) if os.path.isfile(note.path.abs): if request.method == 'PUT': text = request.form['text'] note.write(text) raw = note.content if note.ext == '.md': content = md2html.compile_markdown(raw) else: content = raw return jsonify({ 'title': note.title, 'html': content, 'path': path, 'raw': raw, 'nburl': quote(note.notebook.path.rel) }) else: return 'Not found.', 404
def compile_note(note, outdir, templ): templ = env.get_template('{}.html'.format(templ)) # create output directory if necessary outdir = os.path.join(outdir, note.title) if not os.path.exists(outdir): os.makedirs(outdir) # copy over any images for img in note.images: img_path = os.path.join(outdir, img) img_dir = os.path.dirname(img_path) if not os.path.exists(img_dir): os.makedirs(img_dir) shutil.copy(os.path.join(note.notebook.path.abs, img), img_path) # render the presentation html = md2html.compile_markdown(note.content) content = templ.render(html=html) # save it with open(os.path.join(outdir, note.title) + '.html', 'w') as out: out.write(content)
def view_note(path): """returns the note at the specified path""" path = parse.unquote(path) note = Note(path) if os.path.isfile(note.path.abs): if note.ext == '.md': content = md2html.compile_markdown(note.content) else: content = note.content return render_template('note.html', note={ 'title': note.title, 'html': content, 'path': path, }, breadcrumbs=breadcrumbs(path)) else: return 'Not found.', 404