Support nested chapters

Since ChapterAtom can be nested within itself, a magic value of '' for
the elid is used to not add the element tot he lists a second time.

(I don't really know Perl that well[1], so if I've done something awful, I apologize in advance.)

[1]I had to look up how to negate 'eq'…