"""Horizontal ruleAt least 3 of these characters on a line * - _"""importloggingfrom..common.utilsimportisSpacefrom.state_blockimportStateBlockLOGGER=logging.getLogger(__name__)
[文档]defhr(state:StateBlock,startLine:int,endLine:int,silent:bool):LOGGER.debug("entering hr: %s, %s, %s, %s",state,startLine,endLine,silent)pos=state.bMarks[startLine]+state.tShift[startLine]maximum=state.eMarks[startLine]# if it's indented more than 3 spaces, it should be a code blockifstate.sCount[startLine]-state.blkIndent>=4:returnFalsemarker=state.srcCharCode[pos]pos+=1# Check hr marker: /* * */ /* - */ /* _ */ifmarker!=0x2Aandmarker!=0x2Dandmarker!=0x5F:returnFalse# markers can be mixed with spaces, but there should be at least 3 of themcnt=1whilepos<maximum:ch=state.srcCharCode[pos]pos+=1ifch!=markerandnotisSpace(ch):returnFalseifch==marker:cnt+=1ifcnt<3:returnFalseifsilent:returnTruestate.line=startLine+1token=state.push("hr","hr",0)token.map=[startLine,state.line]token.markup=chr(marker)*(cnt+1)returnTrue