From 909fcb7fcc0e35d26c460b0c23772ef7ba9ffca7 Mon Sep 17 00:00:00 2001 From: Richard Heck Date: Sat, 9 Jul 2016 23:12:32 -0400 Subject: [PATCH] Fix problem with branch handling. The problem was that we were not dealing properly with the paragraph separator tag. We really need to use that tag as a kind of general marker for which tags we're responsible for in a given paragraph and which tags we are not. So the changes to InsetText.cpp use the tag as that kind of marker. Note that, as of this commit, the User Guide again exports without any kind of error. I haven't yet checked the other manuals. This fixes bug #8022. (cherry picked from commit 31e25c8ec695f864bec3679c3e11495e3011a0e2) --- src/Paragraph.cpp | 17 +++++++++++---- src/Paragraph.h | 2 ++ src/insets/InsetText.cpp | 4 ++++ src/output_xhtml.cpp | 47 +++++++++++++++++++++++++--------------- status.22x | 2 ++ 5 files changed, 51 insertions(+), 21 deletions(-) diff --git a/src/Paragraph.cpp b/src/Paragraph.cpp index 0d1c8d3047..23315204be 100644 --- a/src/Paragraph.cpp +++ b/src/Paragraph.cpp @@ -2760,7 +2760,8 @@ void doFontSwitch(vector & tagsToOpen, docstring Paragraph::simpleLyXHTMLOnePar(Buffer const & buf, XHTMLStream & xs, OutputParams const & runparams, - Font const & outerfont, + Font const & outerfont, + bool start_paragraph, bool close_paragraph, pos_type initial) const { docstring retval; @@ -2782,7 +2783,8 @@ docstring Paragraph::simpleLyXHTMLOnePar(Buffer const & buf, Layout const & style = *d->layout_; - xs.startParagraph(allowEmpty()); + if (start_paragraph) + xs.startParagraph(allowEmpty()); FontInfo font_old = style.labeltype == LABEL_MANUAL ? style.labelfont : style.font; @@ -3068,7 +3070,9 @@ docstring Paragraph::simpleLyXHTMLOnePar(Buffer const & buf, if (!runparams.for_toc || inset->isInToc()) { OutputParams np = runparams; np.local_font = &font; - if (!inset->getLayout().htmlisblock()) + // If the paragraph has size 1, then we are in the "special + // case" where we do not output the containing paragraph info + if (!inset->getLayout().htmlisblock() && size() != 1) np.html_in_par = true; retval += inset->xhtml(xs, np); } @@ -3079,8 +3083,13 @@ docstring Paragraph::simpleLyXHTMLOnePar(Buffer const & buf, font_old = font.fontInfo(); } + // FIXME XHTML + // I'm worried about what happens if a branch, say, is itself + // wrapped in some font stuff. I think that will not work. xs.closeFontTags(); - xs.endParagraph(); + if (close_paragraph) + xs.endParagraph(); + return retval; } diff --git a/src/Paragraph.h b/src/Paragraph.h index ce9710ed05..bfb43e9474 100644 --- a/src/Paragraph.h +++ b/src/Paragraph.h @@ -222,6 +222,8 @@ public: XHTMLStream & xs, OutputParams const & runparams, Font const & outerfont, + bool start_paragraph = true, + bool close_paragraph = true, pos_type initial = 0) const; /// diff --git a/src/insets/InsetText.cpp b/src/insets/InsetText.cpp index 660826309f..cf896043e9 100644 --- a/src/insets/InsetText.cpp +++ b/src/insets/InsetText.cpp @@ -588,7 +588,9 @@ docstring InsetText::insetAsXHTML(XHTMLStream & xs, OutputParams const & rp, runparams.par_end = text().paragraphs().size(); if (undefined()) { + xs.startParagraph(false); xhtmlParagraphs(text_, buffer(), xs, runparams); + xs.endParagraph(); return docstring(); } @@ -622,7 +624,9 @@ docstring InsetText::insetAsXHTML(XHTMLStream & xs, OutputParams const & rp, if (il.isPassThru()) runparams.pass_thru = true; + xs.startParagraph(false); xhtmlParagraphs(text_, buffer(), xs, runparams); + xs.endParagraph(); if (opts & WriteInnerTag) xs << html::EndTag(il.htmlinnertag()); diff --git a/src/output_xhtml.cpp b/src/output_xhtml.cpp index c6b3c7875d..da199111c9 100644 --- a/src/output_xhtml.cpp +++ b/src/output_xhtml.cpp @@ -832,25 +832,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; + // 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(); - if (opened) - openParTag(xs, lay, par->params(), - make_parid ? par->magicLabel() : ""); - - docstring const deferred = - par->simpleLyXHTMLOnePar(buf, xs, runparams, text.outerFont(distance(begin, par))); + bool const opened = 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,25 @@ ParagraphList::const_iterator makeParagraphs(Buffer const & buf, bool const needclose = (opened && (!runparams.html_in_par || nextpar != pend)) || (!opened && runparams.html_in_par && par == pbegin && nextpar != pend); + + if (opened) { + // 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)), + opened, needclose); + + if (!deferred.empty()) { + xs << XHTMLStream::ESCAPE_NONE << deferred << html::CR(); + } if (needclose) { closeTag(xs, lay); xs << html::CR(); } - if (!deferred.empty()) { - xs << XHTMLStream::ESCAPE_NONE << deferred << html::CR(); - } } return pend; } @@ -995,7 +1008,7 @@ ParagraphList::const_iterator makeEnvironment(Buffer const & buf, openItemTag(xs, style, par->params()); par->simpleLyXHTMLOnePar(buf, xs, runparams, - text.outerFont(distance(begin, par)), sep); + text.outerFont(distance(begin, par)), true, true, sep); ++par; // We may not want to close the tag yet, in particular: diff --git a/status.22x b/status.22x index d97237088e..2660366e0e 100644 --- a/status.22x +++ b/status.22x @@ -71,6 +71,8 @@ What's new * LYXHTML +Fix problem with output of branches (bug 8022). + * TEX2LYX