@@ -142,22 +142,26 @@ def is_nested_node(el):
142142 return text
143143
144144 def process_text (self , el ):
145- text = six .text_type (el )
145+ text = six .text_type (el ) or ''
146146
147147 # dont remove any whitespace when handling pre or code in pre
148- if (el .parent .name == 'pre'
149- or (el .parent .name == 'code' and el .parent .parent .name == 'pre' )):
150- return escape (text or '' )
148+ if not (el .parent .name == 'pre'
149+ or (el .parent .name == 'code'
150+ and el .parent .parent .name == 'pre' )):
151+ text = whitespace_re .sub (' ' , text )
151152
152- cleaned_text = escape (whitespace_re .sub (' ' , text or '' ))
153+ if el .parent .name != 'code' :
154+ text = escape (text )
153155
154156 # remove trailing whitespaces if any of the following condition is true:
155157 # - current text node is the last node in li
156158 # - current text node is followed by an embedded list
157- if el .parent .name == 'li' and (not el .next_sibling or el .next_sibling .name in ['ul' , 'ol' ]):
158- return cleaned_text .rstrip ()
159+ if (el .parent .name == 'li'
160+ and (not el .next_sibling
161+ or el .next_sibling .name in ['ul' , 'ol' ])):
162+ text = text .rstrip ()
159163
160- return cleaned_text
164+ return text
161165
162166 def __getattr__ (self , attr ):
163167 # Handle headings
0 commit comments