- // Find the paragraph *before* pbegin.
- ParagraphList::const_iterator pbegin_before = begin;
- if (pbegin != begin) {
- ParagraphList::const_iterator pbegin_before_next = begin;
- ++pbegin_before_next;
-
- while (pbegin_before_next != pbegin) {
- ++pbegin_before;
- ++pbegin_before_next;
- }
- }
-
- ParagraphList::const_iterator par = pbegin;
-
- // If this is the first paragraph in a bibliography, open the bibliography tag.
- if (pbegin != begin && pbegin_before->layout().latextype != LATEX_BIB_ENVIRONMENT) {
- xs << xml::StartTag("bibliography");
- xs << xml::CR();
- }
-
- // Generate the required paragraphs, but only if they are .
- for (; par != pend; ++par) {
- // Start the precooked bibliography entry. This is very much like opening a paragraph tag.
- // Don't forget the citation ID!
- docstring attr;
- for (auto i = 0; i < par->size(); ++i) {
- Inset const *ip = par->getInset(0);
- if (ip != nullptr && ip->lyxCode() == BIBITEM_CODE) {
- const auto * bibitem = dynamic_cast<const InsetBibitem*>(par->getInset(i));
- attr = from_utf8("xml:id='") + bibitem->getParam("key") + from_utf8("'");
- break;
- }
- }
- xs << xml::StartTag(from_utf8("bibliomixed"), attr);
-
- // Generate the entry.
- par->simpleDocBookOnePar(buf, xs, runparams, text.outerFont(distance(begin, par)), true, true, 0);
-
- // End the precooked bibliography entry.
- xs << xml::EndTag("bibliomixed");
- xs << xml::CR();
- }
-
- // If this is the last paragraph in a bibliography, close the bibliography tag.
- if (par == end || par->layout().latextype != LATEX_BIB_ENVIRONMENT) {
- xs << xml::EndTag("bibliography");
- xs << xml::CR();
- }
-
- return pend;
-}
-
-
-ParagraphList::const_iterator makeParagraphs(
- Buffer const &buf,
- XMLStream &xs,
- OutputParams const &runparams,
- Text const &text,
- ParagraphList::const_iterator const & pbegin,
- ParagraphList::const_iterator const & pend)
-{
- auto const begin = text.paragraphs().begin();
- auto const end = text.paragraphs().end();
- ParagraphList::const_iterator par = pbegin;
- ParagraphList::const_iterator prevpar = pbegin;
-
- for (; par != pend; prevpar = par, ++par) {
- // We want to open the paragraph tag if:
- // (i) the current layout permits multiple paragraphs
- // (ii) we are either not already inside a paragraph (HTMLIsBlock) OR
- // we are, but this is not the first paragraph
- //
- // But there is also a special case, and we first see whether we are in it.
- // We do not want to open the paragraph tag if this paragraph contains
- // only one item, and that item is "inline", i.e., not HTMLIsBlock (such
- // as a branch). On the other hand, if that single item has a font change
- // applied to it, then we still do need to open the paragraph.
- //
- // Obviously, this is very fragile. The main reason we need to do this is
- // because of branches, e.g., a branch that contains an entire new section.
- // We do not really want to wrap that whole thing in a <div>...</div>.
- bool special_case = false;
- Inset const *specinset = par->size() == 1 ? par->getInset(0) : nullptr;
- if (specinset && !specinset->getLayout().htmlisblock()) { // TODO: Convert htmlisblock to a DocBook parameter?
- Layout const &style = par->layout();
- FontInfo const first_font = style.labeltype == LABEL_MANUAL ?
- style.labelfont : style.font;
- FontInfo const our_font =
- par->getFont(buf.masterBuffer()->params(), 0,
- text.outerFont(distance(begin, par))).fontInfo();
-
- if (first_font == our_font)
- special_case = true;
- }
-
- // Plain layouts must be ignored.
- if (!special_case && buf.params().documentClass().isPlainLayout(par->layout()) && !runparams.docbook_force_pars)
- special_case = true;
- // TODO: Could get rid of this with a DocBook equivalent to htmlisblock?
- if (!special_case && par->size() == 1 && par->getInset(0)) {
- Inset const * firstInset = par->getInset(0);
-
- // Floats cannot be in paragraphs.
- special_case = to_utf8(firstInset->layoutName()).substr(0, 6) == "Float:";
-
- // Bibliographies cannot be in paragraphs.
- if (!special_case && firstInset->asInsetCommand())
- special_case = firstInset->asInsetCommand()->params().getCmdName() == "bibtex";
-
- // Equations do not deserve their own paragraph (DocBook allows them outside paragraphs).
- if (!special_case && firstInset->asInsetMath())
- special_case = true;
-
- // ERTs are in comments, not paragraphs.
- if (!special_case && firstInset->lyxCode() == lyx::ERT_CODE)
- special_case = true;
-
- // Listings should not get into their own paragraph.
- if (!special_case && firstInset->lyxCode() == lyx::LISTINGS_CODE)
- special_case = true;
- }
-
- bool const open_par = runparams.docbook_make_pars
- && (!runparams.docbook_in_par || par != pbegin)
- && !special_case;