- ParagraphList::const_iterator const begin = text.paragraphs().begin();
- ParagraphList::const_iterator par = pbegin;
- for (; par != pend; ++par) {
- Layout const &lay = par->layout();
-
- // 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) : 0;
- 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(lay) && !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;
-
- // We want to issue the closing tag if either:
- // (i) We opened it, and either docbook_in_par is false,
- // or we're not in the last paragraph, anyway.
- // (ii) We didn't open it and docbook_in_par is true,
- // but we are in the first par, and there is a next par.
- ParagraphList::const_iterator nextpar = par;
- ++nextpar;
- bool const close_par =
- ((open_par && (!runparams.docbook_in_par || nextpar != pend))
- || (!open_par && runparams.docbook_in_par && par == pbegin && nextpar != pend));
-
- // Determine if this paragraph has some real content. Things like new pages are not caught
- // by Paragraph::empty(), even though they do not generate anything useful in DocBook.
- odocstringstream os2;
- XMLStream xs2(os2);
- par->simpleDocBookOnePar(buf, xs2, runparams, text.outerFont(distance(begin, par)), open_par, close_par, 0);
-
- docstring cleaned = os2.str();
- static const lyx::regex reg("[ \\r\\n]*");
- cleaned = from_utf8(lyx::regex_replace(to_utf8(cleaned), reg, string("")));