]> git.lyx.org Git - lyx.git/blob - lib/lyx2lyx/lyx_2_0.py
Allow users to specify toolbar icons for commands with a backslash. This is in the...
[lyx.git] / lib / lyx2lyx / lyx_2_0.py
1 # This file is part of lyx2lyx
2 # -*- coding: utf-8 -*-
3 # Copyright (C) 2008 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 """ Convert files to the file format generated by lyx 2.0"""
20
21 import re
22
23 from parser_tools import find_token, find_end_of, find_tokens, get_value, get_value_string
24
25 ####################################################################
26 # Private helper functions
27
28 def find_end_of_inset(lines, i):
29     " Find end of inset, where lines[i] is included."
30     return find_end_of(lines, i, "\\begin_inset", "\\end_inset")
31
32 ####################################################################
33
34
35 def revert_swiss(document):
36     "Set language german-ch to ngerman"
37     i = 0
38     if document.language == "german-ch":
39         document.language = "ngerman"
40         i = find_token(document.header, "\\language", 0)
41         if i != -1:
42             document.header[i] = "\\language ngerman"
43     j = 0
44     while True:
45         j = find_token(document.body, "\\lang german-ch", j)
46         if j == -1:
47             return
48         document.body[j] = document.body[j].replace("\\lang german-ch", "\\lang ngerman")
49         j = j + 1
50
51 def revert_tabularvalign(document):\r
52    "Revert the tabular valign option"\r
53    i = 0\r
54    while True:\r
55        i = find_token(document.body, "\\begin_inset Tabular", i)\r
56        if i == -1:\r
57            return\r
58        j = find_end_of_inset(document.body, i)\r
59        if j == -1:\r
60            document.warning("Malformed LyX document: Could not find end of tabular.")\r
61            i = j\r
62            continue\r
63 \r
64        k = find_token(document.body, "<features tabularvalignment=", i)\r
65        if k == -1:\r
66            i = j\r
67            continue\r
68 \r
69        # which valignment is specified?\r
70        tabularvalignment_re = re.compile(r'<features tabularvalignment="(top|bottom)">')\r
71        m = tabularvalignment_re.match(document.body[k])\r
72        if not m:\r
73            i = j\r
74            continue\r
75 \r
76        tabularvalignment = m.group(1)\r
77 \r
78        subst = ['\\end_layout', '\\end_inset']\r
79        document.body[j+1:j+1] = subst # just inserts those lines\r
80        subst = ['\\begin_inset Box Frameless',\r
81            'position "' + tabularvalignment[0] +'"',\r
82            'hor_pos "c"',\r
83            'has_inner_box 1',\r
84            'inner_pos "c"',\r
85            'use_parbox 0',\r
86            'width "0col%"',\r
87            'special "none"',\r
88            'height "1in"',\r
89            'height_special "totalheight"',\r
90            'status open',\r
91            '',\r
92            '\\begin_layout Plain Layout']\r
93        document.body[i:i] = subst # this just inserts the array at i\r
94        i += len(subst) + 2 # adjust i to save a few cycles 
95
96 ##
97 # Conversion hub
98 #
99
100 supported_versions = ["2.0.0","2.0"]
101 convert = [[346, []],
102            [347, []]
103           ]
104
105 revert =  [[346, [revert_tabularvalign]],
106            [345, [revert_swiss]]
107           ]
108
109
110 if __name__ == "__main__":
111     pass