def _hyperlinks_to_xhtml(dinotext): xhtml = [] offset = 0 while offset < len(dinotext): match = hyperlink_re.search(dinotext[offset:]) if match: xhtml.append(text_to_xhtml(dinotext[offset:][:match.start()])) offset += match.start() + len(match.group(0)) hyperlink_type = _hyperlink_types[match.group('Code')] xhtml.append( ''' <a href="%(URI)s">%(Text)s</a> '''.strip() % { 'URI': xml_escape( _hyperlink_to_uri( match.group('Code'), xhtml_to_text( _re_italicize( text_to_xhtml(match.group('Text')))))), 'Text': text_to_xhtml(match.group('Text')), }) pass else: xhtml.append(text_to_xhtml(dinotext[offset:])) offset = len(dinotext) pass return ''.join(xhtml)
def _hyperlinks_to_xhtml(dinotext): xhtml = [] offset = 0 while offset < len(dinotext): match = hyperlink_re.search(dinotext[offset:]) if match: xhtml.append(text_to_xhtml(dinotext[offset:][:match.start()])) offset += match.start() + len(match.group(0)) hyperlink_type = _hyperlink_types[match.group('Code')] xhtml.append( ''' <a href="%(URI)s">%(Text)s</a> '''.strip() % { 'URI': xml_escape(_hyperlink_to_uri(match.group('Code'), xhtml_to_text(_re_italicize(text_to_xhtml(match.group('Text')))))), 'Text': text_to_xhtml(match.group('Text')), } ) pass else: xhtml.append(text_to_xhtml(dinotext[offset:])) offset = len(dinotext) pass return ''.join(xhtml)
def text_to_xhtml(value): ''' Converts plain text to an XHTML fragment. Converts C1 control characters as if they were Windows-1252 or MacRoman codepoints rather than ISO-8859-1 codepoints. Converts characters not allowed in XHTML to the Unicode replacement character. ''' if value is not None: value = to_unicode(xml_escape(demoronize(value))) return canon_xhtml(value)