6.14.6.2.3. heading processor

The title of the main document is level 0. The top level content of that document is level 1. A heading inserted into the document is level 1. After a level 1 heading is inserted, the immediately following content is level 2.

The hcount list is a list of current heading numbers at each level, including 0. The current document level is the length of this list, minus 1. The last entry in the list is always 0, except briefly when a heading is being generated at that level.

Start python section to interscript/weavers/web.py[4 /8 ] Next Prev First Last
   285: #line 384 "web_weaver.ipk"
   286:   def _current_level(self): return len(self.hcount)-1
   287:   def _pop_level(self): del self.hcount[-1]
   288:   def _push_level(self): self.hcount.append(0)
   289:   def _next_hnum(self): self.hcount[-1] = self.hcount[-1] + 1
   290: 
   291:   def head(self,level, text, **kwds):
   292:     oldsubdoc = self.subdoc_stack.top
   293:     while level <= oldsubdoc[0]:
   294:       self.pattern = oldsubdoc[1]
   295:       self.childcount = oldsubdoc[2]
   296:       #print 'Resetting pattern to',self.pattern,'count to',self.childcount
   297:       self.subdoc_stack.pop()
   298:       oldsubdoc = self.subdoc_stack.top
   299: 
   300:     atext=kwds.get('short_text')
   301:     anchor=kwds.get('key','')
   302:     while level > self._current_level():
   303:       self._head(text, atext,None,None)  # synthesised dummy heading
   304:       self._push_level()
   305:     while level < self._current_level():
   306:       self._pop_level()
   307:       self._foot()
   308:     assert level == self._current_level()
   309:     self._next_hnum()
   310:     if anchor:
   311:       self.subdoc_stack.push((level,self.pattern, self.childcount))
   312:       self.childcount = 0
   313:       self.pattern = munge2filename(anchor) +'_%s.html'
   314:       if self.language: self.pattern = self.language+'_'+self.pattern
   315:       #print 'Setting pattern to',self.pattern,'count to',self.childcount
   316:     nospawn = kwds.get('nospawn',None)
   317:     self._head(text, atext, anchor, nospawn)
   318:     self._push_level()
   319:     assert self._current_level() == level + 1
   320: 
End python section to interscript/weavers/web.py[4]