6.4.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 Last
   256: #line 355 "web_weaver.ipk"
   257:   def _current_level(self): return len(self.hcount)-1
   258:   def _pop_level(self): del self.hcount[-1]
   259:   def _push_level(self): self.hcount.append(0)
   260:   def _next_hnum(self): self.hcount[-1] = self.hcount[-1] + 1
   261: 
   262:   def head(self,level, text, atext='', anchor=''):
   263:     while level > self._current_level():
   264:       self._head(text, atext,anchor)  # synthesised dummy heading
   265:       self._push_level()
   266:     while level < self._current_level():
   267:       self._pop_level()
   268:       self._foot()
   269:     assert level == self._current_level()
   270:     self._next_hnum()
   271:     self._head(text, atext, anchor)
   272:     self._push_level()
   273:     assert self._current_level() == level + 1
   274: 
End python section to interscript/weavers/web.py[4]