X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=lib%2Flyx2lyx%2Flyx_1_2.py;h=46b7797a8bd78a08fc3d46c023027e58d953e2b1;hb=b8227ebda0a2a8127731749d2caaa5dae45ef5d7;hp=2e3063d2e041aef6fce9def98f9e99185a1399bc;hpb=4bd289f1e34301fbc352d188380d1cd808154873;p=lyx.git diff --git a/lib/lyx2lyx/lyx_1_2.py b/lib/lyx2lyx/lyx_1_2.py index 2e3063d2e0..46b7797a8b 100644 --- a/lib/lyx2lyx/lyx_1_2.py +++ b/lib/lyx2lyx/lyx_1_2.py @@ -23,7 +23,7 @@ import re from parser_tools import find_token, find_token_backwards, get_next_paragraph,\ find_tokens, find_end_of_inset, find_re, \ is_nonempty_line, get_paragraph, find_nonempty_line, \ - get_value, get_tabular_lines, check_token + get_value, get_tabular_lines, check_token, get_layout floats = { "footnote": ["\\begin_inset Foot", @@ -91,7 +91,7 @@ def remove_oldfloat(file): while check_token(lines[i2], "\\end_deeper"): i2 = i2+1 if i2 > i+1: - j2 = get_next_paragraph(lines, j+1) + j2 = get_next_paragraph(lines, j + 1, file.format + 1) lines[j2:j2] = ["\\end_deeper "]*(i2-(i+1)) new = floats[floattype]+[""] @@ -116,7 +116,7 @@ def remove_oldfloat(file): # as extra '\foo default' commands are ignored. # In fact, it might be safer to output '\foo default' for all # font attributes. - k = get_paragraph(lines, i) + k = get_paragraph(lines, i, file.format + 1) flag = 0 for token in font_tokens: if find_token(lines, token, k, i) != -1: @@ -136,6 +136,7 @@ def remove_oldfloat(file): pextra_type2_rexp = re.compile(r".*\\pextra_type\s+[12]") pextra_type2_rexp2 = re.compile(r".*(\\layout|\\pextra_type\s+2)") +pextra_widthp = re.compile(r"\\pextra_widthp") def remove_pextra(file): lines = file.body @@ -146,6 +147,12 @@ def remove_pextra(file): if i == -1: break + # Sometimes the \pextra_widthp argument comes in it own + # line. If that happens insert it back in this line. + if pextra_widthp.search(lines[i+1]): + lines[i] = lines[i] + ' ' + lines[i+1] + del lines[i+1] + mo = pextra_rexp.search(lines[i]) width = get_width(mo) @@ -172,10 +179,10 @@ def remove_pextra(file): if hfill: start = ["","\hfill",""]+start else: - start = ["\\layout Standard"] + start + start = ['\\layout %s' % file.default_layout,''] + start j0 = find_token_backwards(lines,"\\layout", i-1) - j = get_next_paragraph(lines, i) + j = get_next_paragraph(lines, i, file.format + 1) count = 0 while 1: @@ -209,13 +216,14 @@ def is_empty(lines): move_rexp = re.compile(r"\\(family|series|shape|size|emph|numeric|bar|noun|end_deeper)") ert_rexp = re.compile(r"\\begin_inset|\\hfill|.*\\SpecialChar") spchar_rexp = re.compile(r"(.*)(\\SpecialChar.*)") -ert_begin = ["\\begin_inset ERT", - "status Collapsed", - "", - "\\layout Standard"] def remove_oldert(file): + ert_begin = ["\\begin_inset ERT", + "status Collapsed", + "", + '\\layout %s' % file.default_layout, + ""] lines = file.body i = 0 while 1: @@ -241,8 +249,7 @@ def remove_oldert(file): new = [] new2 = [] if check_token(lines[i], "\\layout LaTeX"): - new = ["\layout Standard", "", ""] - # We have a problem with classes in which Standard is not the default layout! + new = ['\layout %s' % file.default_layout, "", ""] k = i+1 while 1: @@ -334,7 +341,7 @@ def remove_oldertinset(file): break j = find_end_of_inset(lines, i) k = find_token(lines, "\\layout", i+1) - l = get_paragraph(lines, i) + l = get_paragraph(lines, i, file.format + 1) if lines[k] == lines[l]: # same layout k = k+1 new = lines[k:j] @@ -342,8 +349,11 @@ def remove_oldertinset(file): i = i+1 -def is_ert_paragraph(lines, i): - if not check_token(lines[i], "\\layout Standard"): +def is_ert_paragraph(file, i): + lines = file.body + if not check_token(lines[i], "\\layout"): + return 0 + if not file.is_default_layout(get_layout(lines[i], file.default_layout)): return 0 i = find_nonempty_line(lines, i+1) @@ -362,10 +372,10 @@ def combine_ert(file): i = find_token(lines, "\\begin_inset ERT", i) if i == -1: break - j = get_paragraph(lines, i) + j = get_paragraph(lines, i, file.format + 1) count = 0 text = [] - while is_ert_paragraph(lines, j): + while is_ert_paragraph(file, j): count = count+1 i2 = find_token(lines, "\\layout", j+1) @@ -473,10 +483,11 @@ attr_re = re.compile(r' \w*="(false|0|)"') line_re = re.compile(r'<(features|column|row|cell)') def update_tabular(file): + regexp = re.compile(r'^\\begin_inset\s+Tabular') lines = file.body i = 0 while 1: - i = find_token(lines, '\\begin_inset Tabular', i) + i = find_re(lines, regexp, i) if i == -1: break @@ -601,10 +612,11 @@ longtable_re = re.compile(r'islongtable="(\w)"') ltvalues_re = re.compile(r'endhead="(-?\d*)" endfirsthead="(-?\d*)" endfoot="(-?\d*)" endlastfoot="(-?\d*)"') lt_features_re = re.compile(r'(endhead="-?\d*" endfirsthead="-?\d*" endfoot="-?\d*" endlastfoot="-?\d*")') def update_longtables(file): + regexp = re.compile(r'^\\begin_inset\s+Tabular') body = file.body i = 0 while 1: - i = find_token(body, '\\begin_inset Tabular', i) + i = find_re(body, regexp, i) if i == -1: break i = i + 1 @@ -619,7 +631,7 @@ def update_longtables(file): i = find_token(body, '