- auto const begin = text.paragraphs().begin();
- ParagraphList::const_iterator par = pbegin;
- depth_type const origdepth = pbegin->params().depth();
-
- // open tag for this environment
- openParTag(xs, *par);
- xs << xml::CR();
-
- // we will on occasion need to remember a layout from before.
- Layout const *lastlay = nullptr;
-
- while (par != pend) {
- Layout const & style = par->layout();
- ParagraphList::const_iterator send;
-
- // Actual content of this paragraph.
- switch (style.latextype) {
- case LATEX_ENVIRONMENT:
- case LATEX_LIST_ENVIRONMENT:
- case LATEX_ITEM_ENVIRONMENT: {
- // There are two possibilities in this case.
- // One is that we are still in the environment in which we
- // started---which we will be if the depth is the same.
- if (par->params().depth() == origdepth) {
- LATTEST(par->layout() == style);
- if (lastlay != nullptr) {
- closeItemTag(xs, *lastlay);
- if (lastlay->docbookitemwrappertag() != "NONE") {
- xs << xml::EndTag(lastlay->docbookitemwrappertag());
- xs << xml::CR();
- }
- lastlay = nullptr;
- }
-
- // this will be positive if we want to skip the
- // initial word (if it's been taken for the label).
- pos_type sep = 0;
-
- // Open a wrapper tag if needed.
- if (style.docbookitemwrappertag() != "NONE") {
- xs << xml::StartTag(style.docbookitemwrappertag(), style.docbookitemwrapperattr());
- xs << xml::CR();
- }
-
- // label output
- if (style.labeltype != LABEL_NO_LABEL &&
- style.docbookitemlabeltag() != "NONE") {
-
- if (isNormalEnv(style)) {
- // in this case, we print the label only for the first
- // paragraph (as in a theorem or an abstract).
- if (par == pbegin) {
- docstring const lbl = pbegin->params().labelString();
- if (!lbl.empty()) {
- openLabelTag(xs, style);
- xs << lbl;
- closeLabelTag(xs, style);
- } else {
- // No new line after closeLabelTag.
- xs << xml::CR();
- }
- }
- } else { // some kind of list
- if (style.labeltype == LABEL_MANUAL) {
- // Only variablelist gets here.
-
- openLabelTag(xs, style);
- sep = par->firstWordDocBook(xs, runparams);
- closeLabelTag(xs, style);
- } else {
- openLabelTag(xs, style);
- xs << par->params().labelString();
- closeLabelTag(xs, style);
- }
- }
- } // end label output
-
- // Start generating the item.
- bool wasInParagraph = runparams.docbook_in_par;
- openItemTag(xs, style);
- bool getsIntoParagraph = openInnerItemTag(xs, style);
- OutputParams rp = runparams;
- rp.docbook_in_par = wasInParagraph | getsIntoParagraph;
-
- // Maybe the item is completely empty, i.e. if the first word ends at the end of the current paragraph
- // AND if the next paragraph doesn't have the same depth (if there is such a paragraph).
- // Common case: there is only the first word on the line, but there is a nested list instead
- // of more text.
- bool emptyItem = false;
- if (sep == par->size()) {
- auto next_par = par;
- ++next_par;
- if (next_par == text.paragraphs().end()) // There is no next paragraph.
- emptyItem = true;
- else // There is a next paragraph: check depth.
- emptyItem = par->params().depth() >= next_par->params().depth();
- }
-
- if (emptyItem) {
- // Avoid having an empty item, this is not valid DocBook. A single character is enough to force
- // generation of a full <para>.
- xs << ' ';
- } else {
- // Generate the rest of the paragraph, if need be.
- par->simpleDocBookOnePar(buf, xs, rp, text.outerFont(distance(begin, par)), true, true, sep);
- }
-
- ++par;
- if (getsIntoParagraph)
- closeInnerItemTag(xs, style);
-
- // We may not want to close the tag yet, in particular:
- // If we're not at the end of the item...
- if (par != pend
- // and are doing items...
- && !isNormalEnv(style)
- // and if the depth has changed...
- && par->params().depth() != origdepth) {
- // then we'll save this layout for later, and close it when
- // we get another item.
- lastlay = &style;
- } else {
- closeItemTag(xs, style);
-
- // Eventually, close the item wrapper.
- if (style.docbookitemwrappertag() != "NONE") {
- xs << xml::EndTag(style.docbookitemwrappertag());
- xs << xml::CR();
- }
- }
- }
- // The other possibility is that the depth has increased.
- else {
- send = findEndOfEnvironment(par, pend);
- par = makeEnvironment(buf, xs, runparams, text, par, send);
- }
- break;
- }
- case LATEX_PARAGRAPH:
- send = findLast(par, pend, LATEX_PARAGRAPH);
- par = makeParagraphs(buf, xs, runparams, text, par, send);
- break;
- case LATEX_BIB_ENVIRONMENT:
- send = findLast(par, pend, LATEX_BIB_ENVIRONMENT);
- par = makeParagraphBibliography(buf, xs, runparams, text, par, send);
- break;
- case LATEX_COMMAND:
- ++par;
- break;
- }
- }
-
- if (lastlay != nullptr) {
- closeItemTag(xs, *lastlay);
- if (lastlay->docbookitemwrappertag() != "NONE") {
- xs << xml::EndTag(lastlay->docbookitemwrappertag());
- xs << xml::CR();
- }
- }
- closeTag(xs, *par);
- xs << xml::CR();
- return pend;