+ } else if (style.latextype == LATEX_ENVIRONMENT) {
+ // Generate the paragraph, if need be.
+ std::vector<docstring> pars_prepend;
+ std::vector<docstring> pars;
+ std::vector<docstring> pars_append;
+ tie(pars_prepend, pars, pars_append) = par->simpleDocBookOnePar(buf, runparams, text.outerFont(std::distance(text.paragraphs().begin(), par)), 0, false, ignoreFonts);
+
+ for (docstring const & parXML : pars_prepend)
+ xs << XMLStream::ESCAPE_NONE << parXML;
+ if (mimicListing) {
+ auto p = pars.begin();
+ while (p != pars.end()) {
+ xml::openTag(xs, par->layout().docbookiteminnertag(), par->layout().docbookiteminnerattr(),
+ par->layout().docbookiteminnertagtype());
+ xs << XMLStream::ESCAPE_NONE << *p;
+ xml::closeTag(xs, par->layout().docbookiteminnertag(), par->layout().docbookiteminnertagtype());
+ ++p;
+
+ // Insert a new line after each "paragraph" (i.e. line in the listing), except for the last one.
+ // Otherwise, there would one more new line in the output than in the LyX document.
+ if (p != pars.end())
+ xs << xml::CR();
+ }
+ } else {
+ for (auto const & p : pars) {
+ xml::openTag(xs, par->layout().docbookiteminnertag(), par->layout().docbookiteminnerattr(),
+ par->layout().docbookiteminnertagtype());
+ xs << XMLStream::ESCAPE_NONE << p;
+ xml::closeTag(xs, par->layout().docbookiteminnertag(), par->layout().docbookiteminnertagtype());
+ }
+ }
+ for (docstring const & parXML : pars_append)
+ xs << XMLStream::ESCAPE_NONE << parXML;
+ } else {
+ makeAny(text, buf, xs, runparams, par);
+ }
+
+ // Close the environment.
+ closeParTag(xs, &*par, (nextpar != end) ? &*nextpar : nullptr, runparams);
+}
+
+
+ParagraphList::const_iterator findEndOfEnvironment(
+ ParagraphList::const_iterator const & pstart,
+ ParagraphList::const_iterator const & pend)
+{
+ // Copy-paste from XHTML. Should be factored out at some point...
+ ParagraphList::const_iterator p = pstart;
+ Layout const & bstyle = p->layout();
+ size_t const depth = p->params().depth();
+ for (++p; p != pend; ++p) {
+ Layout const & style = p->layout();
+ // It shouldn't happen that e.g. a section command occurs inside
+ // a quotation environment, at a higher depth, but as of 6/2009,
+ // it can happen. We pretend that it's just at lowest depth.
+ if (style.latextype == LATEX_COMMAND)
+ return p;
+
+ // If depth is down, we're done
+ if (p->params().depth() < depth)
+ return p;
+
+ // If depth is up, we're not done
+ if (p->params().depth() > depth)
+ continue;
+
+ // FIXME I am not sure about the first check.
+ // Surely we *could* have different layouts that count as
+ // LATEX_PARAGRAPH, right?
+ if (style.latextype == LATEX_PARAGRAPH || style != bstyle)
+ return p;
+ }
+ return pend;
+}
+
+
+ParagraphList::const_iterator makeListEnvironment(Text const &text,
+ Buffer const &buf,
+ XMLStream &xs,
+ OutputParams const &runparams,
+ ParagraphList::const_iterator const & begin)
+{
+ // Useful variables.
+ auto par = begin;
+ auto const end = text.paragraphs().end();
+ auto const envend = findEndOfEnvironment(par, end);
+
+ // Output the opening tag for this environment.
+ Layout const & envstyle = par->layout();
+ xml::openTag(xs, envstyle.docbookwrappertag(), envstyle.docbookwrapperattr(), envstyle.docbookwrappertagtype());
+ xml::openTag(xs, envstyle.docbooktag(), envstyle.docbookattr(), envstyle.docbooktagtype());
+
+ // Handle the content of the list environment, item by item.
+ while (par != envend) {
+ // Skip this paragraph if it is both empty and the last one (otherwise, there may be deeper paragraphs after).
+ auto nextpar = par;
+ ++nextpar;
+ if (par->empty() && nextpar == envend)
+ break;
+
+ // Open the item wrapper.
+ Layout const & style = par->layout();
+ xml::openTag(xs, style.docbookitemwrappertag(), style.docbookitemwrapperattr(),
+ style.docbookitemwrappertagtype());