]> git.lyx.org Git - lyx.git/blobdiff - src/output_xhtml.cpp
Fix output of floats, etc, inside environments.
[lyx.git] / src / output_xhtml.cpp
index b50f982178a245b83a2cfc40f3d978960b123528..e87fe23750232b3aaa7223a3c67064329d17ba73 100644 (file)
@@ -368,7 +368,7 @@ bool XHTMLStream::closeFontTags()
 }
 
 
-void XHTMLStream::startParagraph(bool keep_empty)
+void XHTMLStream::startDivision(bool keep_empty)
 {
        pending_tags_.push_back(makeTagPtr(html::StartTag(parsep_tag)));
        if (keep_empty)
@@ -376,7 +376,7 @@ void XHTMLStream::startParagraph(bool keep_empty)
 }
 
 
-void XHTMLStream::endParagraph()
+void XHTMLStream::endDivision()
 {
        if (isTagPending(parsep_tag)) {
                // this case is normal. it just means we didn't have content,
@@ -394,7 +394,7 @@ void XHTMLStream::endParagraph()
        }
 
        if (!isTagOpen(parsep_tag)) {
-               writeError("No paragraph separation tag found in endParagraph().");
+               writeError("No division separation tag found in endDivision().");
                return;
        }
 
@@ -835,25 +835,26 @@ ParagraphList::const_iterator makeParagraphs(Buffer const & buf,
                if (!lay.counter.empty())
                        buf.masterBuffer()->params().
                            documentClass().counters().step(lay.counter, OutputUpdate);
+
                // FIXME We should see if there's a label to be output and
                // do something with it.
                if (par != pbegin)
                        xs << html::CR();
 
-               // 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;
 
                // We want to issue the closing tag if either:
                //   (i)  We opened it, and either html_in_par is false,
@@ -862,13 +863,26 @@ ParagraphList::const_iterator makeParagraphs(Buffer const & buf,
                //        but we are in the first par, and there is a next par.
                ParagraphList::const_iterator nextpar = par;
                ++nextpar;
-               bool const needclose =
-                       (opened && (!runparams.html_in_par || nextpar != pend))
-                       || (!opened && runparams.html_in_par && par == pbegin && nextpar != pend);
-               if (needclose) {
+               bool const close_par =
+                       (open_par && (!runparams.html_in_par || nextpar != pend))
+                       || (!open_par && runparams.html_in_par && par == pbegin && nextpar != pend);
+
+               if (open_par) {
+                       // We do not issue the paragraph id if we are doing 
+                       // this for the TOC (or some similar purpose)
+                       openParTag(xs, lay, par->params(),
+                                  runparams.for_toc ? "" : par->magicLabel());
+               }
+
+               docstring const deferred = par->simpleLyXHTMLOnePar(buf, xs, 
+                       runparams, text.outerFont(distance(begin, par)),
+                       open_par, close_par);
+
+               if (close_par) {
                        closeTag(xs, lay);
                        xs << html::CR();
                }
+
                if (!deferred.empty()) {
                        xs << XHTMLStream::ESCAPE_NONE << deferred << html::CR();
                }
@@ -997,8 +1011,9 @@ ParagraphList::const_iterator makeEnvironment(Buffer const & buf,
                                if (labelfirst)
                                        openItemTag(xs, style, par->params());
 
-                               par->simpleLyXHTMLOnePar(buf, xs, runparams,
-                                       text.outerFont(distance(begin, par)), sep);
+                               docstring deferred = par->simpleLyXHTMLOnePar(buf, xs, runparams,
+                                       text.outerFont(distance(begin, par)), true, true, sep);
+                               xs << XHTMLStream::ESCAPE_NONE << deferred;
                                ++par;
 
                                // We may not want to close the tag yet, in particular: