Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_HTML():
from clld.web.util.htmllib import HTML
assert 'class' in HTML.div(HTML.cdata(), class_='abc')
assert str(HTML.a()) == '<a></a>'
def alt_translation(sentence):
res = ''
if sentence.jsondata.get('alt_translation'):
text = sentence.jsondata['alt_translation']
name = ''
if ALT_TRANSLATION_LANGUAGE_PATTERN.match(text):
name, text = [t.strip() for t in text.split(':', 1)]
name = HTML.span(name + ': ')
res = HTML.div(name, HTML.span(text, class_='translation'))
return res
name = HTML.span(name + ': ')
res = HTML.div(name, HTML.span(text, class_='translation'))
return res
units = []
if sentence.analyzed and sentence.gloss:
analyzed = sentence.analyzed
glossed = sentence.gloss
for morpheme, gloss in zip(analyzed.split('\t'), glossed.split('\t')):
units.append(HTML.div(
HTML.div(morpheme, class_='morpheme'),
HTML.div(*gloss_with_tooltip(gloss), **{'class': 'gloss'}),
class_='gloss-unit'))
return HTML.div(
HTML.div(
HTML.div(
HTML.div(sentence.original_script, class_='original-script')
if sentence.original_script else '',
HTML.div(literal(sentence.markup_text or sentence.name),
class_='object-language'),
HTML.div(*units, **{'class': 'gloss-box'}) if units else '',
HTML.div(sentence.description, class_='translation')
if sentence.description else '',
alt_translation(sentence),
class_='body',
),
class_="sentence",
),
class_="sentence-wrapper",
)
res = HTML.div(name, HTML.span(text, class_='translation'))
return res
units = []
if sentence.analyzed and sentence.gloss:
analyzed = sentence.analyzed
glossed = sentence.gloss
for morpheme, gloss in zip(analyzed.split('\t'), glossed.split('\t')):
units.append(HTML.div(
HTML.div(morpheme, class_='morpheme'),
HTML.div(*gloss_with_tooltip(gloss), **{'class': 'gloss'}),
class_='gloss-unit'))
return HTML.div(
HTML.div(
HTML.div(
HTML.div(sentence.original_script, class_='original-script')
if sentence.original_script else '',
HTML.div(literal(sentence.markup_text or sentence.name),
class_='object-language'),
HTML.div(*units, **{'class': 'gloss-box'}) if units else '',
HTML.div(sentence.description, class_='translation')
if sentence.description else '',
alt_translation(sentence),
class_='body',
),
class_="sentence",
),
class_="sentence-wrapper",
)
def infobox(*content):
return HTML.div(
HTML.button(
'\xd7', **{'type': "button", 'class': "close", 'data-dismiss': "alert"}),
*content,
**{'class': "alert alert-success"})
def icons(req, param):
"""Create an HTML snippet listing available icons.
:param req: current request
:param param: parameter name
:return: HTML element
"""
iconlist = req.registry.queryUtility(interfaces.IIconList)
td = lambda icon: HTML.td(
marker_img(icon.url(req)),
onclick='CLLD.reload({"%s": "%s"})' % (param, icon.name))
rows = [
HTML.tr(*map(td, icons)) for c, icons in
groupby(sorted(iconlist, key=lambda i: i.name[1:]), lambda i: i.name[1:])]
return HTML.div(
HTML.table(
HTML.tbody(*rows),
class_="table table-condensed"
),
button('Close', **{'data-dismiss': 'clickover'}))
"""Create an HTML snippet listing available icons.
:param req: current request
:param param: parameter name
:return: HTML element
"""
iconlist = req.registry.queryUtility(interfaces.IIconList)
def td(icon):
return HTML.td(
marker_img(icon.url(req)),
onclick='CLLD.reload({"%s": "%s"})' % (param, icon.name))
rows = [
HTML.tr(*map(td, icons)) for c, icons in
groupby(sorted(iconlist, key=lambda i: i.name[1:]), lambda i: i.name[1:])]
return HTML.div(
HTML.table(
HTML.tbody(*rows),
class_="table table-condensed"
),
button('Close', **{'data-dismiss': 'clickover'}))
def rendered_sentence(sentence, abbrs=None, fmt='long'):
"""Format a sentence as HTML."""
if sentence.xhtml:
return HTML.div(
HTML.div(Markup(sentence.xhtml), class_='body'), class_="sentence")
if abbrs is None:
q = DBSession.query(models.GlossAbbreviation).filter(
or_(models.GlossAbbreviation.language_pk == sentence.language_pk,
models.GlossAbbreviation.language_pk == None)
)
abbrs = dict((g.id, g.name) for g in q)
def gloss_with_tooltip(gloss):
person_map = {
'1': 'first person',
'2': 'second person',
'3': 'third person',
}
res = []