]> git.lyx.org Git - lyx.git/blob - lib/lyx2lyx/lyxconvert_217.py
remove all forgotten traces of help/
[lyx.git] / lib / lyx2lyx / lyxconvert_217.py
1 # This file is part of lyx2lyx
2 # -*- coding: iso-8859-1 -*-
3 # Copyright (C) 2002 José Matos <jamatos@lyx.org>
4 #
5 # This program is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU General Public License
7 # as published by the Free Software Foundation; either version 2
8 # of the License, or (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18
19 import re, string, sys
20 from parser_tools import *
21
22 def bool_table(item):
23     if item == "0":
24         return "false"
25     # should emit a warning if item != "1"
26     return "true"
27
28 align_table = {"0": "top", "2": "left", "4": "right", "8": "center"}
29 use_table = {"0": "none", "1": "parbox"}
30
31 table_meta_re = re.compile(r'<LyXTabular version="?1"? rows="?(\d*)"? columns="?(\d*)"?>')
32 def update_tabular(lines):
33     i=0
34     while 1:
35         i = find_token(lines, '\\begin_inset  Tabular', i)
36         if i == -1:
37             break
38
39         i = i +1
40
41         # scan table header meta-info
42         res = table_meta_re.match( lines[i] )
43         if res:
44             val = res.groups()
45             lines[i] = '<lyxtabular version="2" rows="%s" columns="%s">' % val
46
47         j = find_token(lines, '</LyXTabular>', i) + 1
48         if j == 0:
49             sys.stderr.write( "Error: Bad lyx format i=%d j=%d\n" % (i,j))
50             break
51
52         new_table = table_update(lines[i:j])
53         lines[i:j] = new_table
54         i = i + len(new_table)
55
56 col_re = re.compile(r'<column alignment="?(\d)"? valignment="?(\d)"? leftline="?(\d)"? rightline="?(\d)"? width="(.*)" special="(.*)">')
57 cell_re = re.compile(r'<cell multicolumn="?(\d)"? alignment="?(\d)"? valignment="?(\d)"? topline="?(\d)"? bottomline="?(\d)"? leftline="?(\d)"? rightline="?(\d)"? rotate="?(\d)"? usebox="?(\d)"? width="(.*)" special="(.*)">')
58 features_re = re.compile(r'<features rotate="?(\d)"? islongtable="?(\d)"? endhead="?(-?\d)"? endfirsthead="?(-?\d)"? endfoot="?(-?\d)"? endlastfoot="?(-?\d)"?>')
59 row_re = re.compile(r'<row topline="?(\d)"? bottomline="?(\d)"? newpage="?(\d)"?>')
60
61 def table_update(lines):
62     lines[1] = string.replace(lines[1], '<Features', '<features')
63     res = features_re.match( lines[1] )
64     if res:
65         val = res.groups()
66         lines[1] = '<features rotate="%s" islongtable="%s" endhead="%s" endfirsthead="%s" endfoot="%s" endlastfoot="%s">' % (bool_table(val[0]), bool_table(val[1]), val[2], val[3], val[4], val[5])
67
68     if lines[2]=="":
69         del lines[2]
70     i = 2
71     col_info = []
72     while i < len(lines):
73         lines[i] = string.replace(lines[i], '<Cell', '<cell')
74         lines[i] = string.replace(lines[i], '</Cell', '</cell')
75         lines[i] = string.replace(lines[i], '<Row', '<row')
76         lines[i] = string.replace(lines[i], '</Row', '</row')
77         lines[i] = string.replace(lines[i], '<Column', '<column')
78         lines[i] = string.replace(lines[i], '</Column', '</column')
79         lines[i] = string.replace(lines[i], '</LyXTabular', '</lyxtabular')
80         k = string.find (lines[i], '<column ')
81         if k != -1:
82             col_info.append(lines[i])
83             del lines[i]
84             continue
85
86         if lines[i] == '</column>' or lines[i] == '<column>':
87             del lines[i]
88             continue
89
90         res = cell_re.match(lines[i])
91         if res:
92             val = res.groups()
93             lines[i] = '<cell multicolumn="%s" alignment="%s" valignment="%s" topline="%s" bottomline="%s" leftline="%s" rightline="%s" rotate="%s" usebox="%s" width="%s" special="%s">' % ( val[0], align_table[val[1]], align_table[val[2]], bool_table(val[3]), bool_table(val[4]), bool_table(val[5]), bool_table(val[6]), bool_table(val[7]), use_table[val[8]], val[9], val[10])
94
95         res = row_re.match(lines[i])
96         if res:
97             val = res.groups()
98             lines[i] = '<row topline="%s" bottomline="%s" newpage="%s">' % (bool_table(val[0]), bool_table(val[1]), bool_table(val[2]))
99
100         i = i + 1
101
102     j = len(col_info)
103     for i in range(j):
104         res = col_re.match(col_info[i])
105         if res:
106             val = res.groups()
107             col_info[i] = '<column alignment="%s" valignment="%s" leftline="%s" rightline="%s" width="%s" special="%s">' \
108                           % ( align_table[val[0]], align_table[val[1]], bool_table(val[2]), bool_table(val[3]), val[4],val[5])
109
110     return lines[:2] + col_info + lines[2:]
111
112 def convert(header,body):
113     update_tabular(body)
114
115 if __name__ == "__main__":
116     pass
117