@@ -87,27 +87,27 @@ def __wptexturize_setup(self):
87
87
88
88
dynamic = []
89
89
if "'" != apos :
90
- dynamic .append (('\' (\d\d(?:’|\' )?s)' , apos + '\\ 1' )) # '99's
91
- dynamic .append (('\' (\d)' , apos + '\\ 1' )) # '99
90
+ dynamic .append ((r '\'(\d\d(?:’|\')?s)' , apos + '\\ 1' )) # '99's
91
+ dynamic .append ((r '\'(\d)' , apos + '\\ 1' )) # '99
92
92
if "'" != opening_single_quote :
93
- dynamic .append (('(\s|\A|[([{<]|")\' ' , '\\ 1' + opening_single_quote )) # opening single quote, even after (, {, <, [
93
+ dynamic .append ((r '(\s|\A|[([{<]|")\'' , '\\ 1' + opening_single_quote )) # opening single quote, even after (, {, <, [
94
94
if '"' != double_prime :
95
- dynamic .append (('(\d)"' , '\\ 1' + double_prime )) # 9" (double prime)
95
+ dynamic .append ((r '(\d)"' , '\\ 1' + double_prime )) # 9" (double prime)
96
96
if "'" != prime :
97
- dynamic .append (('(\d)\' ' , '\\ 1' + prime )) # 9' (prime)
97
+ dynamic .append ((r '(\d)\'' , '\\ 1' + prime )) # 9' (prime)
98
98
if "'" != apos :
99
- dynamic .append (('(\S)\' ([^\' \s])' , '\\ 1' + apos + '\\ 2' )) # apostrophe in a word
99
+ dynamic .append ((r '(\S)\'([^\'\s])' , '\\ 1' + apos + '\\ 2' )) # apostrophe in a word
100
100
if '"' != opening_quote :
101
- dynamic .append (('(\s|\A|[([{<])"(?!\s)' , '\\ 1' + opening_quote )) # opening double quote, even after (, {, <, [
101
+ dynamic .append ((r '(\s|\A|[([{<])"(?!\s)' , '\\ 1' + opening_quote )) # opening double quote, even after (, {, <, [
102
102
# PHP: the original PHP regular expression had a problem, since there was only one capturing group, but both \1 and \2 were
103
103
# used on the right-hand side. Since Python throws an exception in that case, while PHP simply treats \2 as an empty string,
104
104
# I had to remove the "+'\\2'" after opening_quote.
105
105
if '"' != closing_quote :
106
- dynamic .append (('"(\s|\S|\Z)' , closing_quote + '\\ 1' )) # closing double quote
106
+ dynamic .append ((r '"(\s|\S|\Z)' , closing_quote + '\\ 1' )) # closing double quote
107
107
if "'" != closing_single_quote :
108
- dynamic .append (('\' ([\s.]|\Z)' , closing_single_quote + '\\ 1' )) # closing single quote
108
+ dynamic .append ((r '\'([\s.]|\Z)' , closing_single_quote + '\\ 1' )) # closing single quote
109
109
110
- dynamic .append (('\b (\d+)x(\d+)\b ' , '\\ 1×\\ 2' )) # 9x9 (times)
110
+ dynamic .append ((r '\b(\d+)x(\d+)\b' , '\\ 1×\\ 2' )) # 9x9 (times)
111
111
112
112
self .dynamic = dynamic
113
113
@@ -144,7 +144,7 @@ def wptexturize(self, text):
144
144
no_texturize_shortcodes_stack = []
145
145
146
146
# PHP: Since Python doesn't support PHP's /U modifier (which inverts quantifier's greediness), I modified the regular expression accordingly
147
- textarr = regex .split ('(<.*?>|\[.*?\])' , text , flags = regex .DOTALL )
147
+ textarr = regex .split (r '(<.*?>|\[.*?\])' , text , flags = regex .DOTALL )
148
148
149
149
result = []
150
150
for curl in textarr :
@@ -240,8 +240,8 @@ def __convert_chars_setup(self):
240
240
241
241
def convert_chars (self , content ):
242
242
# Remove metadata tags
243
- content = regex .sub ('<title>(.+?)<\/title>' , '' , content )
244
- content = regex .sub ('<category>(.+?)<\/category>' , '' , content )
243
+ content = regex .sub (r '<title>(.+?)<\/title>' , '' , content )
244
+ content = regex .sub (r '<category>(.+?)<\/category>' , '' , content )
245
245
246
246
# Converts lone & characters into & (a.k.a. &)
247
247
content = regex .sub ('&([^#])(?![a-z1-4]{1,8};)' , '&\\ 1' , content , regex .IGNORECASE )
@@ -288,36 +288,36 @@ def wpautop(self, pee, br=True):
288
288
289
289
pee += last_pee
290
290
291
- pee = regex .sub ('<br />\s*<br />' , "\n \n " , pee )
291
+ pee = regex .sub (r '<br />\s*<br />' , "\n \n " , pee )
292
292
# Space things out a little
293
293
self .allblocks = '(?:table|thead|tfoot|caption|col|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|select|option|form|map|area|blockquote|address|math|style|p|h[1-6]|hr|fieldset|noscript|legend|section|article|aside|hgroup|header|footer|nav|figure|figcaption|details|menu|summary)'
294
294
pee = regex .sub ('(<' + self .allblocks + '[^>]*>)' , "\n \\ 1" , pee )
295
295
pee = regex .sub ('(</' + self .allblocks + '>)' , "\\ 1\n \n " , pee )
296
296
pee = pee .replace ("\r \n " , "\n " ).replace ("\r " , "\n " ) # cross-platform newlines
297
297
if pee .find ('<object' ) >= 0 :
298
- pee = regex .sub ('\s*<param([^>]*)>\s*' , "<param\\ 1>" , pee ) # no pee inside object/embed
299
- pee = regex .sub ('\s*</embed>\s*' , '</embed>' , pee )
298
+ pee = regex .sub (r '\s*<param([^>]*)>\s*' , "<param\\ 1>" , pee ) # no pee inside object/embed
299
+ pee = regex .sub (r '\s*</embed>\s*' , '</embed>' , pee )
300
300
pee = regex .sub ("\n \n +" , "\n \n " , pee ) # take care of duplicates
301
301
# make paragraphs, including one at the end
302
- pees = regex .split ('\n \s*\n ' , pee )
302
+ pees = regex .split ('\n \\ s*\n ' , pee )
303
303
pee = ''
304
304
for trinkle in pees :
305
305
if len (trinkle ) > 0 : # PHP: this emulates PHP's flag PREG_SPLIT_NO_EMPTY for preg_split()
306
306
pee += '<p>' + trinkle .strip ("\n " ) + "</p>\n "
307
- pee = regex .sub ('<p>\s*</p>' , '' , pee ) # under certain strange conditions it could create a P of entirely whitespace
307
+ pee = regex .sub (r '<p>\s*</p>' , '' , pee ) # under certain strange conditions it could create a P of entirely whitespace
308
308
pee = regex .sub ('<p>([^<]+)</(div|address|form)>' , "<p>\\ 1</p></\\ 2>" , pee )
309
- pee = regex .sub ('<p>\s*(</?' + self .allblocks + '[^>]*>)\s*</p>' , "\\ 1" , pee ) # don't pee all over a tag
309
+ pee = regex .sub (r '<p>\s*(</?' + self .allblocks + r '[^>]*>)\s*</p>' , "\\ 1" , pee ) # don't pee all over a tag
310
310
pee = regex .sub ("<p>(<li.+?)</p>" , "\\ 1" , pee ) # problem with nested lists
311
311
pee = regex .sub ('<p><blockquote([^>]*)>' , "<blockquote\\ 1><p>" , pee , regex .IGNORECASE )
312
312
pee = pee .replace ('</blockquote></p>' , '</p></blockquote>' )
313
- pee = regex .sub ('<p>\s*(</?' + self .allblocks + '[^>]*>)' , "\\ 1" , pee )
314
- pee = regex .sub ('(</?' + self .allblocks + '[^>]*>)\s*</p>' , "\\ 1" , pee )
313
+ pee = regex .sub (r '<p>\s*(</?' + self .allblocks + '[^>]*>)' , "\\ 1" , pee )
314
+ pee = regex .sub ('(</?' + self .allblocks + r '[^>]*>)\s*</p>' , "\\ 1" , pee )
315
315
if br :
316
- pee = php .preg_replace_callback ('<(script|style).*?<\/\\ 1>' , lambda x : self .__autop_newline_preservation_helper (x ), pee , regex .DOTALL )
317
- pee = regex .sub ('(?<!<br />)\s*\n ' , "<br />\n " , pee ) # optionally make line breaks
316
+ pee = php .preg_replace_callback ('<(script|style).*?<\\ /\\ 1>' , lambda x : self .__autop_newline_preservation_helper (x ), pee , regex .DOTALL )
317
+ pee = regex .sub ('(?<!<br />)\\ s*\n ' , "<br />\n " , pee ) # optionally make line breaks
318
318
pee = pee .replace ('<WPPreserveNewline />' , "\n " )
319
- pee = regex .sub ('(</?' + self .allblocks + '[^>]*>)\s*<br />' , "\\ 1" , pee )
320
- pee = regex .sub ('<br />(\s*</?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)[^>]*>)' , '\\ 1' , pee )
319
+ pee = regex .sub ('(</?' + self .allblocks + r '[^>]*>)\s*<br />' , "\\ 1" , pee )
320
+ pee = regex .sub (r '<br />(\s*</?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)[^>]*>)' , '\\ 1' , pee )
321
321
pee = regex .sub ("\n </p>$" , '</p>' , pee )
322
322
323
323
if len (pre_tags ) > 0 :
0 commit comments