On Sun, Jun 11, 2017 at 01:08:34AM +0200, Enrico Forestieri wrote: > On Mon, Oct 17, 2016 at 00:16:21AM +0200, Guillaume Munch wrote: > > > commit 676a0639c505d52336e3228c44c2515ccbbaf34a > > Author: Guillaume Munch <g...@lyx.org> > > Date: Sat Sep 24 00:49:00 2016 +0200 > > > > Use otexstringstream for the captions of InsetCaptionables > > > > * Enable TexRow for InsetListings caption. > > > > * Move getCaption* from InsetText to InsetCaptionable. > > > > * Clean-up caption generation for InsetFloat. > [...] > > @@ -420,7 +417,11 @@ docstring InsetListings::getCaption(OutputParams const > > & runparams) const > > // NOTE that } is not allowed in blah2. > > regex const reg("(.*)\\\\label\\{(.*?)\\}(.*)"); > > string const new_cap("$1$3},label={$2"); > > - return from_utf8(regex_replace(to_utf8(cap), reg, new_cap)); > > + // TexString validity: the substitution preserves the number of > > newlines. > > + // Moreover we assume that $2 does not contain newlines, so that the > > texrow > > + // information remains accurate. > > + cap.str = from_utf8(regex_replace(to_utf8(cap.str), reg, new_cap)); > > + return cap; > > } > > > > > > This commit broke the caption handling in InsetListings. For example, > the document attached at #9382: > https://www.lyx.org/trac/raw-attachment/ticket/9382/problem.20_nopreamble.lyx > now fails to compile. It can be compiled again with the attached patch, > which is not the right one, of course.
The attached patch should instead work always, or almost so. -- Enrico
diff --git a/src/insets/InsetListings.cpp b/src/insets/InsetListings.cpp index b847131f57..cf5892edec 100644 --- a/src/insets/InsetListings.cpp +++ b/src/insets/InsetListings.cpp @@ -515,7 +515,11 @@ TexString InsetListings::getCaption(OutputParams const & runparams) const // TexString validity: the substitution preserves the number of newlines. // Moreover we assume that $2 does not contain newlines, so that the texrow // information remains accurate. - cap.str = from_utf8(regex_replace(to_utf8(cap.str), reg, new_cap)); + // Replace '\n' with an improbable character from Private Use Area-A + // and then return to '\n' after the regex replacement. + docstring const capstr = subst(cap.str, char_type('\n'), 0xffffd); + cap.str = subst(from_utf8(regex_replace(to_utf8(capstr), reg, new_cap)), + 0xffffd, char_type('\n')); return cap; }