# This file is part of lyx2lyx
-# -*- coding: iso-8859-1 -*-
-# Copyright (C) 2002-2004 José Matos <jamatos@lyx.org>
+# -*- coding: utf-8 -*-
+# Copyright (C) 2002-2004 José Matos <jamatos@lyx.org>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
#
# 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 1.1.6, until fix2"""
import re
-import string
from parser_tools import find_re, find_tokens, find_token, check_token
-
lyxtable_re = re.compile(r".*\\LyXTable$")
-def update_tabular(file):
- lines = file.body
+def update_tabular(document):
+ " Update tabular to version 1 (xml like syntax). "
+ lines = document.body
i=0
- while 1:
+ while True:
i = find_re(lines, lyxtable_re, i)
if i == -1:
break
i = i + 1
lines[i] = "\\begin_inset Tabular"
i = i + 1
- head = string.split(lines[i])
+ head = lines[i].split()
rows = int(head[0])
columns = int(head[1])
row_info = []
cont_row = []
for j in range(rows):
- row_info.append(string.split(lines[i]))
- if string.split(lines[i])[2] == '1':
+ row_info.append(lines[i].split())
+ if lines[i].split()[2] == '1':
cont_row.append(j)
del lines[i]
continue
if l == ncells -1:
- # the end variable refers to cell end, not to file end.
+ # the end variable refers to cell end, not to document end.
end = find_tokens(lines, ['\\layout','\\the_end','\\end_deeper','\\end_float'], i)
else:
end = find_token(lines, '\\newline', i)
if end == -1:
- file.error("Malformed LyX file.")
+ document.error("Malformed LyX file.")
end = end - i
while end > 0:
del lines[i]
end = end -1
- if string.find(lines[i],'\\newline') != -1:
+ if lines[i].find('\\newline') != -1:
del lines[i]
l = l + 1
tmp.append('<Cell multicolumn="%s" alignment="%s" valignment="0" topline="%s" bottomline="%s" leftline="%d" rightline="%d" rotate="%s" usebox="%s" width=%s special=%s>' % (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]))
tmp.append('\\begin_inset Text')
tmp.append('')
- tmp.append('\\layout %s' % file.default_layout)
+ tmp.append('\\layout %s' % document.default_layout)
tmp.append('')
if cell_info[m][0] != '2':
prop_exp = re.compile(r"\\(\S*)\s*(\S*)")
-
def set_paragraph_properties(lines, prop_dict):
+ " Set paragraph properties."
# we need to preserve the order of options
properties = ["family","series","shape","size",
"emph","bar","noun","latex","color"]
return result[:]
-def update_language(file):
- header = file.header
+def update_language(document):
+ """ Update document language, if language is default convert it to
+ english."""
+ header = document.header
i = find_token(header, "\\language", 0)
if i == -1:
# no language, should emit a warning
header.append('\\language english')
return
# This is the lyx behaviour: defaults to english
- if string.split(header[i])[1] == 'default':
+ if header[i].split()[1] == 'default':
header[i] = '\\language english'
return
+supported_versions = ["1.1.6","1.1.6fix1","1.1.6fix2","1.1"]
convert = [[217, [update_tabular, update_language]]]
revert = []