namespace lyx {
using support::token;
+using support::contains;
+using support::subst;
using std::auto_ptr;
using std::istringstream;
using std::ostringstream;
using std::string;
+char const lstinline_delimiters[] = "!@#$^&*()-_=+|;:'\"~`,<.>/?QWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnm";
void InsetListings::init()
{
// of the listings package (see page 25 of the manual)
int lines = 0;
bool lstinline = params().isInline();
- if (lstinline) {
- if (param_string.empty())
- os << "\\lstinline{";
- else
- os << "\\lstinline[" << from_ascii(param_string) << "]{";
- } else {
- docstring const caption = getCaption(buf, runparams);
- if (param_string.empty() && caption.empty())
- os << "\n\\begingroup\n\\inputencoding{latin1}\n\\begin{lstlisting}\n";
- else {
- os << "\n\\begingroup\n\\inputencoding{latin1}\n\\begin{lstlisting}[";
- if (!caption.empty()) {
- os << "caption={" << caption << '}';
- if (!param_string.empty())
- os << ',';
- }
- os << from_utf8(param_string) << "]\n";
- }
- lines += 4;
- }
+ // get the paragraphs. We can not output them directly to given odocstream
+ // because we can not yet determine the delimiter character of \lstinline
+ docstring code;
ParagraphList::const_iterator par = paragraphs().begin();
ParagraphList::const_iterator end = paragraphs().end();
// ignore all struck out text and (caption) insets
if (par->isDeleted(i) || par->isInset(i))
continue;
- os.put(par->getChar(i));
+ code += par->getChar(i);
}
++par;
// for the inline case, if there are multiple paragraphs
// they are simply joined. Otherwise, expect latex errors.
if (par != end && !lstinline && !captionline) {
- os << "\n";
+ code += "\n";
++lines;
}
}
+ char const * delimiter;
+ if (lstinline) {
+ for (delimiter = lstinline_delimiters; delimiter != '\0'; ++delimiter)
+ if (!contains(code, *delimiter))
+ break;
+ // this code piece contains all possible special character? !!!
+ // Replace ! with a warning message and use ! as delimiter.
+ if (*delimiter == '\0') {
+ code = subst(code, from_ascii("!"), from_ascii(" WARNING: no lstline delimiter can be used "));
+ delimiter = lstinline_delimiters;
+ }
+ if (param_string.empty())
+ os << "\\lstinline" << *delimiter;
+ else
+ os << "\\lstinline[" << from_ascii(param_string) << "]" << *delimiter;
+ } else {
+ docstring const caption = getCaption(buf, runparams);
+ if (param_string.empty() && caption.empty())
+ os << "\n\\begingroup\n\\inputencoding{latin1}\n\\begin{lstlisting}\n";
+ else {
+ os << "\n\\begingroup\n\\inputencoding{latin1}\n\\begin{lstlisting}[";
+ if (!caption.empty()) {
+ os << "caption={" << caption << '}';
+ if (!param_string.empty())
+ os << ',';
+ }
+ os << from_utf8(param_string) << "]\n";
+ }
+ lines += 4;
+ }
+ os << code;
if (lstinline)
- os << "}";
+ os << *delimiter;
else {
os << "\n\\end{lstlisting}\n\\endgroup\n";
lines += 3;