X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=lib%2Flyx2lyx%2Flyx_0_12.py;h=6cbd145fb5fdafeee5dfedfc8b27a4842085a731;hb=9da74fe2078e24e1e7891784ecbfe33ff77e7f85;hp=59a0b8cbeff7da31fc4ed6f0ebb28492d4013b32;hpb=695bfd88ed8f02e35c4a31664ed5a2b9f135cf72;p=lyx.git diff --git a/lib/lyx2lyx/lyx_0_12.py b/lib/lyx2lyx/lyx_0_12.py index 59a0b8cbef..6cbd145fb5 100644 --- a/lib/lyx2lyx/lyx_0_12.py +++ b/lib/lyx2lyx/lyx_0_12.py @@ -14,12 +14,11 @@ # # 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA """ Convert files to the file format generated by lyx 0.12""" import re -import string from parser_tools import find_token, find_re, check_token @@ -32,7 +31,7 @@ def space_before_layout(document): if i == -1: break - prot_space = string.find(lines[i-2],'\\protected_separator') + prot_space = lines[i-2].find('\\protected_separator') if lines[i - 1] == '' and prot_space == -1: del lines[i-1] i = i + 1 @@ -66,8 +65,8 @@ def update_tabular(document): lines[i] = 'multicol4' i = i + 1 - rows = int(string.split(lines[i])[0]) - columns = int(string.split(lines[i])[1]) + rows = int(lines[i].split()[0]) + columns = int(lines[i].split()[1]) lines[i] = lines[i] + ' 0 0 -1 -1 -1 -1' i = i + 1 @@ -80,13 +79,13 @@ def update_tabular(document): lines[i] = lines[i] + ' ' i = i + 1 - while string.strip(lines[i]): + while lines[i].strip(): if not format: lines[i] = lines[i] + ' 1 1' lines[i] = lines[i] + ' 0 0 0' i = i + 1 - lines[i] = string.strip(lines[i]) + lines[i] = lines[i].strip() def final_dot(document): @@ -125,9 +124,8 @@ def update_latexdel(document): i = find_token(lines, '\\begin_inset LatexDel', i) if i == -1: return - lines[i] = string.replace(lines[i], - '\\begin_inset LatexDel', - '\\begin_inset LatexCommand') + lines[i] = lines[i].replace('\\begin_inset LatexDel', + '\\begin_inset LatexCommand') i = i + 1 @@ -135,12 +133,10 @@ def update_vfill(document): " Update fill_top and fill_bottom." lines = document.body for i in range(len(lines)): - lines[i] = string.replace(lines[i], - '\\fill_top', - '\\added_space_top vfill') - lines[i] = string.replace(lines[i], - '\\fill_bottom', - '\\added_space_bottom vfill') + lines[i] = lines[i].replace('\\fill_top', + '\\added_space_top vfill') + lines[i] = lines[i].replace('\\fill_bottom', + '\\added_space_bottom vfill') def update_space_units(document): @@ -153,13 +149,13 @@ def update_space_units(document): if result: old = '\\added_space_bottom ' + result.group(1) new = '\\added_space_bottom ' + str(float(result.group(1))) + 'cm' - lines[i] = string.replace(lines[i], old, new) + lines[i] = lines[i].replace(old, new) result = added_space_top.search(lines[i]) if result: old = '\\added_space_top ' + result.group(1) new = '\\added_space_top ' + str(float(result.group(1))) + 'cm' - lines[i] = string.replace(lines[i], old, new) + lines[i] = lines[i].replace(old, new) def remove_cursor(document): @@ -172,7 +168,7 @@ def remove_cursor(document): if i == -1: break cursor = cursor_re.search(lines[i]).group(1) - lines[i] = string.replace(lines[i], cursor, '') + lines[i] = lines[i].replace(cursor, '') i = i + 1 @@ -224,12 +220,12 @@ def header_update(document): lines[i] = lines[i][:-1] if check_token(lines[i], '\\epsfig'): - lines[i] = string.replace(lines[i], '\\epsfig', '\\graphics') + lines[i] = lines[i].replace('\\epsfig', '\\graphics') i = i + 1 continue if check_token(lines[i], '\\papersize'): - size = string.split(lines[i])[1] + size = lines[i].split()[1] new_size = size paperpackage = "" @@ -252,7 +248,7 @@ def header_update(document): if check_token(lines[i], '\\baselinestretch'): - size = string.split(lines[i])[1] + size = lines[i].split()[1] if size == '1.00': name = 'single' elif size == '1.50': @@ -277,9 +273,9 @@ def update_latexaccents(document): if i == -1: return - contents = string.strip(body[i][2:]) + contents = body[i][2:].strip() - if string.find(contents, '{') != -1 and string.find(contents, '}') != -1: + if contents.find('{') != -1 and contents.find('}') != -1: i = i + 1 continue @@ -306,12 +302,30 @@ def obsolete_latex_title(document): if i == -1: return - if string.find(string.lower(body[i]),'latex_title') != -1: + if body[i].lower().find('latex_title') != -1: body[i] = '\\layout Title' i = i + 1 +def remove_inset_latex(document): + "Replace inset latex with layout LaTeX" + body = document.body + + i = 0 + while 1: + i = find_token(body, '\\begin_inset Latex', i) + if i == -1: + return + + body[i] = body[i].replace('\\begin_inset Latex', '\\layout LaTeX') + i = find_token(body, '\\end_inset', i) + if i == -1: + #this should not happen + return + del body[i] + + supported_versions = ["0.12.0","0.12.1","0.12"] convert = [[215, [header_update, add_end_document, remove_cursor, final_dot, update_inset_label, update_latexdel, @@ -319,7 +333,7 @@ convert = [[215, [header_update, add_end_document, remove_cursor, formula_inset_space_eat, update_tabular, update_vfill, remove_empty_insets, remove_formula_latex, update_latexaccents, - obsolete_latex_title]]] + obsolete_latex_title, remove_inset_latex]]] revert = []