]> git.lyx.org Git - lyx.git/blobdiff - lib/lyx2lyx/lyxconvert_215.py
Revert, revert, revert. Sorry about that, y'all.
[lyx.git] / lib / lyx2lyx / lyxconvert_215.py
index a657832cca62ce966a84a42a79e7d5459da24785..91990c5802cd5bcec47d3c77ca61c1159052665d 100644 (file)
@@ -54,9 +54,98 @@ def merge_formula_inset(lines):
             del lines[i+1]
         i = i + 1
 
+# Update from tabular format 4 to 5 if necessary
+def update_tabular(lines):
+    lyxtable_re = re.compile(r".*\\LyXTable$")
+    i=0
+    while 1:
+        i = find_re(lines, lyxtable_re, i)
+        if i == -1:
+            break
+        i = i + 1
+        format = lines[i][8]
+        if format != '4':
+            continue
+        
+        lines[i]='multicol5'
+        i = i + 1
+        rows = int(string.split(lines[i])[0])
+        columns = int(string.split(lines[i])[1])
+
+        i = i + rows + 1
+        for j in range(columns):
+            col_info = string.split(lines[i])
+            if len(col_info) == 3:
+                lines[i] = lines[i] + '"" ""'
+            else:
+                lines[i] = string.join(col_info[:3]) + ' "%s" ""' % col_info[3]
+            i = i + 1
+
+        while lines[i]:
+            lines[i] = lines[i] + ' "" ""'
+            i = i + 1
+
+def update_toc(lines):
+    i = 0
+    while 1:
+        i = find_token(lines, '\\begin_inset LatexCommand \\tableofcontents', i)
+        if i == -1:
+            break
+        lines[i] = lines[i] + '{}'
+        i = i + 1
+
+def remove_cursor(lines):
+    i = find_token(lines, '\\cursor', 0)
+    if i != -1:
+        del lines[i]
+
+def remove_vcid(lines):
+    i = find_token(lines, '\\lyxvcid', 0)
+    if i != -1:
+        del lines[i]
+    i = find_token(lines, '\\lyxrcsid', 0)
+    if i != -1:
+        del lines[i]
+
+def first_layout(lines):
+    while (lines[0] == ""):
+        del lines[0]
+    if lines[0][:7] != "\\layout":
+        lines[:0] = ["\\layout Standard"]
+
+def remove_space_in_units(lines):
+    margins = ["\\topmargin","\\rightmargin",
+               "\\leftmargin","\\bottommargin"]
+
+    unit_rexp = re.compile(r'[^ ]* (.*) (.*)')
+
+    begin_preamble = find_token(lines,"\\begin_preamble", 0)
+    end_preamble = find_token(lines, "\\end_preamble", 0)
+    for margin in margins:
+        i = 0
+        while 1:
+            i = find_token(lines, margin, i)
+            if i == -1:
+                break
+
+            if i > begin_preamble and i < end_preamble:
+                i = i + 1
+                continue
+
+            result = unit_rexp.search(lines[i])
+            if result:
+                lines[i] = margin + " " + result.group(1) + result.group(2)
+            i = i + 1
+
 def convert(header,body):
+    first_layout(body)
+    remove_vcid(header)
+    remove_cursor(body)
+    update_toc(body)
     replace_protected_separator(body)
     merge_formula_inset(body)
+    update_tabular(body)
+    remove_space_in_units(header)    
 
 if __name__ == "__main__":
     pass