commit 95bc23133ac6d1ad19afea8d812f49df648be9b1
Author: Jean-Marc Lasgouttes <[email protected]>
Date:   Wed Sep 9 11:47:47 2015 +0200

    tex2lyx: Add a newline at the end of comment if not at the end of a 
paragraph.
    
    When importing TeX code like
      %comment
      TEXT
    the LyX document currently becomes
      [ERT %comment] TEXT
    so that TEXT is now part of the comment.
    
    Now output_comment adds a trailing newline if the token after the
    comment is not a newline. Note that the newline that marks the end of
    the comment has already been parsed at this point.
    
    tex2lyx tests have been checked manually and updated.
    
    Fixes ticket #9551.

diff --git a/src/tex2lyx/test/CJK.lyx.lyx b/src/tex2lyx/test/CJK.lyx.lyx
index 5a73840..62e9251 100644
--- a/src/tex2lyx/test/CJK.lyx.lyx
+++ b/src/tex2lyx/test/CJK.lyx.lyx
@@ -166,6 +166,10 @@ status collapsed
 % The following Bg5 encoded text cannot be processed as is by latex.
 \end_layout
 
+\begin_layout Plain Layout
+
+\end_layout
+
 \end_inset
 
 
@@ -176,6 +180,10 @@ status collapsed
 % It needs to be preprocessed by bg5conv or bg5latex needs to be used.
 \end_layout
 
+\begin_layout Plain Layout
+
+\end_layout
+
 \end_inset
 
 
@@ -212,6 +220,10 @@ status collapsed
 % The following SJIS encoded text cannot be processed as is by latex.
 \end_layout
 
+\begin_layout Plain Layout
+
+\end_layout
+
 \end_inset
 
 
@@ -222,6 +234,10 @@ status collapsed
 % It needs to be preprocessed by sjisconv or sjislatex needs to be used.
 \end_layout
 
+\begin_layout Plain Layout
+
+\end_layout
+
 \end_inset
 
 
diff --git a/src/tex2lyx/test/XeTeX-polyglossia.lyx.lyx 
b/src/tex2lyx/test/XeTeX-polyglossia.lyx.lyx
index bcf4c0f..02e9db4 100644
--- a/src/tex2lyx/test/XeTeX-polyglossia.lyx.lyx
+++ b/src/tex2lyx/test/XeTeX-polyglossia.lyx.lyx
@@ -174,6 +174,10 @@ status collapsed
 %empty language paragraph
 \end_layout
 
+\begin_layout Plain Layout
+
+\end_layout
+
 \end_inset
 
 
diff --git a/src/tex2lyx/test/box-color-size-space-align.lyx.lyx 
b/src/tex2lyx/test/box-color-size-space-align.lyx.lyx
index 74ee1a4..a171f67 100644
--- a/src/tex2lyx/test/box-color-size-space-align.lyx.lyx
+++ b/src/tex2lyx/test/box-color-size-space-align.lyx.lyx
@@ -1617,6 +1617,10 @@ status collapsed
 %set back to justified
 \end_layout
 
+\begin_layout Plain Layout
+
+\end_layout
+
 \end_inset
 
 
diff --git a/src/tex2lyx/test/test-insets.lyx.lyx 
b/src/tex2lyx/test/test-insets.lyx.lyx
index c60454e..57d8556 100644
--- a/src/tex2lyx/test/test-insets.lyx.lyx
+++ b/src/tex2lyx/test/test-insets.lyx.lyx
@@ -111,6 +111,10 @@ status collapsed
 %stupid stuff
 \end_layout
 
+\begin_layout Plain Layout
+
+\end_layout
+
 \end_inset
 
 
@@ -648,6 +652,10 @@ status collapsed
 bibliography since LaTeX throws an error.
 \end_layout
 
+\begin_layout Plain Layout
+
+\end_layout
+
 \end_inset
 
 
@@ -660,6 +668,10 @@ status collapsed
 bibliographystyle{unsrt}
 \end_layout
 
+\begin_layout Plain Layout
+
+\end_layout
+
 \end_inset
 
 
@@ -4419,6 +4431,10 @@ status collapsed
 % some comment
 \end_layout
 
+\begin_layout Plain Layout
+
+\end_layout
+
 \end_inset
 
 
@@ -6929,6 +6945,10 @@ status collapsed
 % and another
 \end_layout
 
+\begin_layout Plain Layout
+
+\end_layout
+
 \end_inset
 
 
diff --git a/src/tex2lyx/test/test-structure.lyx.lyx 
b/src/tex2lyx/test/test-structure.lyx.lyx
index f2f942d..d77b837 100644
--- a/src/tex2lyx/test/test-structure.lyx.lyx
+++ b/src/tex2lyx/test/test-structure.lyx.lyx
@@ -123,6 +123,10 @@ status collapsed
 % this should be recognized as empty date:
 \end_layout
 
+\begin_layout Plain Layout
+
+\end_layout
+
 \end_inset
 
 
diff --git a/src/tex2lyx/test/test.lyx.lyx b/src/tex2lyx/test/test.lyx.lyx
index 29f08e3..e6a1c6c 100644
--- a/src/tex2lyx/test/test.lyx.lyx
+++ b/src/tex2lyx/test/test.lyx.lyx
@@ -119,6 +119,10 @@ status collapsed
 %Midline comment
 \end_layout
 
+\begin_layout Plain Layout
+
+\end_layout
+
 \end_inset
 
 
diff --git a/src/tex2lyx/text.cpp b/src/tex2lyx/text.cpp
index 87af33c..12e20b1 100644
--- a/src/tex2lyx/text.cpp
+++ b/src/tex2lyx/text.cpp
@@ -575,6 +575,16 @@ void output_ert_inset(ostream & os, string const & s, 
Context & context)
 }
 
 
+void output_comment(Parser & p, ostream & os, string const & s,
+                    Context & context)
+{
+       if (p.next_token().cat() == catNewline)
+               output_ert_inset(os, '%' + s, context);
+       else
+               output_ert_inset(os, '%' + s + '\n', context);
+}
+
+
 Layout const * findLayout(TextClass const & textclass, string const & name, 
bool command)
 {
        Layout const * layout = findLayoutWithoutModule(textclass, name, 
command);
@@ -1113,13 +1123,13 @@ void parse_box(Parser & p, ostream & os, unsigned 
outer_flags,
                // LyX puts a % after the end of the minipage
                if (p.next_token().cat() == catNewline && 
p.next_token().cs().size() > 1) {
                        // new paragraph
-                       //output_ert_inset(os, "%dummy", parent_context);
+                       //output_comment(p, os, "dummy", parent_context);
                        p.get_token();
                        p.skip_spaces();
                        parent_context.new_paragraph(os);
                }
                else if (p.next_token().cat() == catSpace || 
p.next_token().cat() == catNewline) {
-                       //output_ert_inset(os, "%dummy", parent_context);
+                       //output_comment(p, os, "dummy", parent_context);
                        p.get_token();
                        p.skip_spaces();
                        // We add a protected space if something real follows
@@ -1795,7 +1805,7 @@ void parse_comment(Parser & p, ostream & os, Token const 
& t, Context & context)
        LASSERT(t.cat() == catComment, return);
        if (!t.cs().empty()) {
                context.check_layout(os);
-               output_ert_inset(os, '%' + t.cs(), context);
+               output_comment(p, os, t.cs(), context);
                if (p.next_token().cat() == catNewline) {
                        // A newline after a comment line starts a new
                        // paragraph
@@ -2752,8 +2762,8 @@ void parse_text(Parser & p, ostream & os, unsigned flags, 
bool outer,
                        context.check_layout(os);
                        // FIXME: This is a hack to prevent paragraph
                        // deletion if it is empty. Handle this better!
-                       output_ert_inset(os,
-                               "%dummy comment inserted by tex2lyx to "
+                       output_comment(p, os,
+                               "dummy comment inserted by tex2lyx to "
                                "ensure that this paragraph is not empty",
                                context);
                        // Both measures above may generate an additional
diff --git a/status.21x b/status.21x
index c578cb9..8c552af 100644
--- a/status.21x
+++ b/status.21x
@@ -69,6 +69,8 @@ What's new
 
 - Fixed a typo in the tutorial.
 
+- Tex2lyx: fix bug with comments immediately folowed by some test (bug 9551).
+
 
 * LYX2LYX
 

Reply via email to