]> git.lyx.org Git - lyx.git/blob - lib/lyx2lyx/lyxrevert_225.py
Modify the InsetBox format to always start 'Box'.
[lyx.git] / lib / lyx2lyx / lyxrevert_225.py
1 # This file is part of lyx2lyx
2 # Copyright (C) 2003 Jos\81é Matos <jamatos@fep.up.pt>
3 #
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
17
18 import re
19 from parser_tools import find_token, find_end_of_inset
20 from string import replace
21
22 def rm_end_layout(lines):
23     i = 0
24     while 1:
25         i = find_token(lines, '\\end_layout', i)
26
27         if i == -1:
28             return
29
30         del lines[i]
31
32 def begin_layout2layout(lines):
33     i = 0
34     while 1:
35         i = find_token(lines, '\\begin_layout', i)
36         if i == -1:
37             return
38
39         lines[i] = replace(lines[i], '\\begin_layout', '\\layout')
40         i = i + 1
41
42 def table_valignment_middle(lines, start, end):
43     for i in range(start, end):
44         if re.search('^<(column|cell) .*valignment="middle".*>$', lines[i]):
45             lines[i] = replace(lines[i], 'valignment="middle"', 'valignment="center"')
46
47 def valignment_middle(lines):
48     i = 0
49     while 1:
50         i = find_token(lines, '\\begin_inset  Tabular', i)
51         if i == -1:
52             return
53         j = find_end_of_inset(lines, i + 1)
54         if j == -1:
55             #this should not happen
56             valignment_middle(lines, i + 1, len(lines))
57             return
58         valignment_middle(lines, i + 1, j)
59         i = j + 1
60
61 def end_document(lines):
62     i = find_token(lines, "\\end_document", 0)
63     if i == -1:
64         lines.append("\\the_end")
65         return
66     lines[i] = "\\the_end"
67
68 def convert(header, body):
69     rm_end_layout(body)
70     begin_layout2layout(body)
71     end_document(body)
72     valignment_middle(body)
73
74 if __name__ == "__main__":
75     pass