- // If we are already in a paragraph, and this is the first one, then we
- // do not want to open the paragraph tag.
- // we also do not want to open it if the current layout does not permit
- // multiple paragraphs.
- bool const opened = runparams.html_make_pars &&
- (par != pbegin || !runparams.html_in_par);
- bool const make_parid = !runparams.for_toc && runparams.html_make_pars;
-
- if (opened)
- openParTag(xs, lay, par->params(),
- make_parid ? par->magicLabel() : "");
-
- docstring const deferred =
- par->simpleLyXHTMLOnePar(buf, xs, runparams, text.outerFont(distance(begin, 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 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). That is the "special case" we handle first.
+ Inset const * specinset = par->size() == 1 ? par->getInset(0) : 0;
+ bool const special_case =
+ specinset && !specinset->getLayout().htmlisblock();
+
+ bool const open_par = runparams.html_make_pars
+ && (!runparams.html_in_par || par != pbegin)
+ && !special_case;