def run(): src = editor.value if storage: storage["markdown_src"] = src mk, scripts = markdown.mark(src) doc['console'].html = mk
def run(): src = editor.value if storage: storage["markdown_src"]=src mk,scripts = markdown.mark(src) doc['console'].html = mk
def read_pages(presentation_file): lines = open(presentation_file).readlines() footer_text = None pages = [] pls = [] config_data = None in_header = True for L in lines: if L.startswith("!SLIDE"): if pls: if in_header: config_data = json.loads(''.join(pls)) else: pages.append('\n'.join(pls)) pls = [] in_header = False else: pls.append(L) if in_header: config_data = json.loads(''.join(pls)) else: pages.append('\n'.join(pls)) page_datas = [] for page in pages: mk, scripts = markdown.mark(page) page_datas.append((mk, scripts)) return page_datas, config_data
def process_md(index, src, position): html, scripts = markdown.mark(src) html = index.replace('<content>', html) html = html.replace('<prefix>', '/'.join(['..'] * (position + 1))) if position == 1: html = html.replace('class="navig" href="', 'class="navig" href="../') if scripts: html = html.replace( '<scripts>', '<script type="text/python">%s\n</script>' % '\n'.join(scripts)) return html
def make_html(self): res = ('<!doctype html>\n<html>\n<head>\n<meta charset="utf-8">\n' + style + '</head>\n<body>') for num, page in enumerate(self.pages): html = '<div class="page">\n' + markdown.mark(page)[0] + "\n</div>" html += '\n<p style="page-break-after:always;"></p>' res += html """ for elt in zone.get(selector='.python'): src = elt.text.strip() width = max(len(line) for line in src.split('\n')) width = max(width, 30) # replace element content by highlighted code elt.html = highlight.highlight(src).html elt.style.width = '%sem' %int(0.7*width) elt.bind('click', run_code) for elt in zone.get(selector='.python-console'): src = elt.text.strip() lines = src.split('\n') result = '' py = '' py_starts = [] for line in lines: if line.startswith('>>>') or line.startswith('...'): py += line[4:]+'\n' py_starts.append('<span class="python-prompt">{}</span>'.format(line[:3])) else: if py: colored = highlight.highlight(py).html colored_lines = colored.split('\n') if result: result += '\n' result += '\n'.join(start+' '+line for (start, line) in zip(py_starts, colored_lines)) py = '' py_starts = [] result += '\n' + line if py: colored = highlight.highlight(py).html colored_lines = colored.split('\n') if result: result += '\n' result += '\n'.join(start+' '+line for (start, line) in zip(py_starts, colored_lines)) py = '' py_starts = [] elt.html = result """ return res + '</body>\n</html>'
def show_page(slideshow, zone, page_num): # if table of contents is not empty, add it if slideshow.contents: toc = html.SELECT(name="toc") toc.bind( 'change', lambda ev: show_page( slideshow, zone, int(ev.target.options[ev.target.selectedIndex].value))) for content in slideshow.contents: toc <= html.OPTION( content[0], value=content[1], selected=page_num >= content[1]) slideshow.page_num = int(page_num) # store page num in a cookie document.cookie = "page={}".format(page_num) zone.clear() body = html.DIV() body.html = markdown.mark(slideshow.pages[page_num])[0] if slideshow.contents: body = html.DIV(toc + body) footer = html.DIV(Id="footer") if slideshow.title: footer <= html.DIV(slideshow.title, style=dict(display='inline')) if slideshow.show_page_num: footer <= html.SPAN(' (%s/%s)' % (page_num + 1, len(slideshow.pages)), style=dict(display='inline')) timeline = html.DIV(Id='timeline') tl_pos = html.DIV(Id='tl_pos') timeline <= tl_pos timeline.bind('click', lambda ev: move_to(ev, slideshow, zone)) tl_pos.bind('click', click_on_tl_pos) zone <= body + footer + timeline wh = window.innerHeight footer.style.top = "{}px".format(int(wh * 0.9)) timeline.style.top = "{}px".format(int(wh * 0.85)) tl_pos.style.left = '%spx' % (timeline.width * page_num / len(slideshow.pages)) document["cours"].style.minHeight = "{}px".format(int(wh * 0.8)) for elt in zone.get(selector='.python'): src = elt.text.strip() width = max(len(line) for line in src.split('\n')) width = max(width, 30) # replace element content by highlighted code elt.html = highlight.highlight(src).html elt.style.width = '%sem' % int(0.7 * width) elt.bind('click', run_code)
index = open(os.path.join(md_doc_path,lang,'index_static.html'), 'rb').read() index = index.decode('utf-8') for path in dest_paths: if not os.path.exists(path): os.mkdir(path) print('static doc %s' %lang) for i, (src_path, dest_path) in enumerate(zip([os.path.join(md_doc_path, lang), os.path.join(md_doc_path,lang,'cookbook')], dest_paths)): for filename in os.listdir(src_path): ext = os.path.splitext(filename)[1] if ext=='.md': src = open(os.path.join(src_path, filename), 'rb').read() src = src.decode('utf-8') html, scripts = markdown.mark(src) out = open(os.path.join(dest_path,filename[:-3]+'.html'), 'wb') html = index.replace('<content>',html) html = html.replace('<prefix>','/'.join(['..']*(i+1))) if i==1: html = html.replace('class="navig" href="', 'class="navig" href="../') if scripts: script_content = "\n".join( f'<script type="text/python">{script}\n</script>' for script in scripts) html = html.replace('<scripts>', script_content) out.write(html.encode('utf-8')) out.close() elif ext=='.txt': shutil.copy(os.path.join(src_path, filename),
index = open(os.path.join(md_doc_path,lang,'index_static.html'), 'rb').read() index = index.decode('utf-8') for path in dest_paths: if not os.path.exists(path): os.mkdir(path) print('static doc %s' %lang) for i, (src_path, dest_path) in enumerate(zip([os.path.join(md_doc_path, lang), os.path.join(md_doc_path,lang,'cookbook')], dest_paths)): for filename in os.listdir(src_path): ext = os.path.splitext(filename)[1] if ext=='.md': src = open(os.path.join(src_path, filename), 'rb').read() src = src.decode('utf-8') html, scripts = markdown.mark(src) out = open(os.path.join(dest_path,filename[:-3]+'.html'), 'wb') html = index.replace('<content>',html) html = html.replace('<prefix>','/'.join(['..']*(i+1))) if i==1: html = html.replace('class="navig" href="', 'class="navig" href="../') if scripts: html = html.replace('<scripts>', '<script type="text/python">%s\n</script>' %'\n'.join(scripts)) out.write(html.encode('utf-8')) out.close() elif ext=='.txt': shutil.copy(os.path.join(src_path, filename), os.path.join(dest_path, filename)) elif os.path.isdir(os.path.join(src_path,filename)) \
def show_page(slideshow, zone, page_num): # if table of contents is not empty, add it if slideshow.contents: toc = html.SELECT(name="toc") toc.bind('change', lambda ev: show_page(slideshow, zone, int(ev.target.options[ev.target.selectedIndex].value))) for content in slideshow.contents: toc <= html.OPTION(content[0], value=content[1], selected=page_num>=content[1]) slideshow.page_num = int(page_num) # store page num in a cookie document.cookie = "page={}".format(page_num) zone.clear() body = html.DIV() body.html = markdown.mark(slideshow.pages[page_num])[0] if slideshow.contents: body = html.DIV(toc + body) footer = html.DIV(Id="footer") if slideshow.title: footer <= html.DIV(slideshow.title,style=dict(display='inline')) if slideshow.show_page_num: footer <= html.SPAN(' (%s/%s)' %(page_num+1, len(slideshow.pages)), style=dict(display='inline')) timeline = html.DIV(Id='timeline') tl_pos = html.DIV(Id='tl_pos') timeline <= tl_pos timeline.bind('click', lambda ev:move_to(ev, slideshow, zone)) tl_pos.bind('click', click_on_tl_pos) zone <= body + footer +timeline wh = window.innerHeight footer.style.top = "{}px".format(int(wh * 0.9)) timeline.style.top = "{}px".format(int(wh * 0.85)) tl_pos.style.left = '%spx' %(timeline.width*page_num/len(slideshow.pages)) document["cours"].style.minHeight = "{}px".format(int(wh * 0.8)) for elt in zone.get(selector='.python'): src = elt.text.strip() width = max(len(line) for line in src.split('\n')) width = max(width, 30) # replace element content by highlighted code elt.html = highlight.highlight(src).html elt.style.width = '%sem' %int(0.7*width) elt.bind('click', run_code) for elt in zone.get(selector='.python-console'): src = elt.text.strip() lines = src.split('\n') result = '' py = '' py_starts = [] for line in lines: if line.startswith('>>>') or line.startswith('...'): py += line[4:]+'\n' py_starts.append('<span class="python-prompt">{}</span>'.format(line[:3])) else: if py: colored = highlight.highlight(py).html colored_lines = colored.split('\n') if result: result += '\n' result += '\n'.join(start+' '+line for (start, line) in zip(py_starts, colored_lines)) py = '' py_starts = [] result += '\n' + line if py: colored = highlight.highlight(py).html colored_lines = colored.split('\n') if result: result += '\n' result += '\n'.join(start+' '+line for (start, line) in zip(py_starts, colored_lines)) py = '' py_starts = [] elt.html = result
def show_page(slideshow, zone, page_num): # if table of contents is not empty, add it if slideshow.contents: toc = html.SELECT(name="toc") toc.bind('change', lambda ev: show_page(slideshow, zone, int(ev.target.options[ev.target.selectedIndex].value))) for content in slideshow.contents: toc <= html.OPTION(content[0], value=content[1], selected=page_num>=content[1]) slideshow.page_num = int(page_num) # store page num in a cookie document.cookie = "page={}".format(page_num) zone.clear() body = html.DIV() body.html = markdown.mark(slideshow.pages[page_num])[0] wh = window.innerHeight fontSize = int(18 * window.innerHeight / 800) body.style.fontSize = "{}px".format(fontSize) if slideshow.contents: body = html.DIV(toc + body) footer = html.DIV(Id="footer") footer.style.fontSize = "{}px".format(fontSize) if slideshow.title: footer <= html.DIV(slideshow.title,style=dict(display='inline')) if slideshow.show_page_num: footer <= html.SPAN(' (%s/%s)' %(page_num+1, len(slideshow.pages)), style=dict(display='inline')) timeline = html.DIV(Id='timeline') timeline.style.height = "{}px".format(int(fontSize/2)) tl_pos = html.DIV(Id='tl_pos') timeline <= tl_pos timeline.bind('click', lambda ev:move_to(ev, slideshow, zone)) tl_pos.bind('click', click_on_tl_pos) zone <= body + footer + timeline wh = window.innerHeight tl_pos.style.left = '%spx' %(timeline.width*page_num/len(slideshow.pages)) document["cours"].style.minHeight = "{}px".format(int(wh * 0.9)) for elt in zone.get(selector='.python'): src = elt.text.strip() width = max(len(line) for line in src.split('\n')) width = max(width, 30) # replace element content by highlighted code elt.html = highlight.highlight(src).html elt.style.width = '%sem' %int(0.7*width) elt.bind('click', run_code) for elt in zone.get(selector='.python-console'): src = elt.text.strip() lines = src.split('\n') result = '' py = '' py_starts = [] for line in lines: if line.startswith('>>>') or line.startswith('...'): py += line[4:]+'\n' py_starts.append('<span class="python-prompt">{}</span>'.format(line[:3])) else: if py: colored = highlight.highlight(py).html colored_lines = colored.split('\n') if result: result += '\n' result += '\n'.join(start+' '+line for (start, line) in zip(py_starts, colored_lines)) py = '' py_starts = [] else: line = escape(line) result += '\n' + line if py: colored = highlight.highlight(py).html colored_lines = colored.split('\n') if result: result += '\n' result += '\n'.join(start+' '+line for (start, line) in zip(py_starts, colored_lines)) py = '' py_starts = [] elt.html = result