X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=lib%2Flyx2lyx%2Flyx_1_4.py;h=c1a4591b54055574e14d8bd3ef72041e136a860c;hb=7158f7b58d81e89c8e0dcd3a6eb8a53b89dc2619;hp=cd69f9f09a43920217b0be5362a5f657e9132e11;hpb=8b31062e5089f1921893804a1778cb62ebdcbac4;p=lyx.git diff --git a/lib/lyx2lyx/lyx_1_4.py b/lib/lyx2lyx/lyx_1_4.py index cd69f9f09a..c1a4591b54 100644 --- a/lib/lyx2lyx/lyx_1_4.py +++ b/lib/lyx2lyx/lyx_1_4.py @@ -16,7 +16,7 @@ # # 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.4""" @@ -24,7 +24,7 @@ import re from os import access, F_OK import os.path from parser_tools import check_token, find_token, \ - get_value, del_token, is_nonempty_line, \ + get_value, is_nonempty_line, \ find_tokens, find_end_of, find_beginning_of, find_token_exact, find_tokens_exact, \ find_re, find_tokens_backwards from sys import stdin @@ -84,6 +84,21 @@ def find_end_of_inset(lines, i): "Finds the matching \end_inset" return find_end_of(lines, i, "\\begin_inset", "\\end_inset") +def del_token(lines, token, start, end): + """ del_token(lines, token, start, end) -> int + + Find the lower line in lines where token is the first element and + delete that line. + + Returns the number of lines remaining.""" + + k = find_token_exact(lines, token, start, end) + if k == -1: + return end + else: + del lines[k] + return end - 1 + # End of helper functions #################################################################### @@ -466,6 +481,9 @@ def add_end_layout(document): document.body.insert(i,"") document.body.insert(i,"\\end_layout") i = i + 3 + # consecutive begin_deeper only insert one end_layout + while document.body[i].startswith('\\begin_deeper'): + i += 1 struct_stack.append(token) continue @@ -1477,7 +1495,7 @@ def convert_len(len, special): len = '%f\\' % len2value(len) + special # Convert LyX units to LaTeX units - for unit in units.keys(): + for unit in list(units.keys()): if len.find(unit) != -1: len = '%f' % (len2value(len) / 100) + units[unit] break @@ -1553,7 +1571,7 @@ def convert_frameless_box(document): 'inner_pos':1, 'use_parbox':'0', 'width':'100col%', 'special':'none', 'height':'1in', 'height_special':'totalheight', 'collapsed':'false'} - for key in params.keys(): + for key in list(params.keys()): value = get_value(document.body, key, i, j).replace('"', '') if value != "": if key == 'position': @@ -1823,20 +1841,38 @@ def convert_float(document): def revert_float(document): - " Revert sideway floats. " + " Revert sideways floats. " i = 0 while 1: i = find_token_exact(document.body, '\\begin_inset Float', i) if i == -1: return + line = document.body[i] + r = re.compile(r'\\begin_inset Float (.*)$') + m = r.match(line) + floattype = m.group(1) + if floattype != "figure" and floattype != "table": + i = i + 1 + continue j = find_end_of_inset(document.body, i) if j == -1: document.warning("Malformed lyx document: Missing '\\end_inset'.") i = i + 1 continue if get_value(document.body, 'sideways', i, j) != "false": - document.warning("Conversion of 'sideways true' not yet implemented.") - # Don't remove 'sideways' so that people will get warnings by lyx + l = find_token(document.body, "\\begin_layout Standard", i + 1, j) + if l == -1: + document.warning("Malformed LyX document: Missing `\\begin_layout Standard' in Float inset.") + return + document.body[j] = '\\layout Standard\n\\begin_inset ERT\nstatus Collapsed\n\n' \ + '\\layout Standard\n\n\n\\backslash\n' \ + 'end{sideways' + floattype + '}\n\n\\end_inset\n' + del document.body[i+1:l-1] + document.body[i] = '\\begin_inset ERT\nstatus Collapsed\n\n' \ + '\\layout Standard\n\n\n\\backslash\n' \ + 'begin{sideways' + floattype + '}\n\n\\end_inset\n\n' + add_to_preamble(document, + ['\\usepackage{rotfloat}\n']) i = i + 1 continue del_token(document.body, 'sideways', i, j) @@ -2298,11 +2334,11 @@ def convert_ert_paragraphs(document): if k == -1: break document.body[k:k+1] = ["\\end_layout", "", '\\begin_layout %s' % document.default_layout] - k = k + 4 - j = j + 3 + k = k + 3 + j = j + 2 # We need an empty line if document.default_layout == '' - if document.body[k-1] != '': - document.body.insert(k-1, '') + if document.body[k] != '': + document.body.insert(k, '') k = k + 1 j = j + 1 i = i + 1 @@ -2427,7 +2463,7 @@ def convert_sgml_paragraphs(document): i = i + 10 ## -# Convertion hub +# Conversion hub # supported_versions = ["1.4.%d" % i for i in range(3)] + ["1.4"]