#include "support/docstream.h"
#include "support/lstrings.h"
+#include <boost/regex.hpp>
+
#include <sstream>
using namespace std;
namespace lyx {
+using boost::regex;
char const lstinline_delimiters[] =
"!*()-=+|;:'\"`,<.>/?QWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnm";
-InsetListings::InsetListings(BufferParams const & bp, InsetListingsParams const & par)
- : InsetCollapsable(bp, par.status())
-{}
-
-
-InsetListings::InsetListings(InsetListings const & in)
- : InsetCollapsable(in), params_(in.params_)
+InsetListings::InsetListings(Buffer const & buf, InsetListingsParams const & par)
+ : InsetCollapsable(buf, par.status())
{}
-Inset * InsetListings::clone() const
-{
- return new InsetListings(*this);
-}
-
-
InsetListings::~InsetListings()
{
InsetListingsMailer(*this).hideDialog();
}
-void InsetListings::updateLabels(Buffer const & buf, ParIterator const & it)
+void InsetListings::updateLabels(ParIterator const & it)
{
- Counters & cnts = buf.params().getTextClass().counters();
+ Counters & cnts = buffer().params().documentClass().counters();
string const saveflt = cnts.current_float();
// Tell to captions what the current float is
cnts.current_float("listing");
- InsetCollapsable::updateLabels(buf, it);
+ InsetCollapsable::updateLabels(it);
//reset afterwards
cnts.current_float(saveflt);
}
-void InsetListings::write(Buffer const & buf, ostream & os) const
+void InsetListings::write(ostream & os) const
{
os << "listings" << "\n";
InsetListingsParams const & par = params();
os << "inline true\n";
else
os << "inline false\n";
- InsetCollapsable::write(buf, os);
+ InsetCollapsable::write(os);
}
-void InsetListings::read(Buffer const & buf, Lexer & lex)
+void InsetListings::read(Lexer & lex)
{
while (lex.isOK()) {
lex.next();
break;
}
}
- InsetCollapsable::read(buf, lex);
+ InsetCollapsable::read(lex);
}
-docstring const InsetListings::editMessage() const
+docstring InsetListings::editMessage() const
{
return _("Opened Listing Inset");
}
-int InsetListings::latex(Buffer const & buf, odocstream & os,
- OutputParams const & runparams) const
+int InsetListings::latex(odocstream & os, OutputParams const & runparams) const
{
string param_string = params().params();
// NOTE: I use {} to quote text, which is an experimental feature
// but real_current_font moved to cursor.
//rp.local_font = &text_.real_current_font;
rp.moving_arg = true;
- docstring const caption = getCaption(buf, rp);
+ docstring const caption = getCaption(rp);
runparams.encoding = rp.encoding;
if (param_string.empty() && caption.empty())
os << "\n\\begingroup\n\\inputencoding{latin1}\n\\begin{lstlisting}\n";
}
-docstring InsetListings::getCaption(Buffer const & buf,
- OutputParams const & runparams) const
+docstring InsetListings::getCaption(OutputParams const & runparams) const
{
if (paragraphs().empty())
return docstring();
odocstringstream ods;
InsetCaption * ins =
static_cast<InsetCaption *>(it->inset);
- ins->getOptArg(buf, ods, runparams);
- ins->getArgument(buf, ods, runparams);
- return ods.str();
+ ins->getOptArg(ods, runparams);
+ ins->getArgument(ods, runparams);
+ // 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));
}
}
}