From 6434b666bf68afc3965396351cde86db080daa4f Mon Sep 17 00:00:00 2001 From: Thibaut Cuvelier Date: Fri, 31 Jul 2020 00:55:00 +0200 Subject: [PATCH] DocBook: don't output abstract if it would have no content. Restore a change from e709a662 (reverted by d75ff993) that was mixed into another commit. Also, add a TODO for InsetIndex. --- src/insets/InsetIndex.cpp | 1 + src/output_docbook.cpp | 29 +++++++++++++++++++---------- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/src/insets/InsetIndex.cpp b/src/insets/InsetIndex.cpp index 83b3be186e..987c138321 100644 --- a/src/insets/InsetIndex.cpp +++ b/src/insets/InsetIndex.cpp @@ -199,6 +199,7 @@ void InsetIndex::docbook(XMLStream & xs, OutputParams const & runparams) const "Complete entry: \"") + latexString + from_utf8("\""); LYXERR0(error); xs << XMLStream::ESCAPE_NONE << (from_utf8("\n")); + // TODO: implement @ using the sortas attribute (on primary, secondary, tertiary). } // Handle several indices. diff --git a/src/output_docbook.cpp b/src/output_docbook.cpp index 33d9910912..c5519de5c9 100644 --- a/src/output_docbook.cpp +++ b/src/output_docbook.cpp @@ -39,6 +39,7 @@ #include #include #include +#include using namespace std; using namespace lyx::support; @@ -863,17 +864,25 @@ void outputDocBookInfo( generateDocBookParagraphWithoutSectioning(text, buf, xs, runparams, paragraphs, bpitInfo, epitInfo); if (hasAbstract) { - string tag = paragraphs[bpitAbstract].layout().docbookforceabstracttag(); - if (tag == "NONE") - tag = "abstract"; + // Sometimes, there are many paragraphs that should go into the abstract, but none generates actual content. + // Thus, first generate to a temporary stream, then only create the tag if these paragraphs + // generate some content. + odocstringstream os2; + XMLStream xs2(os2); + generateDocBookParagraphWithoutSectioning(text, buf, xs2, runparams, paragraphs, bpitAbstract, epitAbstract); - xs << xml::StartTag(tag); - xs << xml::CR(); - xs.startDivision(false); - generateDocBookParagraphWithoutSectioning(text, buf, xs, runparams, paragraphs, bpitAbstract, epitAbstract); - xs.endDivision(); - xs << xml::EndTag(tag); - xs << xml::CR(); + // Actually output the abstract if there is something to do. + if (!os2.str().empty()) { + string tag = paragraphs[bpitAbstract].layout().docbookforceabstracttag(); + if (tag == "NONE") + tag = "abstract"; + + xs << xml::StartTag(tag); + xs << xml::CR(); + xs << XMLStream::ESCAPE_NONE << os2.str(); + xs << xml::EndTag(tag); + xs << xml::CR(); + } } // End the tag if it was started.