]> git.lyx.org Git - lyx.git/blobdiff - lib/lyx2lyx/lyx_1_2.py
Separate preamble from from header. Make its treatment more robust.
[lyx.git] / lib / lyx2lyx / lyx_1_2.py
index 2e3063d2e041aef6fce9def98f9e99185a1399bc..e413dee5528f9d1ac179e48b1d0aee6bc3fc54ff 100644 (file)
@@ -136,6 +136,7 @@ def remove_oldfloat(file):
 
 pextra_type2_rexp = re.compile(r".*\\pextra_type\s+[12]")
 pextra_type2_rexp2 = re.compile(r".*(\\layout|\\pextra_type\s+2)")
+pextra_widthp = re.compile(r"\\pextra_widthp")
 
 def remove_pextra(file):
     lines = file.body
@@ -146,6 +147,12 @@ def remove_pextra(file):
        if i == -1:
            break
 
+        # Sometimes the \pextra_widthp argument comes in it own
+        # line. If that happens insert it back in this line.
+        if pextra_widthp.search(lines[i+1]):
+            lines[i] = lines[i] + ' ' + lines[i+1]
+            del lines[i+1]
+
        mo = pextra_rexp.search(lines[i])
         width = get_width(mo)
 
@@ -473,10 +480,11 @@ attr_re = re.compile(r' \w*="(false|0|)"')
 line_re = re.compile(r'<(features|column|row|cell)')
 
 def update_tabular(file):
+    regexp = re.compile(r'^\\begin_inset\s+Tabular')
     lines = file.body
     i = 0
     while 1:
-        i = find_token(lines, '\\begin_inset  Tabular', i)
+        i = find_re(lines, regexp, i)
         if i == -1:
             break
 
@@ -601,10 +609,11 @@ longtable_re = re.compile(r'islongtable="(\w)"')
 ltvalues_re = re.compile(r'endhead="(-?\d*)" endfirsthead="(-?\d*)" endfoot="(-?\d*)" endlastfoot="(-?\d*)"')
 lt_features_re = re.compile(r'(endhead="-?\d*" endfirsthead="-?\d*" endfoot="-?\d*" endlastfoot="-?\d*")')
 def update_longtables(file):
+    regexp = re.compile(r'^\\begin_inset\s+Tabular')
     body = file.body
     i = 0
     while 1:
-        i = find_token(body, '\\begin_inset  Tabular', i)
+        i = find_re(body, regexp, i)
         if i == -1:
             break
         i = i + 1
@@ -619,7 +628,7 @@ def update_longtables(file):
         i = find_token(body, '<features', i)
         if i == -1:
             break
-    
+
         # is this a longtable?
         longtable = longtable_re.search(body[i])
 
@@ -721,7 +730,7 @@ def change_infoinset(file):
         i = i+5
 
 
-def change_preamble(file):
+def change_header(file):
     lines = file.header
     i = find_token(lines, "\\use_amsmath", 0)
     if i == -1:
@@ -730,20 +739,11 @@ def change_preamble(file):
                      "\use_numerical_citations 0"]
 
 
-def convert(file):
-    table = [change_preamble, change_listof, fix_oldfloatinset,
-             update_tabular, update_longtables, remove_pextra,
-             remove_oldfloat, remove_figinset, remove_oldertinset,
-             remove_oldert, combine_ert, change_infoinset]
-
-    for conv in table:
-        conv(file)
-
-    file.format = 220
-
-
-def revert(file):
-    file.error("The convertion to an older format (%s) is not implemented." % file.format)
+convert = [[220, [change_header, change_listof, fix_oldfloatinset,
+                  update_tabular, update_longtables, remove_pextra,
+                  remove_oldfloat, remove_figinset, remove_oldertinset,
+                  remove_oldert, combine_ert, change_infoinset]]]
+revert  = []
 
 
 if __name__ == "__main__":