@@ -95,32 +95,32 @@ def build_inlinepatterns(md, **kwargs):
95
95
NOIMG = r'(?<!\!)'
96
96
97
97
# `e=f()` or ``e=f("`")``
98
- BACKTICK_RE = r'(?<!\\)(`+)(.+?)(?<!`)\2 (?!`)'
98
+ BACKTICK_RE = r'(?<!\\)(`+)(.+?)(?<!`)\1 (?!`)'
99
99
100
100
# \<
101
101
ESCAPE_RE = r'\\(.)'
102
102
103
103
# *emphasis*
104
- EMPHASIS_RE = r'(\*)([^\*]+)\2 '
104
+ EMPHASIS_RE = r'(\*)([^\*]+)\1 '
105
105
106
106
# **strong**
107
- STRONG_RE = r'(\*{2})(.+?)\2 '
107
+ STRONG_RE = r'(\*{2})(.+?)\1 '
108
108
109
109
# __smart__strong__
110
- SMART_STRONG_RE = r'(?<!\w)(_{2})(?!_)(.+?)(?<!_)\2 (?!\w)'
110
+ SMART_STRONG_RE = r'(?<!\w)(_{2})(?!_)(.+?)(?<!_)\1 (?!\w)'
111
111
112
112
# _smart_emphasis_
113
- SMART_EMPHASIS_RE = r'(?<!\w)(_)(?!_)(.+?)(?<!_)\2 (?!\w)'
113
+ SMART_EMPHASIS_RE = r'(?<!\w)(_)(?!_)(.+?)(?<!_)\1 (?!\w)'
114
114
115
115
# ***strongem*** or ***em*strong**
116
- EM_STRONG_RE = r'(\*|_)\2 {2}(.+?)\2 (.*?)\2 {2}'
116
+ EM_STRONG_RE = r'(\*|_)\1 {2}(.+?)\1 (.*?)\1 {2}'
117
117
118
118
# ***strong**em*
119
- STRONG_EM_RE = r'(\*|_)\2 {2}(.+?)\2 {2}(.*?)\2 '
119
+ STRONG_EM_RE = r'(\*|_)\1 {2}(.+?)\1 {2}(.*?)\1 '
120
120
121
121
# [text](url) or [text](<url>) or [text](url "title")
122
122
LINK_RE = NOIMG + BRK + \
123
- r'''\(\s*(<.*?>|((?:(?:\(.*?\))|[^\(\)]))*?)\s*((['"])(.*?)\12 \s*)?\)'''
123
+ r'''\(\s*(<.*?>|((?:(?:\(.*?\))|[^\(\)]))*?)\s*((['"])(.*?)\1 \s*)?\)'''
124
124
125
125
#  or 
126
126
IMAGE_LINK_RE = r'\!' + BRK + r'\s*\((<.*?>|([^")]+"[^"]*"|[^\)]*))\)'
@@ -181,8 +181,7 @@ def __init__(self, pattern, md=None):
181
181
182
182
"""
183
183
self .pattern = pattern
184
- self .compiled_re = re .compile ("^(.*?)%s(.*?)$" % pattern ,
185
- re .DOTALL | re .UNICODE )
184
+ self .compiled_re = re .compile (pattern , re .DOTALL | re .UNICODE )
186
185
187
186
if md :
188
187
self .md = md
@@ -215,7 +214,7 @@ def unescape(self, text):
215
214
return text
216
215
217
216
def get_stash (m ):
218
- id = m .group (1 )
217
+ id = m .group (0 )
219
218
if id in stash :
220
219
value = stash .get (id )
221
220
if isinstance (value , util .string_type ):
@@ -227,16 +226,16 @@ def get_stash(m):
227
226
228
227
229
228
class SimpleTextPattern (Pattern ):
230
- """ Return a simple text of group(2 ) of a Pattern. """
229
+ """ Return a simple text of group(1 ) of a Pattern. """
231
230
def handleMatch (self , m ):
232
- return m .group (2 )
231
+ return m .group (1 )
233
232
234
233
235
234
class EscapePattern (Pattern ):
236
235
""" Return an escaped character. """
237
236
238
237
def handleMatch (self , m ):
239
- char = m .group (2 )
238
+ char = m .group (1 )
240
239
if char in self .md .ESCAPED_CHARS :
241
240
return '%s%s%s' % (util .STX , ord (char ), util .ETX )
242
241
else :
@@ -245,7 +244,7 @@ def handleMatch(self, m):
245
244
246
245
class SimpleTagPattern (Pattern ):
247
246
"""
248
- Return element of type `tag` with a text attribute of group(3 )
247
+ Return element of type `tag` with a text attribute of group(2 )
249
248
of a Pattern.
250
249
251
250
"""
@@ -255,7 +254,7 @@ def __init__(self, pattern, tag):
255
254
256
255
def handleMatch (self , m ):
257
256
el = util .etree .Element (self .tag )
258
- el .text = m .group (3 )
257
+ el .text = m .group (2 )
259
258
return el
260
259
261
260
@@ -273,7 +272,7 @@ def __init__(self, pattern):
273
272
274
273
def handleMatch (self , m ):
275
274
el = util .etree .Element (self .tag )
276
- el .text = util .AtomicString (m .group (3 ).strip ())
275
+ el .text = util .AtomicString (m .group (2 ).strip ())
277
276
return el
278
277
279
278
@@ -287,16 +286,16 @@ def handleMatch(self, m):
287
286
tag1 , tag2 = self .tag .split ("," )
288
287
el1 = util .etree .Element (tag1 )
289
288
el2 = util .etree .SubElement (el1 , tag2 )
290
- el2 .text = m .group (3 )
291
- if len (m .groups ()) == 5 :
292
- el2 .tail = m .group (4 )
289
+ el2 .text = m .group (2 )
290
+ if len (m .groups ()) == 3 : # TODO: confirm this is right. maybe 4?
291
+ el2 .tail = m .group (3 )
293
292
return el1
294
293
295
294
296
295
class HtmlPattern (Pattern ):
297
296
""" Store raw inline html and return a placeholder. """
298
297
def handleMatch (self , m ):
299
- rawhtml = self .unescape (m .group (2 ))
298
+ rawhtml = self .unescape (m .group (1 ))
300
299
place_holder = self .md .htmlStash .store (rawhtml )
301
300
return place_holder
302
301
@@ -308,7 +307,7 @@ def unescape(self, text):
308
307
return text
309
308
310
309
def get_stash (m ):
311
- id = m .group (1 )
310
+ id = m .group (0 )
312
311
value = stash .get (id )
313
312
if value is not None :
314
313
try :
@@ -323,9 +322,9 @@ class LinkPattern(Pattern):
323
322
""" Return a link element from the given match. """
324
323
def handleMatch (self , m ):
325
324
el = util .etree .Element ("a" )
326
- el .text = m .group (2 )
327
- title = m .group (13 )
328
- href = m .group (9 )
325
+ el .text = m .group (1 )
326
+ title = m .group (12 )
327
+ href = m .group (8 )
329
328
330
329
if href :
331
330
if href [0 ] == "<" :
@@ -344,7 +343,7 @@ class ImagePattern(LinkPattern):
344
343
""" Return a img element from the given match. """
345
344
def handleMatch (self , m ):
346
345
el = util .etree .Element ("img" )
347
- src_parts = m .group (9 ).split ()
346
+ src_parts = m .group (8 ).split ()
348
347
if src_parts :
349
348
src = src_parts [0 ]
350
349
if src [0 ] == "<" and src [- 1 ] == ">" :
@@ -365,21 +364,21 @@ class ReferencePattern(LinkPattern):
365
364
366
365
def handleMatch (self , m ):
367
366
try :
368
- id = m .group (9 ).lower ()
367
+ id = m .group (8 ).lower ()
369
368
except IndexError :
370
369
id = None
371
370
if not id :
372
371
# if we got something like "[Google][]" or "[Goggle]"
373
372
# we'll use "google" as the id
374
- id = m .group (2 ).lower ()
373
+ id = m .group (1 ).lower ()
375
374
376
375
# Clean up linebreaks in id
377
376
id = self .NEWLINE_CLEANUP_RE .sub (' ' , id )
378
377
if id not in self .md .references : # ignore undefined refs
379
378
return None
380
379
href , title = self .md .references [id ]
381
380
382
- text = m .group (2 )
381
+ text = m .group (1 )
383
382
return self .makeTag (href , title , text )
384
383
385
384
def makeTag (self , href , title , text ):
@@ -408,8 +407,8 @@ class AutolinkPattern(Pattern):
408
407
""" Return a link Element given an autolink (`<http://example/com>`). """
409
408
def handleMatch (self , m ):
410
409
el = util .etree .Element ("a" )
411
- el .set ('href' , self .unescape (m .group (2 )))
412
- el .text = util .AtomicString (m .group (2 ))
410
+ el .set ('href' , self .unescape (m .group (1 )))
411
+ el .text = util .AtomicString (m .group (1 ))
413
412
return el
414
413
415
414
@@ -419,7 +418,7 @@ class AutomailPattern(Pattern):
419
418
"""
420
419
def handleMatch (self , m ):
421
420
el = util .etree .Element ('a' )
422
- email = self .unescape (m .group (2 ))
421
+ email = self .unescape (m .group (1 ))
423
422
if email .startswith ("mailto:" ):
424
423
email = email [len ("mailto:" ):]
425
424
0 commit comments