+void InsetText::docbookText(XMLStream & xs, OutputParams const & rp, XHTMLOptions opts) const
+{
+ InsetLayout const &il = getLayout();
+ OutputParams runparams = rp;
+
+ // In some cases, the input parameters must be overridden for outer tags.
+ bool writeOuterTag = opts & WriteOuterTag;
+ if (writeOuterTag) {
+ // For each paragraph, if there are only Bibitems and the corresponding text, don't write the outer tags.
+ bool allBibitems = std::all_of(text().paragraphs().begin(), text().paragraphs().end(), [](Paragraph const & par) {
+ auto nInsets = std::distance(par.insetList().begin(), par.insetList().end());
+ auto parSize = (size_t) par.size();
+ return nInsets == 1 && parSize > 1 && par.insetList().begin()->inset->lyxCode() == BIBITEM_CODE;
+ });
+ writeOuterTag = !allBibitems;
+ }
+
+ // Detect arguments that should be output before/after the paragraph.
+ // Don't reuse runparams.docbook_prepended_arguments, as the same object is used in InsetArgument to determine
+ // whether the inset should be output or not, whatever the context (i.e. position with respect to the wrapper).
+ std::set<InsetArgument const *> prependedArguments;
+ for (auto const & par : paragraphs()) {
+ for (pos_type i = 0; i < par.size(); ++i) {
+ if (par.getInset(i) && par.getInset(i)->lyxCode() == ARG_CODE) {
+ InsetArgument const *arg = par.getInset(i)->asInsetArgument();
+ if (arg->docbookargumentbeforemaintag())
+ prependedArguments.insert(par.getInset(i)->asInsetArgument());
+ }
+ }
+ }
+
+ std::set<InsetArgument const *> appendedArguments;
+ for (auto const & par : paragraphs()) {
+ for (pos_type i = 0; i < par.size(); ++i) {
+ if (par.getInset(i) && par.getInset(i)->lyxCode() == ARG_CODE) {
+ InsetArgument const *arg = par.getInset(i)->asInsetArgument();
+ if (arg->docbookargumentaftermaintag())
+ appendedArguments.insert(par.getInset(i)->asInsetArgument());
+ }
+ }
+ }
+
+ // Start outputting this inset.
+ // - First, wrapper around the inset and its main tag.
+ if (writeOuterTag) {
+ if (!il.docbookwrappertag().empty() && il.docbookwrappertag() != "NONE" && il.docbookwrappertag() != "IGNORE")
+ xml::openTag(xs, il.docbookwrappertag(), il.docbookwrapperattr(), il.docbookwrappertagtype());
+
+ if (!il.docbooktag().empty() && il.docbooktag() != "NONE" && il.docbooktag() != "IGNORE") {
+ docstring attrs = docstring();
+ if (!il.docbookattr().empty())
+ attrs += from_ascii(il.docbookattr());
+ if (il.docbooktag() == "link")
+ attrs += from_ascii(" xlink:href=\"") + text_.asString() + from_ascii("\"");
+ xml::openTag(xs, il.docbooktag(), attrs, il.docbooktagtype());
+ }
+
+ if (!il.docbookinnertag().empty() && il.docbookinnertag() != "NONE" && il.docbookinnertag() != "IGNORE")
+ xml::openTag(xs, il.docbookinnertag(), il.docbookinnerattr(), il.docbookinnertagtype());
+ }
+
+ // - Think about the arguments before the paragraph.
+ OutputParams np = runparams;
+ np.docbook_in_par = true;
+ for (auto const & arg : prependedArguments)
+ arg->docbook(xs, np);
+
+ // - Mark the newly generated arguments are not-to-be-generated-again. Do the same for arguments that will follow.
+ runparams.docbook_prepended_arguments = std::move(prependedArguments);
+ runparams.docbook_appended_arguments = appendedArguments;
+
+ // - Deal with the first item.
+ // TODO: in things like SciPoster, this should also check if the item tag is allowed. Hard to formalise for now...
+ if (writeOuterTag) {
+ if (!il.docbookitemwrappertag().empty() && il.docbookitemwrappertag() != "NONE" && il.docbookitemwrappertag() != "IGNORE")
+ xml::openTag(xs, il.docbookitemwrappertag(), il.docbookitemwrapperattr(), il.docbookitemwrappertagtype());
+
+ if (!il.docbookitemtag().empty() && il.docbookitemtag() != "NONE" && il.docbookitemtag() != "IGNORE")
+ xml::openTag(xs, il.docbookitemtag(), il.docbookitemattr(), il.docbookitemtagtype());
+ }
+
+ // No need for labels that are generated from counters. They should be handled by the external DocBook processor.
+
+ // With respect to XHTML, paragraphs are still allowed here.
+ if (runparams.docbook_consider_allow_multi_par && !allowMultiPar())
+ runparams.docbook_make_pars = false;
+ if (il.isPassThru())
+ runparams.pass_thru = true;
+
+ // - Write the main content of the inset.
+ xs.startDivision(false);
+ docbookParagraphs(text_, buffer(), xs, runparams);
+ xs.endDivision();
+
+ // - Think about the arguments after the paragraph.
+ for (auto const & arg : appendedArguments)
+ arg->docbook(xs, np);
+
+ // - Close the required tags.
+ if (writeOuterTag) {
+ if (!il.docbookitemtag().empty() && il.docbookitemtag() != "NONE" && il.docbookitemtag() != "IGNORE")
+ xml::closeTag(xs, il.docbookitemtag(), il.docbookitemtagtype());
+
+ if (!il.docbookitemwrappertag().empty() && il.docbookitemwrappertag() != "NONE" && il.docbookitemwrappertag() != "IGNORE")
+ xml::closeTag(xs, il.docbookitemwrappertag(), il.docbookitemwrappertagtype());
+
+ if (!il.docbookinnertag().empty() && il.docbookinnertag() != "NONE" && il.docbookinnertag() != "IGNORE")
+ xml::closeTag(xs, il.docbookinnertag(), il.docbookinnertagtype());
+
+ if (!il.docbooktag().empty() && il.docbooktag() != "NONE" && il.docbooktag() != "IGNORE")
+ xml::closeTag(xs, il.docbooktag(), il.docbooktagtype());
+
+ if (!il.docbookwrappertag().empty() && il.docbookwrappertag() != "NONE" && il.docbookwrappertag() != "IGNORE")
+ xml::closeTag(xs, il.docbookwrappertag(), il.docbookwrappertagtype());
+ }
+}
+
+
+docstring InsetText::xhtml(XMLStream & xs, OutputParams const & runparams) const