@@ -19,25 +19,37 @@ def backtick(state: StateInline, silent: bool) -> bool:
1919 pos += 1
2020 maximum = state .posMax
2121
22- # /* ` */
23- while pos < maximum and (state .srcCharCode [pos ] == 0x60 ):
22+ # scan marker length
23+ while pos < maximum and (state .srcCharCode [pos ] == 0x60 ): # /* ` */
2424 pos += 1
2525
2626 marker = state .src [start :pos ]
27+ openerLength = len (marker )
28+
29+ if state .backticksScanned and state .backticks .get (openerLength , 0 ) <= start :
30+ if not silent :
31+ state .pending += marker
32+ state .pos += openerLength
33+ return True
2734
2835 matchStart = matchEnd = pos
2936
37+ # Nothing found in the cache, scan until the end of the line (or until marker is found)
3038 while True :
3139 try :
3240 matchStart = state .src .index ("`" , matchEnd )
3341 except ValueError :
3442 break
3543 matchEnd = matchStart + 1
36- # /* ` */
37- while matchEnd < maximum and (state .srcCharCode [matchEnd ] == 0x60 ):
44+
45+ # scan marker length
46+ while matchEnd < maximum and (state .srcCharCode [matchEnd ] == 0x60 ): # /* ` */
3847 matchEnd += 1
3948
40- if matchEnd - matchStart == len (marker ):
49+ closerLength = matchEnd - matchStart
50+
51+ if closerLength == openerLength :
52+ # Found matching closer length.
4153 if not silent :
4254 token = state .push ("code_inline" , "code" , 0 )
4355 token .markup = marker
@@ -51,7 +63,13 @@ def backtick(state: StateInline, silent: bool) -> bool:
5163 state .pos = matchEnd
5264 return True
5365
66+ # Some different length found, put it in cache as upper limit of where closer can be found
67+ state .backticks [closerLength ] = matchStart
68+
69+ # Scanned through the end, didn't find anything
70+ state .backticksScanned = True
71+
5472 if not silent :
5573 state .pending += marker
56- state .pos += len ( marker )
74+ state .pos += openerLength
5775 return True
0 commit comments