[文档]deflheading(state:StateBlock,startLine:int,endLine:int,silent:bool):LOGGER.debug("entering lheading: %s, %s, %s, %s",state,startLine,endLine,silent)level=NonenextLine=startLine+1ruler:Ruler=state.md.block.rulerterminatorRules=ruler.getRules("paragraph")# if it's indented more than 3 spaces, it should be a code blockifstate.sCount[startLine]-state.blkIndent>=4:returnFalseoldParentType=state.parentTypestate.parentType="paragraph"# use paragraph to match terminatorRules# jump line-by-line until empty one or EOFwhilenextLine<endLineandnotstate.isEmpty(nextLine):# this would be a code block normally, but after paragraph# it's considered a lazy continuation regardless of what's thereifstate.sCount[nextLine]-state.blkIndent>3:nextLine+=1continue# Check for underline in setext headerifstate.sCount[nextLine]>=state.blkIndent:pos=state.bMarks[nextLine]+state.tShift[nextLine]maximum=state.eMarks[nextLine]ifpos<maximum:marker=state.srcCharCode[pos]# /* - */ /* = */ifmarker==0x2Dormarker==0x3D:pos=state.skipChars(pos,marker)pos=state.skipSpaces(pos)# /* = */ifpos>=maximum:level=1ifmarker==0x3Delse2break# quirk for blockquotes, this line should already be checked by that ruleifstate.sCount[nextLine]<0:nextLine+=1continue# Some tags can terminate paragraph without empty line.terminate=FalseforterminatorRuleinterminatorRules:ifterminatorRule(state,nextLine,endLine,True):terminate=Truebreakifterminate:breaknextLine+=1ifnotlevel:# Didn't find valid underlinereturnFalsecontent=state.getLines(startLine,nextLine,state.blkIndent,False).strip()state.line=nextLine+1token=state.push("heading_open","h"+str(level),1)token.markup=chr(marker)token.map=[startLine,state.line]token=state.push("inline","",0)token.content=contenttoken.map=[startLine,state.line-1]token.children=[]token=state.push("heading_close","h"+str(level),-1)token.markup=chr(marker)state.parentType=oldParentTypereturnTrue