1 from StringIO import StringIO
4 from xml.etree.ElementTree import XML # Python 2.5 (and greater?)
6 from elementtree.ElementTree import XML
7 from libbe.restconvert import rest_xml
12 if ch not in ('\r', '\n'):
25 translations = {'\n': '<br />\n', '&': '&', '\x3c': '<',
27 for ch in to_unix(text):
28 if ch == ' ' and first_space is True:
30 first_space = ch in (' ')
32 yield translations[ch]
38 return XML('<div style="font-family: monospace">'+
39 ''.join(soft_text(text)).encode('utf-8')+'</div>')
42 def get_rest_body(rest):
43 xml, warnings = rest_xml(StringIO(rest))
44 return xml.find('{http://www.w3.org/1999/xhtml}body'), warnings
47 def comment_body_xhtml(comment):
48 if comment.content_type == "text/restructured":
49 return get_rest_body(comment.body)[0]
51 return soft_pre(comment.body)
54 def select_among(name, options, default, display_names=None):
55 output = ['<select name="%s">' % name]
56 for option in options:
58 selected = ' selected="selected"'
61 if display_names is None:
64 display_name = display_names.get(option)
68 if display_name is None:
72 value = ' value="%s"' % option
73 output.append("<option%s%s>%s</option>" % (selected, value,
75 output.append("</select>")
76 return XML("".join(output))