def _tag_line(line): line = to_unicode(line) if line and xml_lang: tag = u''.join([ unichr( uniord(u'\N{TAG LATIN CAPITAL LETTER A}') - uniord(u'A') + uniord(ch)) for ch in to_unicode(_canon_lang(xml_lang)) ]) line = u'\N{LANGUAGE TAG}' + tag + line + u'\N{LANGUAGE TAG}\N{CANCEL TAG}' return line
def embed_xhtml(xhtml, xml_lang=None, xhtml_dir='ltr'): ''' Prepare a span of XHTML text for embedding in arbitrary other XHTML text. Each line of the span is wrapped in language tags corresponding to xml_lang (if xml_lang is neither empty nor None) and a Unicode bidirectional embedding of the xhtml_dir direction (default is "ltr" for left-to-right; "rtl" for right-to-left is also allowed.) An empty string or None is simply returned. The result is returned as a UTF-8 string. ''' if xhtml is None: return None if not xhtml: return to_utf8(xhtml) xhtml = to_utf8(xhtml) assert xhtml_dir in ('ltr', 'rtl') return to_utf8('<span dir="%s"%s>%s</span>' % (to_utf8(xhtml_dir), (xml_lang and (' xml:lang="%s"' % _canon_lang(xml_lang)) or ''), xhtml))
def embed_xhtml(xhtml, xml_lang = None, xhtml_dir = 'ltr'): ''' Prepare a span of XHTML text for embedding in arbitrary other XHTML text. Each line of the span is wrapped in language tags corresponding to xml_lang (if xml_lang is neither empty nor None) and a Unicode bidirectional embedding of the xhtml_dir direction (default is "ltr" for left-to-right; "rtl" for right-to-left is also allowed.) An empty string or None is simply returned. The result is returned as a UTF-8 string. ''' if xhtml is None: return None if not xhtml: return to_utf8(xhtml) xhtml = to_utf8(xhtml) assert xhtml_dir in ('ltr', 'rtl') return to_utf8('<span dir="%s"%s>%s</span>' % ( to_utf8(xhtml_dir), (xml_lang and (' xml:lang="%s"' % _canon_lang(xml_lang)) or ''), xhtml))
def _tag_line(line): line = to_unicode(line) if line and xml_lang: tag = u''.join([ unichr(uniord(u'\N{TAG LATIN CAPITAL LETTER A}') - uniord(u'A') + uniord(ch)) for ch in to_unicode(_canon_lang(xml_lang)) ]) line = u'\N{LANGUAGE TAG}' + tag + line + u'\N{LANGUAGE TAG}\N{CANCEL TAG}' return line