@@ -471,18 +471,35 @@ def strip_html(string, keep_tag_content=False):
471
471
472
472
473
473
def prettify (string ):
474
- # turns first letter after ".", "?", "!" into uppercase
475
- def uppercase_after_sign (regex_match ):
474
+ def remove_duplicates (regex_match ):
475
+ return regex_match .group (1 )[0 ]
476
+
477
+ def uppercase_first_letter_after_sign (regex_match ):
476
478
match = regex_match .group (1 )
477
479
return match [:- 1 ] + match [2 ].upper ()
478
480
479
- p = PRETTIFY_RE ['DUPLICATES' ].sub (lambda m : m .group (1 )[0 ], string )
480
- p = PRETTIFY_RE ['RIGHT_SPACE' ].sub (lambda m : m .group (1 ).strip () + ' ' , p )
481
- p = PRETTIFY_RE ['LEFT_SPACE' ].sub (lambda m : ' ' + m .group (1 ).strip (), p )
482
- p = PRETTIFY_RE ['SPACES_AROUND' ].sub (lambda m : ' ' + m .group (1 ).strip () + ' ' , p )
483
- p = PRETTIFY_RE ['SPACES_INSIDE' ].sub (lambda m : m .group (1 ).strip (), p )
484
- p = PRETTIFY_RE ['UPPERCASE_AFTER_SIGN' ].sub (uppercase_after_sign , p )
485
- p = PRETTIFY_RE ['SAXON_GENITIVE' ].sub (lambda m : m .group (1 ).replace (' ' , '' ) + ' ' , p )
481
+ def ensure_right_space_only (regex_match ):
482
+ return regex_match .group (1 ).strip () + ' '
483
+
484
+ def ensure_left_space_only (regex_match ):
485
+ return ' ' + regex_match .group (1 ).strip ()
486
+
487
+ def ensure_spaces_around (regex_match ):
488
+ return ' ' + regex_match .group (1 ).strip () + ' '
489
+
490
+ def remove_internal_spaces (regex_match ):
491
+ return regex_match .group (1 ).strip ()
492
+
493
+ def fix_saxon_genitive (regex_match ):
494
+ return regex_match .group (1 ).replace (' ' , '' ) + ' '
495
+
496
+ p = PRETTIFY_RE ['DUPLICATES' ].sub (remove_duplicates , string )
497
+ p = PRETTIFY_RE ['RIGHT_SPACE' ].sub (ensure_right_space_only , p )
498
+ p = PRETTIFY_RE ['LEFT_SPACE' ].sub (ensure_left_space_only , p )
499
+ p = PRETTIFY_RE ['SPACES_AROUND' ].sub (ensure_spaces_around , p )
500
+ p = PRETTIFY_RE ['SPACES_INSIDE' ].sub (remove_internal_spaces , p )
501
+ p = PRETTIFY_RE ['UPPERCASE_AFTER_SIGN' ].sub (uppercase_first_letter_after_sign , p )
502
+ p = PRETTIFY_RE ['SAXON_GENITIVE' ].sub (fix_saxon_genitive , p )
486
503
p = p .strip ()
487
504
try :
488
505
return p [0 ].capitalize () + p [1 :]
0 commit comments