From: Juergen Spitzmueller Date: Tue, 1 Nov 2022 09:20:50 +0000 (+0100) Subject: Handle empty index subentries (#7820) X-Git-Tag: 2.4-beta2~436 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=fd5adacef25eb40f813dedd961920c353448213a;p=lyx.git Handle empty index subentries (#7820) --- diff --git a/src/insets/InsetIndex.cpp b/src/insets/InsetIndex.cpp index 13a7b4d1df..b3024bf74c 100644 --- a/src/insets/InsetIndex.cpp +++ b/src/insets/InsetIndex.cpp @@ -160,7 +160,7 @@ void InsetIndex::latex(otexstream & ios, OutputParams const & runparams_in) cons getSortkey(os, runparams); os << "@"; os << ourlatex.str(); - getSubentries(os, runparams); + getSubentries(os, runparams, ourlatex.str()); if (hasSeeRef()) { os << "|"; os << insetindexpagerangetranslator_latex().find(params_.range); @@ -214,7 +214,7 @@ void InsetIndex::latex(otexstream & ios, OutputParams const & runparams_in) cons odocstringstream subentries; otexstream otsub(subentries); - getSubentries(otsub, runparams); + getSubentries(otsub, runparams, ourlatex.str()); if (subentries.str().empty()) { // Separate the entries and subentries, i.e., split on "!". // This goes wrong on an escaped "!", but as the escape @@ -230,6 +230,12 @@ void InsetIndex::latex(otexstream & ios, OutputParams const & runparams_in) cons vector::const_iterator it2 = levels_plain.begin(); bool first = true; for (; it != end; ++it) { + if ((*it).empty()) { + emptySubentriesWarning(ourlatex.str()); + if (it2 < levels_plain.end()) + ++it2; + continue; + } // The separator needs to be put back when // writing the levels, except for the first level if (!first) @@ -668,7 +674,22 @@ docstring InsetIndex::getSortkeyAsText(OutputParams const & runparams) const } -void InsetIndex::getSubentries(otexstream & os, OutputParams const & runparams) const +void InsetIndex::emptySubentriesWarning(docstring const & mainentry) const +{ + // Empty subentries crash makeindex. So warn and ignore this. + TeXErrors terr; + ErrorList & errorList = buffer().errorList("Export"); + docstring const s = bformat(_("There is an empty index subentry in the entry '%1$s'.\n" + "It will be ignored in the output."), mainentry); + Paragraph const & par = buffer().paragraphs().front(); + errorList.push_back(ErrorItem(_("Empty index subentry!"), s, + {par.id(), 0}, {par.id(), -1})); + buffer().bufferErrors(terr, errorList); +} + + +void InsetIndex::getSubentries(otexstream & os, OutputParams const & runparams, + docstring const & mainentry) const { Paragraph const & par = paragraphs().front(); InsetList::const_iterator it = par.insetList().begin(); @@ -679,6 +700,10 @@ void InsetIndex::getSubentries(otexstream & os, OutputParams const & runparams) InsetIndexMacro const & iim = static_cast(inset); if (iim.params().type == InsetIndexMacroParams::Subentry) { + if (iim.hasNoContent()) { + emptySubentriesWarning(mainentry); + continue; + } ++i; if (i > 2) return; diff --git a/src/insets/InsetIndex.h b/src/insets/InsetIndex.h index 1aaf2d79f3..742ecae545 100644 --- a/src/insets/InsetIndex.h +++ b/src/insets/InsetIndex.h @@ -102,7 +102,9 @@ private: /// docstring getSortkeyAsText(OutputParams const &) const; /// - void getSubentries(otexstream &, OutputParams const &) const; + void emptySubentriesWarning(docstring const & mainentry) const; + /// + void getSubentries(otexstream &, OutputParams const &, docstring const &) const; /// std::vector getSubentriesAsText(OutputParams const &, bool const asLabel = false) const; diff --git a/src/insets/InsetIndexMacro.cpp b/src/insets/InsetIndexMacro.cpp index 31754308f8..e4dc167ca3 100644 --- a/src/insets/InsetIndexMacro.cpp +++ b/src/insets/InsetIndexMacro.cpp @@ -205,6 +205,12 @@ docstring InsetIndexMacro::getXhtml(XMLStream & xs, OutputParams const & runpara } +bool InsetIndexMacro::hasNoContent() const +{ + return paragraphs().front().empty(); +} + + void InsetIndexMacro::doDispatch(Cursor & cur, FuncRequest & cmd) { switch (cmd.action()) { diff --git a/src/insets/InsetIndexMacro.h b/src/insets/InsetIndexMacro.h index 3d56e399de..07109f8faf 100644 --- a/src/insets/InsetIndexMacro.h +++ b/src/insets/InsetIndexMacro.h @@ -66,6 +66,8 @@ public: int getPlaintext(odocstringstream &, OutputParams const &, size_t) const; /// void getDocbook(XMLStream &, OutputParams const &) const; + /// + bool hasNoContent() const; private: /// InsetCode lyxCode() const override;