# This file is part of lyx2lyx # Copyright (C) 2002-2004 José Matos # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA """ Convert files to the file format generated by lyx 1.1.6, fix3 and fix4""" import re from parser_tools import find_token, find_re def bool_table(item): " Convert 0, 1 to false, true." if item == "0": return "false" # should emit a warning if item != "1" return "true" align_vertical = {"0": "top", "1": "bottom", "2": "center"} align_table = {"0": "top", "2": "left", "4": "right", "8": "center"} use_table = {"0": "none", "1": "parbox"} table_meta_re = re.compile(r'') def update_tabular(document): " Update tabular format to version 2 (xml like syntax)." regexp = re.compile(r'^\\begin_inset\s+Tabular') lines = document.body i=0 while True: i = find_re(lines, regexp, i) if i == -1: break i = i +1 # scan table header meta-info res = table_meta_re.match( lines[i] ) if res: val = res.groups() lines[i] = '' % val j = find_token(lines, '', i) + 1 if j == 0: document.warning( "Error: Bad lyx format i=%d j=%d" % (i,j)) break new_table = table_update(lines[i:j]) lines[i:j] = new_table i = i + len(new_table) col_re = re.compile(r'') cell_re = re.compile(r'') features_re = re.compile(r'') row_re = re.compile(r'') def table_update(lines): " Update table's internal content to format 2." lines[1] = lines[1].replace('' if lines[2]=="": del lines[2] i = 2 col_info = [] while i < len(lines): lines[i] = lines[i].replace('' or lines[i] == '': del lines[i] continue res = cell_re.match(lines[i]) if res: val = res.groups() lines[i] = f'' res = row_re.match(lines[i]) if res: val = res.groups() lines[i] = f'' i = i + 1 j = len(col_info) for i in range(j): res = col_re.match(col_info[i]) if res: val = res.groups() col_info[i] = '' \ % ( align_table[val[0]], align_vertical[val[1]], bool_table(val[2]), bool_table(val[3]), val[4],val[5]) return lines[:2] + col_info + lines[2:] supported_versions = ["1.1.6fix3","1.1.6fix4","1.1"] convert = [[218, [update_tabular]]] revert = [] if __name__ == "__main__": pass