]> git.lyx.org Git - lyx.git/blobdiff - lib/lyx2lyx/LyX.py
Sanitize backreferences in hyperref.
[lyx.git] / lib / lyx2lyx / LyX.py
index ad41ba7a8189b7e055f680ae9648737f7b81601c..9ad4c69c35eac794328c4d8d38b0a0e20a2588d4 100644 (file)
@@ -79,9 +79,20 @@ format_relation = [("0_06",    [200], minor_versions("0.6" , 4)),
                    ("1_2",     [220], minor_versions("1.2" , 4)),
                    ("1_3",     [221], minor_versions("1.3" , 7)),
                    ("1_4", range(222,246), minor_versions("1.4" , 5)),
-                   ("1_5", range(246,277), minor_versions("1.5" , 2)),
-                   ("1_6", range(277,315), minor_versions("1.6" , 0))] # Uwe Stöhr: scrlttr2 for serial letters
+                   ("1_5", range(246,277), minor_versions("1.5" , 5)),
+                   ("1_6",     []   , minor_versions("1.6" , 0))]
 
+####################################################################
+# This is useful just for development versions                     #
+# if the list of supported formats is empty get it from last step  #
+if not format_relation[-1][1]:
+    step, mode = format_relation[-1][0], "convert"
+    convert = getattr(__import__("lyx_" + step), mode)
+    format_relation[-1] = (step,
+                           [conv[0] for conv in convert],
+                           format_relation[-1][2])
+#                                                                  #
+####################################################################
 
 def formats_list():
     " Returns a list with supported file formats."
@@ -144,7 +155,7 @@ def get_encoding(language, inputencoding, format, cjk_encoding):
 #
 class LyX_base:
     """This class carries all the information of the LyX file."""
-    
+
     def __init__(self, end_format = 0, input = "", output = "", error = "",
                  debug = default_debug__, try_hard = 0, cjk_encoding = '',
                  language = "english", encoding = "auto"):
@@ -222,10 +233,10 @@ class LyX_base:
                     line = trim_eol(line)
                     if check_token(line, '\\end_preamble'):
                         break
-                    
+
                     if line.split()[:0] in ("\\layout",
                                             "\\begin_layout", "\\begin_body"):
-                        
+
                         self.warning("Malformed LyX file:"
                                      "Missing '\\end_preamble'."
                                      "\nAdding it now and hoping"
@@ -247,6 +258,12 @@ class LyX_base:
 
             self.header.append(line)
 
+        i = find_token(self.header, '\\textclass', 0)
+        if i == -1:
+            self.warning("Malformed LyX file: Missing '\\textclass'.")
+            i = find_token(self.header, '\\lyxformat', 0) + 1
+            self.header[i:i] = ['\\textclass article']
+
         self.textclass = get_value(self.header, "\\textclass", 0)
         self.backend = get_backend(self.textclass)
         self.format  = self.read_format()
@@ -284,10 +301,7 @@ class LyX_base:
         if self.preamble:
             i = find_token(self.header, '\\textclass', 0) + 1
             preamble = ['\\begin_preamble'] + self.preamble + ['\\end_preamble']
-            if i == 0:
-                self.error("Malformed LyX file: Missing '\\textclass'.")
-            else:
-                header = self.header[:i] + preamble + self.header[i:]
+            header = self.header[:i] + preamble + self.header[i:]
         else:
             header = self.header
 
@@ -309,7 +323,7 @@ class LyX_base:
             try:
                 gzip.open(input).readline()
                 self.input = gzip.open(input)
-                self.output = gzip.GzipFile(mode="wb", fileobj=self.output) 
+                self.output = gzip.GzipFile(mode="wb", fileobj=self.output)
             except:
                 self.input = open(input)
         else:
@@ -601,7 +615,7 @@ class LyX_base:
             # skip paragraph parameters
             while not self.body[k].strip() or self.body[k].split()[0] \
                       in allowed_parameters:
-                k += 1 
+                k += 1
 
             while k < j:
                 if check_token(self.body[k], '\\begin_inset'):