# 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
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+""" Convert files to the file format generated by lyx 1.1.6, fix3 and fix4"""
+
import re
-import string
from parser_tools import find_token, find_re
def bool_table(item):
+ " Convert 0, 1 to false, true."
if item == "0":
return "false"
# should emit a warning if item != "1"
use_table = {"0": "none", "1": "parbox"}
table_meta_re = re.compile(r'<LyXTabular version="?1"? rows="?(\d*)"? columns="?(\d*)"?>')
-def update_tabular(file):
+def update_tabular(document):
+ " Update tabular format to version 2 (xml like syntax)."
regexp = re.compile(r'^\\begin_inset\s+Tabular')
- lines = file.body
+ lines = document.body
i=0
while 1:
i = find_re(lines, regexp, i)
j = find_token(lines, '</LyXTabular>', i) + 1
if j == 0:
- file.warning( "Error: Bad lyx format i=%d j=%d" % (i,j))
+ document.warning( "Error: Bad lyx format i=%d j=%d" % (i,j))
break
new_table = table_update(lines[i:j])
row_re = re.compile(r'<row topline="?(\d)"? bottomline="?(\d)"? newpage="?(\d)"?>')
def table_update(lines):
- lines[1] = string.replace(lines[1], '<Features', '<features')
+ " Update table's internal content to format 2."
+ lines[1] = lines[1].replace('<Features', '<features')
res = features_re.match( lines[1] )
if res:
val = res.groups()
i = 2
col_info = []
while i < len(lines):
- lines[i] = string.replace(lines[i], '<Cell', '<cell')
- lines[i] = string.replace(lines[i], '</Cell', '</cell')
- lines[i] = string.replace(lines[i], '<Row', '<row')
- lines[i] = string.replace(lines[i], '</Row', '</row')
- lines[i] = string.replace(lines[i], '<Column', '<column')
- lines[i] = string.replace(lines[i], '</Column', '</column')
- lines[i] = string.replace(lines[i], '</LyXTabular', '</lyxtabular')
- k = string.find (lines[i], '<column ')
+ lines[i] = lines[i].replace('<Cell', '<cell')
+ lines[i] = lines[i].replace('</Cell', '</cell')
+ lines[i] = lines[i].replace('<Row', '<row')
+ lines[i] = lines[i].replace('</Row', '</row')
+ lines[i] = lines[i].replace('<Column', '<column')
+ lines[i] = lines[i].replace('</Column', '</column')
+ lines[i] = lines[i].replace('</LyXTabular', '</lyxtabular')
+ k = lines[i].find ('<column ')
if k != -1:
col_info.append(lines[i])
del lines[i]
return lines[:2] + col_info + lines[2:]
+supported_versions = ["1.1.6fix3","1.1.6fix4","1.1"]
convert = [[218, [update_tabular]]]
revert = []