X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=lib%2Flyx2lyx%2Flyxconvert_216.py;h=66c1aa059846525e584765a5b248f2d3bb6cab2e;hb=bee4ac06d85f2fbad447d3e975b2ecfa9217a65c;hp=b8bab3bdd51305e75b1dfb0f29a646c14fab4bf9;hpb=17b41b16550acfc4051f40091886da9c45683211;p=lyx.git diff --git a/lib/lyx2lyx/lyxconvert_216.py b/lib/lyx2lyx/lyxconvert_216.py index b8bab3bdd5..66c1aa0598 100644 --- a/lib/lyx2lyx/lyxconvert_216.py +++ b/lib/lyx2lyx/lyxconvert_216.py @@ -48,40 +48,80 @@ def update_tabular(lines): i = i +1 row_info = [] + cont_row = [] for j in range(rows): row_info.append(string.split(lines[i])) + if string.split(lines[i])[2] == '1': + cont_row.append(j) del lines[i] + column_info = [] + col_info_re = re.compile(r'(\d) (\d) (\d) (".*") (".*")') for j in range(columns): - column_info.append(string.split(lines[i])) + column_info.append(col_info_re.match(lines[i]).groups()) del lines[i] cell_info = [] + cell_col = [] ncells = 0 - cont_row = [] + cell_re = re.compile(r'(\d) (\d) (\d) (\d) (\d) (\d) (\d) (".*") (".*")') for j in range(rows): - c_row = 0 for k in range(columns): - cell_info.append(string.split(lines[i])) - if cell_info[len(cell_info)-1][6] == '1': - c_row = 1 + #add column location to read properties + cell_info.append(cell_re.match(lines[i]).groups()) + cell_col.append(k) if lines[i][0] != "2": ncells = ncells + 1 del lines[i] - if c_row: - cont_row.append(j+1) lines[tabular_line] = '' % (rows-len(cont_row),columns) del lines[i] if not lines[i]: del lines[i] + # Read cells + l = 0 + cell_content = [] + for j in range(rows): + cell_content.append([]) + + for j in range(rows): + for k in range(columns): + cell_content[j].append([]) + + for j in range(rows): + for k in range(columns): + m = j*columns + k + if cell_info[m][0] == '2': + continue + + if l == ncells -1: + # the end variable refers to cell end, not to file end. + end = find_tokens(lines, ['\\layout','\\the_end','\\end_deeper','\\end_float'], i) + else: + end = find_token(lines, '\\newline ', i) + + if end == -1: + sys.stderr.write("Malformed lyx file\n") + sys.exit(1) + + end = end - i + while end > 0: + cell_content[j][k].append(lines[i]) + del lines[i] + end = end -1 + + if lines[i] == '\\newline ': + del lines[i] + l = l + 1 + tmp = [] tmp.append("") - l = 0 for j in range(rows): - tmp.append('' % (row_info[j][0],row_info[j][1],row_info[j][2])) + if j in cont_row: + continue + tmp.append('' % (row_info[j][0],row_info[j][1],row_info[j][3])) for k in range(columns): if j: @@ -95,10 +135,9 @@ def update_tabular(lines): n = m + 1 while n < rows * columns - 1 and cell_info[n][0] == '2': n = n + 1 - rightline = int(column_info[k][2]) + rightline = int(column_info[cell_col[n-1]][2]) else: # not a multicolumn main cell - # rightline = int(cell_info[m][5]) or int(column_info[k][2]) rightline = int(column_info[k][2]) tmp.append('' % (cell_info[m][0],cell_info[m][1],cell_info[m][2],cell_info[m][3],leftline,rightline,cell_info[m][5],cell_info[m][6],cell_info[m][7],cell_info[m][8])) @@ -107,36 +146,22 @@ def update_tabular(lines): tmp.append('\\layout Standard') tmp.append('') - if cell_info[m][0] == '2': - tmp.append('\\end_inset ') - tmp.append('') - tmp.append('') - continue - - if l == ncells -1: - end = find_tokens(lines, ['\\layout','\\the_end','\\end_deeper','\\end_float'], i) - if end == -1: - sys.stderr.write("Malformed lyx file\n") - else: - end = end - i - paragraph = [] - while end > 0: - paragraph.append(lines[i]) - del lines[i] - end = end -1 - tmp.extend(set_paragraph_properties(paragraph, prop_dict)) - else: + if cell_info[m][0] != '2': paragraph = [] - while lines[i] != '\\newline ': - paragraph.append(lines[i]) - del lines[i] - del lines[i] + if cell_info[m][4] == '1': + l = j + paragraph.extend(cell_content[j][k]) + while cell_info[m][4] == '1': + m = m + columns + l = l + 1 + paragraph.extend(cell_content[l][k]) + else: + paragraph = cell_content[j][k] tmp.extend(set_paragraph_properties(paragraph, prop_dict)) tmp.append('\\end_inset ') tmp.append('') tmp.append('') - l = l + 1 tmp.append('') tmp.append('') @@ -215,7 +240,6 @@ def set_paragraph_properties(lines, prop_dict): lines.append('') break - #debug_list('*' * 10 + ' begin ' + '*' * 10, lines[start:]) if not lines[start:] and not lines[end:]: return [] @@ -225,25 +249,18 @@ def set_paragraph_properties(lines, prop_dict): return result[:] -def debug_list(title, list): - sys.stderr.write(title+'\n') - for line in list: - sys.stderr.write(line+'\n') - def update_language(header): i = find_token(header, "\\language", 0) if i == -1: # no language, should emit a warning header.append('\\language english') return - # FIXME: find the document default language in user preferences + # This is the lyx behaviour: defaults to english header[i] = '\\language english' return def convert(header,body): - sys.stderr.write("%d\n" % len(body)) update_tabular(body) - sys.stderr.write("%d\n" % len(body)) update_language(header) if __name__ == "__main__":