[文档]defbacktick(state:StateInline,silent:bool)->bool:pos=state.posch=state.srcCharCode[pos]# /* ` */ifch!=0x60:returnFalsestart=pospos+=1maximum=state.posMax# scan marker lengthwhilepos<maximumand(state.srcCharCode[pos]==0x60):# /* ` */pos+=1marker=state.src[start:pos]openerLength=len(marker)ifstate.backticksScannedandstate.backticks.get(openerLength,0)<=start:ifnotsilent:state.pending+=markerstate.pos+=openerLengthreturnTruematchStart=matchEnd=pos# Nothing found in the cache, scan until the end of the line (or until marker is found)whileTrue:try:matchStart=state.src.index("`",matchEnd)exceptValueError:breakmatchEnd=matchStart+1# scan marker lengthwhilematchEnd<maximumand(state.srcCharCode[matchEnd]==0x60):# /* ` */matchEnd+=1closerLength=matchEnd-matchStartifcloserLength==openerLength:# Found matching closer length.ifnotsilent:token=state.push("code_inline","code",0)token.markup=markertoken.content=state.src[pos:matchStart].replace("\n"," ")if(token.content.startswith(" ")andtoken.content.endswith(" ")andlen(token.content.strip())>0):token.content=token.content[1:-1]state.pos=matchEndreturnTrue# Some different length found, put it in cache as upper limit of where closer can be foundstate.backticks[closerLength]=matchStart# Scanned through the end, didn't find anythingstate.backticksScanned=Trueifnotsilent:state.pending+=markerstate.pos+=openerLengthreturnTrue