}
-void parse_listings(Parser & p, ostream & os, Context & parent_context)
+void parse_listings(Parser & p, ostream & os, Context & parent_context, bool in_line)
{
parent_context.check_layout(os);
begin_inset(os, "listings\n");
- os << "inline false\n"
- << "status collapsed\n";
+ if (p.hasOpt()) {
+ // there can be a [] pair inside the argument for the language
+ string arg = p.getArg('[', ']');
+ if (arg.find("language={[") != string::npos) {
+ char start = p.next_token().character();
+ arg += ']';
+ arg += start;
+ arg += p.getArg(start, ']');
+ }
+ os << "lstparams " << '"' << arg << '"' << '\n';
+ }
+ if (in_line)
+ os << "inline true\n";
+ else
+ os << "inline false\n";
+ os << "status collapsed\n";
Context context(true, parent_context.textclass);
context.layout = &parent_context.textclass.plainLayout();
- context.check_layout(os);
- string const s = p.verbatimEnvironment("lstlisting");
+ string s;
+ if (in_line) {
+ s = p.plainCommand('!', '!', "lstinline");
+ context.new_paragraph(os);
+ context.check_layout(os);
+ } else
+ s = p.plainEnvironment("lstlisting");
for (string::const_iterator it = s.begin(), et = s.end(); it != et; ++it) {
if (*it == '\\')
os << "\n\\backslash\n";
// we must make sure that the next item gets a \begin_layout.
parent_context.new_paragraph(os);
p.skip_spaces();
- preamble.registerAutomaticallyLoadedPackage("rotfloat");
+ preamble.registerAutomaticallyLoadedPackage("rotfloat");
}
else if (name == "wrapfigure" || name == "wraptable") {
// we must make sure that the next item gets a \begin_layout.
parent_context.new_paragraph(os);
p.skip_spaces();
- preamble.registerAutomaticallyLoadedPackage("wrapfig");
+ preamble.registerAutomaticallyLoadedPackage("wrapfig");
}
else if (name == "minipage") {
}
else if (name == "verbatim") {
- eat_whitespace(p, os, parent_context, false);
- os << "\n\\begin_layout Verbatim\n";
- string const s = p.verbatimEnvironment("verbatim");
+ os << "\n\\end_layout\n\n\\begin_layout Verbatim\n";
+ string const s = p.plainEnvironment("verbatim");
string::const_iterator it2 = s.begin();
for (string::const_iterator it = s.begin(), et = s.end(); it != et; ++it) {
- if (*it == '\n') {
+ if (*it == '\\')
+ os << "\\backslash ";
+ else if (*it == '\n') {
it2 = it + 1;
// avoid adding an empty paragraph at the end
- // if there are 2 consecutive spaces at the end ignore it
+ // FIXME: if there are 2 consecutive spaces at the end ignore it
// because LyX will re-add a \n
+ // This hack must be removed once bug 8049 is fixed!
if ((it + 1 != et) && (it + 2 != et || *it2 != '\n'))
os << "\n\\end_layout\n\\begin_layout Verbatim\n";
- } else
+ } else
os << *it;
}
os << "\n\\end_layout\n\n";
p.skip_spaces();
- skip_braces(p); // eat {} that might by set by LyX behind comments
// reset to Standard layout
os << "\n\\begin_layout Standard\n";
}
else if (name == "lstlisting") {
eat_whitespace(p, os, parent_context, false);
- // FIXME handle listings with parameters
- // If this is added, don't forgot to handle the
- // automatic color package loading
- if (p.hasOpt())
- parse_unknown_environment(p, name, os, FLAG_END,
- outer, parent_context);
- else
- parse_listings(p, os, parent_context);
+ // FIXME handle the automatic color package loading
+ // uwestoehr asks: In what case color is loaded?
+ parse_listings(p, os, parent_context, false);
p.skip_spaces();
}
end_inset(os);
}
+ else if (t.cs() == "lstinline") {
+ p.skip_spaces();
+ parse_listings(p, os, context, true);
+ }
+
else if (t.cs() == "ensuremath") {
p.skip_spaces();
context.check_layout(os);
btprint = key;
}
- else if (t.cs() == "index") {
+ else if (t.cs() == "index" ||
+ (t.cs() == "sindex" && preamble.use_indices() == "true")) {
context.check_layout(os);
- begin_inset(os, "Index idx\n");
- os << "status collapsed\n";
+ string const arg = (t.cs() == "sindex" && p.hasOpt()) ?
+ p.getArg('[', ']') : "";
+ string const kind = arg.empty() ? "idx" : arg;
+ begin_inset(os, "Index ");
+ os << kind << "\nstatus collapsed\n";
parse_text_in_inset(p, os, FLAG_ITEM, false, context, "Index");
end_inset(os);
+ if (kind != "idx")
+ preamble.registerAutomaticallyLoadedPackage("splitidx");
}
else if (t.cs() == "nomenclature") {