示例#1
0
def show_source(text):
    shown = document.select(".show_source")
    if not shown:
        top = btn.offsetTop + btn.offsetHeight
    else:
        top = max(elt.offsetTop + elt.offsetHeight for elt in shown)

    top += int(0.5 * btn.offsetHeight)

    div = html.DIV(style=div_style, Class="show_source")
    indent = None
    lines = text.split("\n")
    for line in lines:
        if line.strip():
            _indent = len(line) - len(line.lstrip())
            if indent is None:
                indent = _indent
                break
    if indent:
        text = "\n".join(line[indent:] for line in lines)

    div <= highlight.highlight(text)
    document <= div
    div.top = top
    div.left = max(int(width / 2),
        width - div.offsetWidth - int(0.02 * width))
示例#2
0
def show_source(text):
    shown = document.select(".show_source")
    print(shown)
    if not shown:
        top = btn.offsetTop + btn.offsetHeight
    else:
        top = max(elt.offsetTop + elt.offsetHeight for elt in shown)

    top += int(0.5 * btn.offsetHeight)

    div = html.DIV(style=div_style, Class="show_source")
    indent = None
    lines = text.split("\n")
    for line in lines:
        if line.strip():
            _indent = len(line) - len(line.lstrip())
            if indent is None:
                indent = _indent
                break
    if indent:
        text = "\n".join(line[indent:] for line in lines)

    div <= highlight.highlight(text)
    document <= div
    div.top = top
    div.left = max(int(width / 2),
        width - div.offsetWidth - int(0.02 * width))
示例#3
0
def syntax_highlight(evt, elt):
    global is_highlighted
    if not is_highlighted:
        colored = highlight.highlight(editor.text)
        editor.html = colored.html
    else:
        editor.html = editor.text
    is_highlighted = not is_highlighted
示例#4
0
def show_source(text):
    div = html.DIV(style=div_style, Class="show_source")
    indent = None
    lines = text.split("\n")
    for line in lines:
        if line.strip():
            _indent = len(line) - len(line.lstrip())
            if indent is None:
                indent = _indent
                break
    if indent:
        text = "\n".join(line[indent:] for line in lines)

    div <= highlight.highlight(text)
    document <= div
    div.left = max(int(width / 2), width - div.offsetWidth - int(0.02 * width))
示例#5
0
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])

    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
    tw = window.getComputedStyle(timeline).width
    tw = round(float(tw[:-2]))
    tl_pos.style.left = '%spx' % (tw * page_num / len(slideshow.pages))

    for elt in zone.get(selector='.python'):
        src = elt.text.strip()
        width = max(len(line) for line in src.split('\n'))
        # replace element content by highlighted code
        elt.html = highlight.highlight(src).html
        elt.style.width = '%sem' % int(0.7 * width)
示例#6
0
from browser import highlight

src = """from browser import document, alert"""

assert highlight.highlight(src).html == \
    '<span class="python-keyword">from</span> browser ' \
    '<span class="python-keyword">import</span> document, alert'

print('all tests ok...')
示例#7
0
def syntax_highlight(evt, elt):
    colored = highlight.highlight(editor.text)
    editor.html = colored.html