commit c734504d3b4bac795627e1c4fa5b2e27b15e8653
Author: Thibaut Cuvelier <[email protected]>
Date: Fri Dec 24 01:08:24 2021 +0100
DocBook: in InsetFloat, detect the presence of a caption by generating it.
This catches the case where the caption only contains a comment, as in
export/export/latex/lyxbugs-resolved/cprotect/9313-comment-in-figure-float-caption.
No duplicate work is performed to ensure the same level of performance as
before.
---
src/insets/InsetFloat.cpp | 30 ++++++++++++++++++++----------
1 files changed, 20 insertions(+), 10 deletions(-)
diff --git a/src/insets/InsetFloat.cpp b/src/insets/InsetFloat.cpp
index db74e9e..97d8061 100644
--- a/src/insets/InsetFloat.cpp
+++ b/src/insets/InsetFloat.cpp
@@ -774,11 +774,20 @@ void docbookNoSubfigures(XMLStream & xs, OutputParams
const & runparams, const I
rpNoTitle.docbook_in_table = true;
// Generate the contents of the float (to check for emptiness).
- odocstringstream os2;
- XMLStream xs2(os2);
- thisFloat->InsetText::docbook(xs2, rpNoTitle);
+ odocstringstream osFloatContent;
+ XMLStream xsFloatContent(osFloatContent);
+ thisFloat->InsetText::docbook(xsFloatContent, rpNoTitle);
+ bool hasFloat = !osFloatContent.str().empty();
+
+ // Do the same for the caption.
+ odocstringstream osCaptionContent;
+ XMLStream xsCaptionContent(osCaptionContent);
+ caption->getCaptionAsDocBook(xsCaptionContent, rpNoLabel);
+ bool hasCaption = !osCaptionContent.str().empty();
// Organisation: <float> <title if any/> <contents without title/>
</float>.
+
+ // - Generate the attributes for the float tag.
docstring attr = docstring();
if (label)
attr += "xml:id=\"" + xml::cleanID(label->screenLabel()) + "\"";
@@ -789,28 +798,29 @@ void docbookNoSubfigures(XMLStream & xs, OutputParams
const & runparams, const I
}
// - Open the float tag.
- xs << xml::StartTag(ftype.docbookTag(caption != nullptr), attr);
+ xs << xml::StartTag(ftype.docbookTag(hasCaption), attr);
xs << xml::CR();
// - Generate the caption.
- if (caption) {
+ if (hasCaption) {
string const &titleTag = ftype.docbookCaption();
xs << xml::StartTag(titleTag);
- caption->getCaptionAsDocBook(xs, rpNoLabel);
+ xs << XMLStream::ESCAPE_NONE << osCaptionContent.str();
xs << xml::EndTag(titleTag);
xs << xml::CR();
}
- // - Output the actual content of the float.
- if (!os2.str().empty())
- xs << XMLStream::ESCAPE_NONE << os2.str();
+ // - Output the actual content of the float or some dummy content (to
ensure that the output
+ // document is valid).
+ if (hasFloat)
+ xs << XMLStream::ESCAPE_NONE << osFloatContent.str();
else if (ftype.docbookFloatType() == "table")
docbookGenerateFillerTable(xs,
thisFloat->buffer().params().docbook_table_output);
else
docbookGenerateFillerMedia(xs);
// - Close the float.
- xs << xml::EndTag(ftype.docbookTag(caption != nullptr));
+ xs << xml::EndTag(ftype.docbookTag(hasCaption));
xs << xml::CR();
}
--
lyx-cvs mailing list
[email protected]
http://lists.lyx.org/mailman/listinfo/lyx-cvs