+ if (entry_number == -1 || !eit->equal(last)) {
+ if (entry_number != -1) {
+ // not the first time through the loop, so
+ // close last entry or entries, depending.
+ if (level == 3) {
+ // close this sub-sub-entry
+ xs << html::EndTag("li") << html::CR();
+ // is this another sub-sub-entry within the same sub-entry?
+ if (!eit->same_sub(last)) {
+ // close this level
+ xs << html::EndTag("ul") << html::CR();
+ level = 2;
+ }
+ }
+ // the point of the second test here is that we might get
+ // here two ways: (i) by falling through from above; (ii) because,
+ // though the sub-entry hasn't changed, the sub-sub-entry has,
+ // which means that it is the first sub-sub-entry within this
+ // sub-entry. In that case, we do not want to close anything.
+ if (level == 2 && !eit->same_sub(last)) {
+ // close sub-entry
+ xs << html::EndTag("li") << html::CR();
+ // is this another sub-entry with the same main entry?
+ if (!eit->same_main(last)) {
+ // close this level
+ xs << html::EndTag("ul") << html::CR();
+ level = 1;
+ }
+ }
+ // again, we can get here two ways: from above, or because we have
+ // found the first sub-entry. in the latter case, we do not want to
+ // close the entry.
+ if (level == 1 && !eit->same_main(last)) {
+ // close entry
+ xs << html::EndTag("li") << html::CR();
+ }
+ }
+
+ // we'll be starting new entries
+ entry_number = 0;
+
+ // We need to use our own stream, since we will have to
+ // modify what we get back.
+ odocstringstream ent;
+ XHTMLStream entstream(ent);
+ OutputParams ours = op;
+ ours.for_toc = true;
+ par.simpleLyXHTMLOnePar(buffer(), entstream, ours, dummy);
+
+ // these will contain XHTML versions of the main entry, etc
+ // remember that everything will already have been escaped,
+ // so we'll need to use NextRaw() during output.
+ docstring main;
+ docstring sub;
+ docstring subsub;
+ extractSubentries(ent.str(), main, sub, subsub);
+ parseItem(main, true);
+ parseItem(sub, true);
+ parseItem(subsub, true);
+
+ if (level == 3) {
+ // another subsubentry
+ xs << html::StartTag("li", "class='subsubentry'")
+ << XHTMLStream::ESCAPE_NONE << subsub;
+ } else if (level == 2) {
+ // there are two ways we can be here:
+ // (i) we can actually be inside a sub-entry already and be about
+ // to output the first sub-sub-entry. in this case, our sub
+ // and the last sub will be the same.
+ // (ii) we can just have closed a sub-entry, possibly after also
+ // closing a list of sub-sub-entries. here our sub and the last
+ // sub are different.
+ // only in the latter case do we need to output the new sub-entry.
+ // note that in this case, too, though, the sub-entry might already
+ // have a sub-sub-entry.
+ if (eit->sub != last.sub)
+ xs << html::StartTag("li", "class='subentry'")
+ << XHTMLStream::ESCAPE_NONE << sub;
+ if (!subsub.empty()) {
+ // it's actually a subsubentry, so we need to start that list
+ xs << html::CR()
+ << html::StartTag("ul", "class='subsubentry'")
+ << html::StartTag("li", "class='subsubentry'")
+ << XHTMLStream::ESCAPE_NONE << subsub;
+ level = 3;
+ }
+ } else {
+ // there are also two ways we can be here:
+ // (i) we can actually be inside an entry already and be about
+ // to output the first sub-entry. in this case, our main
+ // and the last main will be the same.
+ // (ii) we can just have closed an entry, possibly after also
+ // closing a list of sub-entries. here our main and the last
+ // main are different.
+ // only in the latter case do we need to output the new main entry.
+ // note that in this case, too, though, the main entry might already
+ // have a sub-entry, or even a sub-sub-entry.
+ if (eit->main != last.main)
+ xs << html::StartTag("li", "class='main'") << main;
+ if (!sub.empty()) {
+ // there's a sub-entry, too
+ xs << html::CR()
+ << html::StartTag("ul", "class='subentry'")
+ << html::StartTag("li", "class='subentry'")
+ << XHTMLStream::ESCAPE_NONE << sub;
+ level = 2;
+ if (!subsub.empty()) {
+ // and a sub-sub-entry
+ xs << html::CR()
+ << html::StartTag("ul", "class='subsubentry'")
+ << html::StartTag("li", "class='subsubentry'")
+ << XHTMLStream::ESCAPE_NONE << subsub;
+ level = 3;
+ }
+ }
+ }
+ }
+ // finally, then, we can output the index link itself