Support nested chapters

Since ChapterAtom can be nested within itself, a magic value of '' for
the elid is used to not add the element to the lists a second time.