From 3f07ae9083ab7299f9bc63a8f7749ce94e9aea6e Mon Sep 17 00:00:00 2001 From: Thibaut Cuvelier Date: Fri, 27 Nov 2020 05:19:27 +0100 Subject: [PATCH] DocBook: for empty figures, output a message. This ensures that this part of the DocBook file is valid. --- development/autotests/invertedTests | 2 +- src/insets/InsetFloat.cpp | 28 +++++++++++++++++++++++++--- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/development/autotests/invertedTests b/development/autotests/invertedTests index e40d0d85e6..edf4c597bf 100644 --- a/development/autotests/invertedTests +++ b/development/autotests/invertedTests @@ -498,7 +498,7 @@ export/examples/(es|fr)/Modules/Linguistics_docbook5 export/examples/ko/cjk-ko-doc_docbook5 # - Metadata in abstract paragraph. export/templates/Articles/Springers_Global_Journal_Template_%28V._3%29_docbook5 -# - Sweave impossible to implement. Document irremediably wrong (no .bib file, still referenced in the text). +# - Sweave impossible to implement. Broken references (no .bib file, still referenced in the text). export/templates/Articles/R_Journal_docbook5 # - Forbidden inlines, equation in formatting, broken references, float in paragraphs, videos. export/templates/Articles/REVTeX_%28V._4.1%29_docbook5 diff --git a/src/insets/InsetFloat.cpp b/src/insets/InsetFloat.cpp index 2dfd53c9a9..e432fa05de 100644 --- a/src/insets/InsetFloat.cpp +++ b/src/insets/InsetFloat.cpp @@ -731,6 +731,11 @@ void docbookNoSubfigures(XMLStream & xs, OutputParams const & runparams, const I if (ftype.docbookFloatType() == "table") rpNoTitle.docbook_in_table = true; + // Generate the contents of the float (to check for emptiness). + odocstringstream os2; + XMLStream xs2(os2); + thisFloat->InsetText::docbook(xs, rpNoTitle); + // Organisation: <contents without title/> </float>. docstring attr = docstring(); if (label) @@ -749,7 +754,24 @@ void docbookNoSubfigures(XMLStream & xs, OutputParams const & runparams, const I xs << xml::EndTag(titleTag); xs << xml::CR(); } - thisFloat->InsetText::docbook(xs, rpNoTitle); + + if (!os2.str().empty()) { + xs << XMLStream::ESCAPE_NONE << os2.str(); + } else { + xs << xml::StartTag("mediaobject"); + xs << xml::CR(); + xs << xml::StartTag("textobject"); + xs << xml::CR(); + xs << xml::StartTag("phrase"); + xs << "This figure is empty."; + xs << xml::EndTag("phrase"); + xs << xml::CR(); + xs << xml::EndTag("textobject"); + xs << xml::CR(); + xs << xml::EndTag("mediaobject"); + xs << xml::CR(); + } + xs << xml::EndTag(ftype.docbookTag(caption != nullptr)); xs << xml::CR(); } @@ -777,8 +799,8 @@ void InsetFloat::docbook(XMLStream & xs, OutputParams const & runparams) const } // Gather a few things from global environment that are shared between all following cases. - FloatList const &floats = buffer().params().documentClass().floats(); - Floating const &ftype = floats.getType(params_.type); + FloatList const & floats = buffer().params().documentClass().floats(); + Floating const & ftype = floats.getType(params_.type); // Switch on subfigures. if (!subfigures.empty()) -- 2.39.5