210 # HTML generation helper functions ############################################ |
210 # HTML generation helper functions ############################################ |
211 |
211 |
212 HTML4_EMPTY_TAGS = frozenset(('base', 'meta', 'link', 'hr', 'br', 'param', |
212 HTML4_EMPTY_TAGS = frozenset(('base', 'meta', 'link', 'hr', 'br', 'param', |
213 'img', 'area', 'input', 'col')) |
213 'img', 'area', 'input', 'col')) |
214 |
214 |
|
215 def sgml_attributes(attrs): |
|
216 return u' '.join(u'%s="%s"' % (attr, xml_escape(unicode(value))) |
|
217 for attr, value in sorted(attrs.items()) |
|
218 if value is not None) |
|
219 |
215 def simple_sgml_tag(tag, content=None, escapecontent=True, **attrs): |
220 def simple_sgml_tag(tag, content=None, escapecontent=True, **attrs): |
216 """generation of a simple sgml tag (eg without children tags) easier |
221 """generation of a simple sgml tag (eg without children tags) easier |
217 |
222 |
218 content and attri butes will be escaped |
223 content and attri butes will be escaped |
219 """ |
224 """ |
221 if attrs: |
226 if attrs: |
222 try: |
227 try: |
223 attrs['class'] = attrs.pop('klass') |
228 attrs['class'] = attrs.pop('klass') |
224 except KeyError: |
229 except KeyError: |
225 pass |
230 pass |
226 value += u' ' + u' '.join(u'%s="%s"' % (attr, xml_escape(unicode(value))) |
231 value += u' ' + sgml_attributes(attrs) |
227 for attr, value in sorted(attrs.items()) |
|
228 if value is not None) |
|
229 if content: |
232 if content: |
230 if escapecontent: |
233 if escapecontent: |
231 content = xml_escape(unicode(content)) |
234 content = xml_escape(unicode(content)) |
232 value += u'>%s</%s>' % (content, tag) |
235 value += u'>%s</%s>' % (content, tag) |
233 else: |
236 else: |