]> git.lyx.org Git - features.git/commitdiff
Improve a warning in lyx2lyx.
authorGünter Milde <milde@lyx.org>
Thu, 17 Jan 2019 23:20:19 +0000 (00:20 +0100)
committerGünter Milde <milde@lyx.org>
Thu, 17 Jan 2019 23:20:19 +0000 (00:20 +0100)
If get_containing_layout() finds a layout without name,
it will return an empty string as layoutname.
Calling functions can thus differentiate between missing
\begin_layout and missing layoutname and give a more specific
response or warning.

lib/lyx2lyx/lyx_2_3.py
lib/lyx2lyx/parser_tools.py

index a2f37bc8d4354642c1678e92aad687470d0b6f05..fd029d557bd3b39b27df64f24829b549a51ea3b2 100644 (file)
@@ -1837,6 +1837,9 @@ def convert_dashligatures(document):
                 document.warning("Malformed LyX document: "
                                 "Can't find layout at line %d" % i)
                 continue
+            if not layoutname:
+                document.warning("Malformed LyX document: "
+                                 "Missing layout name on line %d"%start)
             if layoutname == "LyX-Code":
                 i = end
                 continue
index c53dbfa1abf5ad83c225740babceff269ebda7e9..12d6aa6be05cd5396c833c3d0ab442f84fddd504 100644 (file)
@@ -639,12 +639,15 @@ def get_containing_inset(lines, i):
 
 def get_containing_layout(lines, i):
   '''
-  Finds out what kind of layout line i is within. Returns a
-  list containing what follows \begin_layout on the line
-  on which the layout begins, plus the starting and ending line
-  and the start of the paragraph (after all params). I.e, returns:
+  Find out what kind of layout line `i` is within.
+  Return a tuple
     (layoutname, layoutstart, layoutend, startofcontent)
-  Returns False on any kind of error.
+  containing
+    * layout style/name,
+    * start line number,
+    * end line number, and
+    * number of first paragraph line (after all params).
+  Return `False` on any kind of error.
   '''
   j = i
   while True:
@@ -659,10 +662,13 @@ def get_containing_layout(lines, i):
   if endlay < i:
       return False
 
-  lay = get_value(lines, "\\begin_layout", stlay)
-  if lay == "":
-      # shouldn't happen
-      return False
+  layoutname = get_value(lines, "\\begin_layout", stlay)
+  if layoutname == "": # layout style missing
+      # TODO: What shall we do in this case?
+      pass
+      # layoutname == "Standard" # use same fallback as the LyX parser:
+      # raise ValueError("Missing layout name on line %d"%stlay) # diagnosis
+      # return False # generic error response
   par_params = ["\\noindent", "\\indent", "\\indent-toggle", "\\leftindent",
                 "\\start_of_appendix", "\\paragraph_spacing", "\\align",
                 "\\labelwidthstring"]
@@ -671,7 +677,7 @@ def get_containing_layout(lines, i):
       stpar += 1
       if lines[stpar].split(' ', 1)[0] not in par_params:
           break
-  return (lay, stlay, endlay, stpar)
+  return (layoutname, stlay, endlay, stpar)
 
 
 def count_pars_in_inset(lines, i):