Author: baum
Date: Sun Nov 13 11:43:30 2011
New Revision: 40183
URL: http://www.lyx.org/trac/changeset/40183

Log:
Fix bug #7663: Misparsing of description \item with spaces

Modified:
   lyx-devel/branches/BRANCH_2_0_X/   (props changed)
   lyx-devel/branches/BRANCH_2_0_X/src/Paragraph.cpp
   lyx-devel/branches/BRANCH_2_0_X/src/tex2lyx/   (props changed)
   lyx-devel/branches/BRANCH_2_0_X/src/tex2lyx/test/test-structure.tex
   lyx-devel/branches/BRANCH_2_0_X/src/tex2lyx/text.cpp
   lyx-devel/branches/BRANCH_2_0_X/status.20x

Modified: lyx-devel/branches/BRANCH_2_0_X/src/Paragraph.cpp
==============================================================================
--- lyx-devel/branches/BRANCH_2_0_X/src/Paragraph.cpp   Sun Nov 13 11:40:07 
2011        (r40182)
+++ lyx-devel/branches/BRANCH_2_0_X/src/Paragraph.cpp   Sun Nov 13 11:43:30 
2011        (r40183)
@@ -2307,6 +2307,10 @@
        if (body_pos > 0) {
                // the optional argument is kept in curly brackets in
                // case it contains a ']'
+               // This is not strictly needed, but if this is changed it
+               // would be a file format change, and tex2lyx would need
+               // to be adjusted, since it unconditionally removes the
+               // braces when it parses \item.
                os << "[{";
                column += 2;
                basefont = getLabelFont(bparams, outerfont);

Modified: lyx-devel/branches/BRANCH_2_0_X/src/tex2lyx/test/test-structure.tex
==============================================================================
--- lyx-devel/branches/BRANCH_2_0_X/src/tex2lyx/test/test-structure.tex Sun Nov 
13 11:40:07 2011        (r40182)
+++ lyx-devel/branches/BRANCH_2_0_X/src/tex2lyx/test/test-structure.tex Sun Nov 
13 11:43:30 2011        (r40183)
@@ -269,6 +269,10 @@
 \begin{description}
 \item[ABC] first item
 \item[BCD] second one
+\item[{x y z}] with space
+\item  % hi there
+[{x y % bla
+z}] and with comments
 \end{description}
 labelings:
 \begin{lyxlist}{00.00.0000}

Modified: lyx-devel/branches/BRANCH_2_0_X/src/tex2lyx/text.cpp
==============================================================================
--- lyx-devel/branches/BRANCH_2_0_X/src/tex2lyx/text.cpp        Sun Nov 13 
11:40:07 2011        (r40182)
+++ lyx-devel/branches/BRANCH_2_0_X/src/tex2lyx/text.cpp        Sun Nov 13 
11:43:30 2011        (r40183)
@@ -2158,16 +2158,15 @@
                }
 
                else if (t.cs() == "item") {
-                       p.skip_spaces();
                        string s;
-                       bool optarg = false;
-                       if (p.next_token().cat() != catEscape &&
-                           p.next_token().character() == '[') {
-                               p.get_token(); // eat '['
-                               s = parse_text_snippet(p, FLAG_BRACK_LAST,
-                                                      outer, context);
-                               optarg = true;
-                       }
+                       bool const optarg = p.hasOpt();
+                       if (optarg) {
+                               // FIXME: This swallows comments, but we cannot 
use
+                               //        eat_whitespace() since we must not 
output
+                               //        anything before the item.
+                               s = p.getArg('[', ']');
+                       } else
+                               p.skip_spaces(false);
                        context.set_item();
                        context.check_layout(os);
                        if (context.has_item) {
@@ -2183,13 +2182,30 @@
                                if (context.layout->labeltype != LABEL_MANUAL) {
                                        // LyX does not support \item[\mybullet]
                                        // in itemize environments
-                                       handle_ert(os, "[", context);
-                                       os << s;
-                                       handle_ert(os, "]", context);
+                                       Parser p2(s + ']');
+                                       os << parse_text_snippet(p2,
+                                               FLAG_BRACK_LAST, outer, 
context);
                                } else if (!s.empty()) {
+                                       // LyX adds braces around the argument,
+                                       // so we need to remove them here.
+                                       if (s.size() > 2 && s[0] == '{' &&
+                                           s[s.size()-1] == '}')
+                                               s = s.substr(1, s.size()-2);
+                                       // If the argument contains a space we
+                                       // must put it into ERT: Otherwise LyX
+                                       // would misinterpret the space as
+                                       // item delimiter (bug 7663)
+                                       if (contains(s, ' ')) {
+                                               handle_ert(os, s, context);
+                                       } else {
+                                               Parser p2(s + ']');
+                                               os << parse_text_snippet(p2,
+                                                       FLAG_BRACK_LAST,
+                                                       outer, context);
+                                       }
                                        // The space is needed to separate the
                                        // item from the rest of the sentence.
-                                       os << s << ' ';
+                                       os << ' ';
                                        eat_whitespace(p, os, context, false);
                                }
                        }

Modified: lyx-devel/branches/BRANCH_2_0_X/status.20x
==============================================================================
--- lyx-devel/branches/BRANCH_2_0_X/status.20x  Sun Nov 13 11:40:07 2011        
(r40182)
+++ lyx-devel/branches/BRANCH_2_0_X/status.20x  Sun Nov 13 11:43:30 2011        
(r40183)
@@ -168,6 +168,8 @@
 
 - Fix tex2lyx handling of framed boxes without inner box.
 
+- Fix tex2lyx handling of description \item with spaces (bug 7663).
+
 - Store the autosave files of unnamed buffers in the correct directory
   and make sure they are not left behind after saving (bug 7793).
 

Reply via email to