From 9b4ee44620ecde1c057e3c4f52b17e8eb692eeb6 Mon Sep 17 00:00:00 2001 From: Georg Baum Date: Fri, 28 Jan 2011 21:20:48 +0000 Subject: [PATCH] Improve roundtrip of Customization.lyx: 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 | 2 +- src/tex2lyx/text.cpp | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/src/tex2lyx/TODO.txt b/src/tex2lyx/TODO.txt index 97586f361a..267772bd32 100644 --- a/src/tex2lyx/TODO.txt +++ b/src/tex2lyx/TODO.txt @@ -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 diff --git a/src/tex2lyx/text.cpp b/src/tex2lyx/text.cpp index 23435d9337..b82d1686e8 100644 --- a/src/tex2lyx/text.cpp +++ b/src/tex2lyx/text.cpp @@ -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); -- 2.39.2