]> git.lyx.org Git - features.git/commitdiff
Improve roundtrip of Customization.lyx:
authorGeorg Baum <Georg.Baum@post.rwth-aachen.de>
Fri, 28 Jan 2011 21:20:48 +0000 (21:20 +0000)
committerGeorg Baum <Georg.Baum@post.rwth-aachen.de>
Fri, 28 Jan 2011 21:20:48 +0000 (21:20 +0000)
The lstlistings environment is no longer be unknown.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@37355 a592a061-630c-0410-9148-cb99ea01b6c8

src/tex2lyx/TODO.txt
src/tex2lyx/text.cpp

index 97586f361a94d3529c11ed63906d11ef0fdb7192..267772bd324e36035c66dc9dc3c48168a8d2a78a 100644 (file)
@@ -26,7 +26,7 @@ Format LaTeX feature                        LyX feature
 266    armenian                             \language, \lang
 267    XeTeX                                utf8 encoding
 268    CJK.sty                              CJK encodings, languages
-269    listings.sty                         InsetListings
+269    listings.sty (inline, with args)     InsetListings
 270    \alert, \structure (beamer)          layout
 281    ?                                    modules
 284    wrapfig.sty                          InsetWrap
index 23435d93374c7ba491b9fc5b81163d39b3924a00..b82d1686e89c2e0b5a195f17f43e20f06bad548c 100644 (file)
@@ -925,6 +925,33 @@ void parse_outer_box(Parser & p, ostream & os, unsigned flags, bool outer,
 }
 
 
+void parse_listings(Parser & p, ostream & os, Context & parent_context)
+{
+       parent_context.check_layout(os);
+       begin_inset(os, "listings\n");
+       os << "inline false\n"
+          << "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");
+       for (string::const_iterator it = s.begin(), et = s.end(); it != et; ++it) {
+               if (*it == '\\')
+                       os << "\n\\backslash\n";
+               else if (*it == '\n') {
+                       // avoid adding an empty paragraph at the end
+                       if (it + 1 != et) {
+                               context.new_paragraph(os);
+                               context.check_layout(os);
+                       }
+               } else
+                       os << *it;
+       }
+       context.check_end_layout(os);
+       end_inset(os);
+}
+
+
 /// parse an unknown environment
 void parse_unknown_environment(Parser & p, string const & name, ostream & os,
                               unsigned flags, bool outer,
@@ -1030,6 +1057,17 @@ void parse_environment(Parser & p, ostream & os, bool outer,
                p.skip_spaces();
        }
 
+       else if (name == "lstlisting") {
+               eat_whitespace(p, os, parent_context, false);
+               // FIXME handle listings with parameters
+               if (p.hasOpt())
+                       parse_unknown_environment(p, name, os, FLAG_END,
+                                                 outer, parent_context);
+               else
+                       parse_listings(p, os, parent_context);
+               p.skip_spaces();
+       }
+
        else if (!parent_context.new_layout_allowed)
                parse_unknown_environment(p, name, os, FLAG_END, outer,
                                          parent_context);