]> git.lyx.org Git - lyx.git/blobdiff - lib/lyx2lyx/lyx_2_3.py
When cleaning up before quitting, take care of exceptions
[lyx.git] / lib / lyx2lyx / lyx_2_3.py
index 95439377ed6fd42a65b7699dcf2dde94ece698d2..73ac45cf00c8d23c0db2c9c28b491e88034e0047 100644 (file)
@@ -1146,11 +1146,12 @@ def revert_noprefix(document):
             i += 1
             continue
         k = find_token(document.body, "LatexCommand labelonly", i, j)
-        if k == -1:
-            i = j
-            continue
-        noprefix = get_bool_value(document.body, "noprefix", i, j)
+        noprefix = False
+        if k != -1:
+            noprefix = get_bool_value(document.body, "noprefix", i, j)
         if not noprefix:
+            # either it was not a labelonly command, or else noprefix was not set.
+            # in that case, we just delete the option.
             del_token(document.body, "noprefix", i, j)
             i = j
             continue
@@ -2145,9 +2146,10 @@ def convert_mathnumberpos(document):
     " add the \\math_number_before tag "
     # check if the document uses the class option "leqno"
     k = find_token(document.header, "\\quotes_style", 0)
+    m = find_token(document.header, "\\options", 0)
     regexp = re.compile(r'^.*leqno.*')
     i = find_re(document.header, regexp, 0)
-    if i != -1:
+    if i != -1 and i == m:
         document.header.insert(k, "\\math_number_before 1")
         # delete the found option
         document.header[i] = document.header[i].replace(",leqno", "")
@@ -2182,7 +2184,6 @@ def revert_mathnumberpos(document):
 
 def convert_mathnumberingname(document):
     " rename the \\math_number_before tag to \\math_numbering_side "
-    document.warning("Malformed LyX document: Missing '\\end_inset' of Float inset.")
     regexp = re.compile(r'(\\math_number_before 1)')
     i = find_re(document.header, regexp, 0)
     if i != -1:
@@ -2193,9 +2194,10 @@ def convert_mathnumberingname(document):
         document.header[i] = "\\math_numbering_side default"
     # check if the document uses the class option "reqno"
     k = find_token(document.header, "\\math_numbering_side", 0)
+    m = find_token(document.header, "\\options", 0)
     regexp = re.compile(r'^.*reqno.*')
     i = find_re(document.header, regexp, 0)
-    if i != -1:
+    if i != -1 and i == m:
         document.header[k] = "\\math_numbering_side right"
         # delete the found option
         document.header[i] = document.header[i].replace(",reqno", "")
@@ -2232,6 +2234,18 @@ def revert_mathnumberingname(document):
         document.header[i] = "\\math_number_before 0"
 
 
+def convert_minted(document):
+    " add the \\use_minted tag "
+    document.header.insert(-1, "\\use_minted 0")
+
+
+def revert_minted(document):
+    " remove the \\use_minted tag "
+    i = find_token(document.header, "\\use_minted", 0)
+    if i != -1:
+        document.header.pop(i)
+
+
 ##
 # Conversion hub
 #
@@ -2272,10 +2286,12 @@ convert = [
            [540, []],
            [541, [convert_allowbreak]],
            [542, [convert_mathnumberpos]],
-           [543, [convert_mathnumberingname]]
+           [543, [convert_mathnumberingname]],
+           [544, [convert_minted]]
           ]
 
 revert =  [
+           [543, [revert_minted]],
            [542, [revert_mathnumberingname]],
            [541, [revert_mathnumberpos]],
            [540, [revert_allowbreak]],