+ docbook(xs, rp, WriteEverything);
+}
+
+
+void InsetText::docbook(XMLStream & xs, OutputParams const & rp, XHTMLOptions opts) const
+{
+ // we will always want to output all our paragraphs when we are
+ // called this way.
+ OutputParams runparams = rp;
+ runparams.par_begin = 0;
+ runparams.par_end = text().paragraphs().size();
+
+ if (undefined()) {
+ xs.startDivision(false);
+ docbookParagraphs(text_, buffer(), xs, runparams);
+ xs.endDivision();
+ return;
+ }
+
+ InsetLayout const & il = getLayout();
+
+ // Maybe this is an <info> paragraph that should not be generated at all (i.e. right now, its place is somewhere
+ // else, typically outside the current paragraph).
+ if (!rp.docbook_generate_info && il.docbookininfo() != "never")
+ return;
+
+ // 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());
+ }
+ }
+
+ // - 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.