X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=lib%2Flyx2lyx%2Flyx_1_1_5.py;h=d8dc59006e727065208b91bb8c39f0b4b99d7640;hb=b8227ebda0a2a8127731749d2caaa5dae45ef5d7;hp=00b84d2a3fafd9c2fc42f4e7307cae2610303bf0;hpb=7400f85b89edbe6ead683bf2e5c4e7439d6ea8d4;p=lyx.git diff --git a/lib/lyx2lyx/lyx_1_1_5.py b/lib/lyx2lyx/lyx_1_1_5.py index 00b84d2a3f..d8dc59006e 100644 --- a/lib/lyx2lyx/lyx_1_1_5.py +++ b/lib/lyx2lyx/lyx_1_1_5.py @@ -18,10 +18,9 @@ import re import string -from parser_tools import find_token, find_token_backwards, find_re +from parser_tools import find_token, find_token_backwards, find_re, get_layout -layout_exp = re.compile(r"\\layout (\S*)") math_env = ["\\[","\\begin{eqnarray*}","\\begin{eqnarray}","\\begin{equation}"] def replace_protected_separator(file): @@ -33,11 +32,7 @@ def replace_protected_separator(file): break j = find_token_backwards(lines, "\\layout", i) #if j == -1: print error - layout_m = layout_exp.match(lines[j]) - if layout_m: - layout = layout_m.group(1) - else: - layout = "Standard" + layout = get_layout(lines[j], file.default_layout) if layout == "LyX-Code": result = "" @@ -130,7 +125,7 @@ def first_layout(file): while (lines[0] == ""): del lines[0] if lines[0][:7] != "\\layout": - lines[:0] = ["\\layout Standard"] + lines[:0] = ['\\layout %s' % file.default_layout, ''] def remove_space_in_units(file): @@ -140,8 +135,6 @@ def remove_space_in_units(file): 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: @@ -149,19 +142,93 @@ def remove_space_in_units(file): 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 latexdel_getargs(file, i): + lines = file.body + + # play safe, clean empty lines + while 1: + if lines[i]: + break + del lines[i] + + j = find_token(lines, '\\end_inset', i) + + if i == j: + del lines[i] + else: + file.warning("Unexpected end of inset.") + j = find_token(lines, '\\begin_inset LatexDel }{', i) + + ref = string.join(lines[i:j]) + del lines[i:j + 1] + + # play safe, clean empty lines + while 1: + if lines[i]: + break + del lines[i] + + j = find_token(lines, '\\end_inset', i - 1) + if i == j: + del lines[i] + else: + file.warning("Unexpected end of inset.") + j = find_token(lines, '\\begin_inset LatexDel }', i) + label = string.join(lines[i:j]) + del lines[i:j + 1] + + return ref, label + + +def update_ref(file): + lines = file.body + i = 0 + while 1: + i = find_token(lines, '\\begin_inset LatexCommand', i) + if i == -1: + return + + if string.split(lines[i])[-1] == "\\ref{": + i = i + 1 + ref, label = latexdel_getargs(file, i) + lines[i - 1] = "%s[%s]{%s}" % (lines[i - 1][:-1], ref, label) + + i = i + 1 + + +def update_latexdel(file): + lines = file.body + i = 0 + latexdel_re = re.compile(r".*\\begin_inset LatexDel") + while 1: + i = find_re(lines, latexdel_re, i) + if i == -1: + return + lines[i] = string.replace(lines[i],'\\begin_inset LatexDel', '\\begin_inset LatexCommand') + + j = string.find(lines[i],'\\begin_inset') + lines.insert(i+1, lines[i][j:]) + lines[i] = string.strip(lines[i][:j]) + i = i + 1 + + if string.split(lines[i])[-1] in ("\\url{", "\\htmlurl{"): + i = i + 1 + + ref, label = latexdel_getargs(file, i) + lines[i -1] = "%s[%s]{%s}" % (lines[i-1][:-1], label, ref) + + i = i + 1 + + convert = [[216, [first_layout, remove_vcid, remove_cursor, update_toc, replace_protected_separator, merge_formula_inset, - update_tabular, remove_space_in_units]]] + update_tabular, remove_space_in_units, update_ref, update_latexdel]]] revert = [] if __name__ == "__main__":