def worksheet_file(path): # Create a live Sage worksheet from the given path. if not os.path.exists(path): return current_app.message(_('Document does not exist.'), username=g.username) doc_page_html = open(path).read() from sagenb.notebook.docHTMLProcessor import SphinxHTMLProcessor doc_page = SphinxHTMLProcessor().process_doc_html(doc_page_html) title = (extract_title(doc_page_html).replace('—', '--') or 'Live Sage Documentation') W = doc_worksheet() W.edit_save(doc_page) W.set_system('sage') W.set_name(title) W.save() W.quit() # FIXME: For some reason, an extra cell gets added so we # remove it here. W.cell_list().pop() return g.notebook.html(worksheet_filename=W.filename(), username=g.username)
def worksheet_file(path): # Create a live Sage worksheet out of path and render it. if not os.path.exists(path): return current_app.message('Document does not exist.') doc_page_html = open(path).read() from sagenb.notebook.docHTMLProcessor import SphinxHTMLProcessor doc_page = SphinxHTMLProcessor().process_doc_html(doc_page_html) title = extract_title(doc_page_html).replace('—', '--') doc_page = title + '\nsystem:sage\n\n' + doc_page W = doc_worksheet() W.edit_save(doc_page) #FIXME: For some reason, an extra cell gets added #so we remove it here. cells = W.cell_list() cells.pop() return g.notebook.html(worksheet_filename=W.filename(), username=g.username)