]> git.lyx.org Git - features.git/blobdiff - lib/lyx2lyx/lyx_2_0.py
* Add possibility to append active branch names to the output file name (#3105).
[features.git] / lib / lyx2lyx / lyx_2_0.py
index bd4a4778ea594d74a95d4f74867a627235e7c57b..cb2461dd52f10b5267ed25bbfc611869d2b7010d 100644 (file)
@@ -207,38 +207,54 @@ def revert_tabularvalign(document):
            document.warning("Malformed LyX document: Could not find end of tabular.")
            i = j
            continue
-
-       k = find_token(document.body, "<features tabularvalignment=", i)
-       if k == -1:
-           i = j
-           continue
-
-       # which valignment is specified?
-       tabularvalignment_re = re.compile(r'<features tabularvalignment="(top|bottom)">')
-       m = tabularvalignment_re.match(document.body[k])
-       if not m:
-           i = j
-           continue
-
-       tabularvalignment = m.group(1)
-
-       subst = ['\\end_layout', '\\end_inset']
-       document.body[j+1:j+1] = subst # just inserts those lines
-       subst = ['\\begin_inset Box Frameless',
-           'position "' + tabularvalignment[0] +'"',
-           'hor_pos "c"',
-           'has_inner_box 1',
-           'inner_pos "c"',
-           'use_parbox 0',
-           'width "0col%"',
-           'special "none"',
-           'height "1in"',
-           'height_special "totalheight"',
-           'status open',
-           '',
-           '\\begin_layout Plain Layout']
-       document.body[i:i] = subst # this just inserts the array at i
-       i += len(subst) + 2 # adjust i to save a few cycles
+       # don't set a box for longtables, only delete tabularvalignment
+       # the alignment is 2 lines below \\begin_inset Tabular
+       p = document.body[i+2].find("islongtable")
+       if p > -1:
+           q = document.body[i+2].find("tabularvalignment")
+           if q > -1:
+               document.body[i+2] = document.body[i+2][:q-1]
+               document.body[i+2] = document.body[i+2] + '>'
+           i = i + 1
+
+       # when no longtable
+       if p == -1:
+         tabularvalignment = 'c'
+         # which valignment is specified?
+         m = document.body[i+2].find('tabularvalignment="top"')
+         if m > -1:
+             tabularvalignment = 't'
+         m = document.body[i+2].find('tabularvalignment="bottom"')
+         if m > -1:
+             tabularvalignment = 'b'
+         # delete tabularvalignment
+         q = document.body[i+2].find("tabularvalignment")
+         if q > -1:
+             document.body[i+2] = document.body[i+2][:q-1]
+             document.body[i+2] = document.body[i+2] + '>'
+
+         # don't add a box when centered
+         if tabularvalignment == 'c':
+             i = j
+             continue
+         subst = ['\\end_layout', '\\end_inset']
+         document.body[j+1:j+1] = subst # just inserts those lines
+         subst = ['\\begin_inset Box Frameless',
+             'position "' + tabularvalignment +'"',
+             'hor_pos "c"',
+             'has_inner_box 1',
+             'inner_pos "c"',
+             'use_parbox 0',
+             # we don't know the width, assume 50%
+             'width "50col%"',
+             'special "none"',
+             'height "1in"',
+             'height_special "totalheight"',
+             'status open',
+             '',
+             '\\begin_layout Plain Layout']
+         document.body[i:i] = subst # this just inserts the array at i
+         i += len(subst) + 2 # adjust i to save a few cycles
 
 
 def revert_phantom(document):
@@ -688,6 +704,62 @@ def revert_nomencl_width(document):
       i = i + 1
 
 
+def revert_nomencl_cwidth(document):
+    " Remove width param from nomencl_print "
+    i = 0
+    while True:
+      i = find_token(document.body, "\\begin_inset CommandInset nomencl_print", i)
+      if i == -1:
+        break
+      j = find_end_of_inset(document.body, i)
+      l = find_token(document.body, "width", i, j)
+      if l == -1:
+            document.warning("Can't find width option for nomencl_print!")
+            i = j
+            continue
+      width = get_value(document.body, "width", i, j).strip('"')
+      del document.body[l]
+      add_to_preamble(document, ["\\setlength{\\nomlabelwidth}{" + width + "}"])
+      i = i + 1
+
+
+def revert_applemac(document):
+    " Revert applemac encoding to auto "
+    i = 0
+    if document.encoding == "applemac":
+        document.encoding = "auto"
+        i = find_token(document.header, "\\encoding", 0)
+        if i != -1:
+            document.header[i] = "\\encoding auto"
+
+
+def revert_longtable_align(document):
+    " Remove longtable alignment setting "
+    i = 0
+    j = 0
+    while True:
+      i = find_token(document.body, "\\begin_inset Tabular", i)
+      if i == -1:
+          break
+      # the alignment is 2 lines below \\begin_inset Tabular
+      j = document.body[i+2].find("longtabularalignment")
+      if j == -1:
+          break
+      document.body[i+2] = document.body[i+2][:j-1]
+      document.body[i+2] = document.body[i+2] + '>'
+      i = i + 1
+
+
+def revert_branch_filename(document):
+    " Remove \\filename_suffix parameter from branches "
+    i = 0
+    while True:
+        i = find_token(document.header, "\\filename_suffix", i)
+        if i == -1:
+            return
+        del document.header[i]
+
+
 ##
 # Conversion hub
 #
@@ -706,10 +778,20 @@ convert = [[346, []],
            [356, []],
            [357, []],
            [358, []],
-           [359, [convert_nomencl_width]]
+           [359, [convert_nomencl_width]],
+           [360, []],
+           [361, []],
+           [362, []],
+           [363, []],
+           [364, []]
           ]
 
-revert =  [[358, [revert_nomencl_width]],
+revert =  [[363, [revert_branch_filename]],
+           [362, [revert_longtable_align]],
+           [361, [revert_applemac]],
+           [360, []],
+           [359, [revert_nomencl_cwidth]],
+           [358, [revert_nomencl_width]],
            [357, [revert_custom_processors]],
            [356, [revert_ulinelatex]],
            [355, [revert_uulinewave]],