Ejemplo n.º 1
0
def insert_markup(elem, uid, vlam, markup, interactive_type):
    '''clears an element and inserts the new markup inside it'''
    elem.clear()
    elem.tag = "div"
    elem.attrib["id"] = "div_"+uid
    elem.attrib['class'] = interactive_type # 'editor', 'doctest', 'interpreter'
    if not "no_pre" in vlam:
        try:
            new_div = Element("div")
            new_div.append(markup)
            new_div.attrib['class'] = 'sample_python_code'
            elem.insert(0, new_div)
        except AssertionError:  # this should never happen
            elem.insert(0, Element("br"))
            bold = Element("b")
            span = Element("span")
            span.text = "AssertionError from ElementTree"
            bold.append(span)
            elem.insert(1, bold)
Ejemplo n.º 2
0
def insert_markup(elem, uid, vlam, markup, interactive_type):
    '''clears an element and inserts the new markup inside it'''
    elem.clear()
    elem.tag = "div"
    elem.attrib["id"] = "div_" + uid
    elem.attrib[
        'class'] = interactive_type  # 'editor', 'doctest', 'interpreter'
    if not "no_pre" in vlam:
        try:
            new_div = Element("div")
            new_div.append(markup)
            new_div.attrib['class'] = 'sample_python_code'
            elem.insert(0, new_div)
        except AssertionError:  # this should never happen
            elem.insert(0, Element("br"))
            bold = Element("b")
            span = Element("span")
            span.text = "AssertionError from ElementTree"
            bold.append(span)
            elem.insert(1, bold)
Ejemplo n.º 3
0
def create_show_vlam(page, elem, vlam):
    '''Creates a <code> element showing the complete vlam options
    used, as well as the element type.'''
    if 'show_vlam' not in vlam:
        return None
    cssclass = config[page.username]['style']
    attributes = ' title="%s"' % vlam
    for attr in elem.attrib:
        if attr != 'title':
            attributes += ' %s="%s"' % (attr, elem.attrib[attr])
    elem_info = '<%s%s> ... </%s>' % (elem.tag, attributes, elem.tag)
    styled_elem_info = _style(elem_info, 'html', cssclass)
    show_vlam = fromstring(styled_elem_info)
    show_vlam.tag = 'code'
    show_vlam.attrib['class'] = CRUNCHY_PYGMENTS
    display = Element('h3')
    display.attrib['class'] = "show_vlam"
    display.text = "VLAM = "
    display.append(show_vlam)
    return display
Ejemplo n.º 4
0
def create_show_vlam(page, elem, vlam):
    '''Creates a <code> element showing the complete vlam options
    used, as well as the element type.'''
    if 'show_vlam' not in vlam:
        return None
    cssclass = config[page.username]['style']
    attributes = ' title="%s"' % vlam
    for attr in elem.attrib:
        if attr != 'title':
            attributes += ' %s="%s"' % (attr, elem.attrib[attr])
    elem_info = '<%s%s> ... </%s>' % (elem.tag, attributes, elem.tag)
    styled_elem_info = _style(elem_info, 'html', cssclass)
    show_vlam = fromstring(styled_elem_info)
    show_vlam.tag = 'code'
    show_vlam.attrib['class'] = CRUNCHY_PYGMENTS
    display = Element('h3')
    display.attrib['class'] = "show_vlam"
    display.text = "VLAM = "
    display.append(show_vlam)
    return display
Ejemplo n.º 5
0
def wrap_in_div(elem, uid, vlam, element_type, show_vlam):
    '''wraps a styled code inside a div'''
    elem_copy = copy.deepcopy(elem)
    elem.clear()
    elem.text = ''
    elem.tag = "div"
    elem.attrib["id"] = "div_" + uid
    username = names[uid.split("_")[0]]
    # element_type = 'editor', 'doctest', etc.
    elem.attrib['class'] = element_type + " " + config[username]['style']
    if not "no_pre" in vlam:
        try:
            elem.append(elem_copy)
        except AssertionError:  # this should never happen
            elem.insert(0, Element("br"))
            bold = Element("b")
            span = Element("span")
            span.text = "AssertionError from ElementTree"
            bold.append(span)
            elem.insert(1, bold)
            return
    if show_vlam is not None:
        elem.insert(0, show_vlam)
Ejemplo n.º 6
0
def wrap_in_div(elem, uid, vlam, element_type, show_vlam):
    '''wraps a styled code inside a div'''
    elem_copy = copy.deepcopy(elem)
    elem.clear()
    elem.text = ''
    elem.tag = "div"
    elem.attrib["id"] = "div_"+uid
    username = names[uid.split("_")[0]]
    # element_type = 'editor', 'doctest', etc.
    elem.attrib['class'] = element_type + " " + config[username]['style']
    if not "no_pre" in vlam:
        try:
            elem.append(elem_copy)
        except AssertionError:  # this should never happen
            elem.insert(0, Element("br"))
            bold = Element("b")
            span = Element("span")
            span.text = "AssertionError from ElementTree"
            bold.append(span)
            elem.insert(1, bold)
            return
    if show_vlam is not None:
        elem.insert(0, show_vlam)