From 8753847055d89ceddc670fd9758c7dd665f899ab Mon Sep 17 00:00:00 2001 From: Bo Peng Date: Thu, 20 Mar 2008 16:04:22 +0000 Subject: [PATCH] Listings: Move \label{} outside of caption={} git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@23853 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/insets/InsetListings.cpp | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/insets/InsetListings.cpp b/src/insets/InsetListings.cpp index 1499790088..2768b831da 100644 --- a/src/insets/InsetListings.cpp +++ b/src/insets/InsetListings.cpp @@ -30,6 +30,8 @@ #include "support/docstream.h" #include "support/lstrings.h" +#include + #include using namespace std; @@ -37,6 +39,7 @@ using namespace lyx::support; namespace lyx { +using boost::regex; char const lstinline_delimiters[] = "!*()-=+|;:'\"`,<.>/?QWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnm"; @@ -276,7 +279,22 @@ docstring InsetListings::getCaption(OutputParams const & runparams) const static_cast(it->inset); ins->getOptArg(ods, runparams); ins->getArgument(ods, runparams); - return ods.str(); + // the caption may contain \label{} but the listings + // package prefer caption={}, label={} + docstring cap = ods.str(); + if (!contains(to_utf8(cap), "\\label{")) + return cap; + // convert from + // blah1\label{blah2} blah3 + // to + // blah1 blah3},label={blah2 + // to form options + // caption={blah1 blah3},label={blah2} + // + // 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)); } } } -- 2.39.2