#NEWLINE# def _assertMarkdown( self , text , html , text_path = None , html_path = None , opts = None , toc_html = None , toc_html_path = None , metadata = None , metadata_path = None ) : #NEWLINE# #INDENT# 'Assert that markdown2.py produces the expected HTML.' #NEWLINE# if ( html is None ) : #NEWLINE# #INDENT# text_path = '<text content>' #NEWLINE# #UNINDENT# if ( html_path is None ) : #NEWLINE# #INDENT# html_path = '<html content>' #NEWLINE# #UNINDENT# if ( opts is None ) : #NEWLINE# #INDENT# opts = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# norm_html = norm_html_from_html ( html ) #NEWLINE# python_html = markdown2 . markdown ( text , ** opts ) #NEWLINE# python_norm_html = norm_html_from_html ( python_html ) #NEWLINE# close_though = '' #NEWLINE# if ( ( python_norm_html != norm_html ) and ( python_norm_html . replace ( '\n' , '' ) == norm_html . replace ( '\n' , '' ) ) ) : #NEWLINE# #INDENT# close_though = ' (close though -- all but EOLs match)' #NEWLINE# #UNINDENT# diff = '' #NEWLINE# if ( python_norm_html != norm_html ) : #NEWLINE# #INDENT# diff = difflib . unified_diff ( norm_html . splitlines ( 1 ) , python_norm_html . splitlines ( 1 ) , html_path , ( 'markdown2 ' + text_path ) ) #NEWLINE# diff = '' . join ( diff ) #NEWLINE# #UNINDENT# errmsg = ( _dedent ( "            markdown2.py didn't produce the expected HTML%s:\n              ---- text (escaping: .=space, \\n=newline) ----\n            %s  ---- Python markdown2.py HTML (escaping: .=space, \\n=newline) ----\n            %s  ---- expected HTML (escaping: .=space, \\n=newline) ----\n            %s  ---- diff ----\n            %s" ) % ( close_though , _display ( text ) , _display ( python_html ) , _display ( html ) , _indent ( diff ) ) ) #NEWLINE# def charreprreplace( exc ) : #NEWLINE# #INDENT# if ( not isinstance ( exc , UnicodeEncodeError ) ) : #NEWLINE# #INDENT# raise TypeError ( ( "don't know how to handle %r" % exc ) ) #NEWLINE# #UNINDENT# if py3 : #NEWLINE# #INDENT# obj_repr = repr ( exc . object [ exc . start : exc . end ] ) [ 1 : ( - 1 ) ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# obj_repr = repr ( exc . object [ exc . start : exc . end ] ) [ 2 : ( - 1 ) ] #NEWLINE# #UNINDENT# return ( unicode ( obj_repr ) , exc . end ) #NEWLINE# #UNINDENT# codecs . register_error ( 'charreprreplace' , charreprreplace ) #NEWLINE# self . assertEqual ( python_norm_html , norm_html , errmsg ) #NEWLINE# if toc_html : #NEWLINE# #INDENT# python_toc_html = python_html . toc_html #NEWLINE# python_norm_toc_html = norm_html_from_html ( python_toc_html ) #NEWLINE# norm_toc_html = norm_html_from_html ( toc_html ) #NEWLINE# diff = '' #NEWLINE# if ( python_norm_toc_html != norm_toc_html ) : #NEWLINE# #INDENT# diff = difflib . unified_diff ( norm_toc_html . splitlines ( 1 ) , python_norm_toc_html . splitlines ( 1 ) , toc_html_path , ( '`markdown2 %s`.toc_html' % text_path ) ) #NEWLINE# diff = '' . join ( diff ) #NEWLINE# #UNINDENT# errmsg = ( _dedent ( "                markdown2.py didn't produce the expected TOC HTML%s:\n                  ---- text (escaping: .=space, \\n=newline) ----\n                %s  ---- Python markdown2.py TOC HTML (escaping: .=space, \\n=newline) ----\n                %s  ---- expected TOC HTML (escaping: .=space, \\n=newline) ----\n                %s  ---- diff ----\n                %s" ) % ( close_though , _display ( text ) , _display ( python_toc_html ) , _display ( toc_html ) , _indent ( diff ) ) ) #NEWLINE# self . assertEqual ( python_norm_toc_html , norm_toc_html , errmsg . encode ( 'ascii' , 'charreprreplace' ) ) #NEWLINE# #UNINDENT# if metadata : #NEWLINE# #INDENT# self . assertEqual ( python_html . metadata , metadata )