From a99f3cc3c614478c6d19a8b8ec361b97e045076c Mon Sep 17 00:00:00 2001 From: Dekel Tsur Date: Tue, 6 Aug 2002 12:10:09 +0000 Subject: [PATCH] - Fix ert conversion - Convert old ERT insets git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@4875 a592a061-630c-0410-9148-cb99ea01b6c8 --- lib/lyx2lyx/lyxconvert_218.py | 26 ++++++++++++++++++++++++-- lib/lyx2lyx/parser_tools.py | 12 ++++++++++++ 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/lib/lyx2lyx/lyxconvert_218.py b/lib/lyx2lyx/lyxconvert_218.py index eddd6c8670..996788f995 100644 --- a/lib/lyx2lyx/lyxconvert_218.py +++ b/lib/lyx2lyx/lyxconvert_218.py @@ -185,8 +185,15 @@ def remove_oldert(lines): i = find_tokens(lines, ["\\latex latex", "\\layout LaTeX"], i) if i == -1: break - j = find_tokens(lines, ["\\latex default", "\\layout", "\\end_float", "\\the_end"], - i+1) + j = i+1 + while 1: + j = find_tokens(lines, ["\\latex default", "\\begin_inset", "\\layout", "\\end_float", "\\the_end"], + j) + if check_token(lines[j], "\\begin_inset"): + j = skip_inset(lines, j) + else: + break + if check_token(lines[j], "\\layout"): while j-1 >= 0 and check_token(lines[j-1], "\\begin_deeper"): j = j-1 @@ -261,6 +268,20 @@ def remove_oldert(lines): lines[i:j+1] = new i = i+1 +def convert_ertinset(lines): + i = 0 + while 1: + i = find_token(lines, "\\begin_inset ERT", i) + if i == -1: + break + j = find_token(lines, "collapsed", i+1) + if string.split(lines[j])[1] == "true": + status = "Collapsed" + else: + status = "Open" + lines[j] = "status " + status + i = i+1 + def is_ert_paragraph(lines, i): i = find_nonempty_line(lines, i+1) if not check_token(lines[i], "\\begin_inset ERT"): @@ -379,6 +400,7 @@ def convert(header, body): language = "english" change_preamble(header) + convert_ertinset(body) remove_oldert(body) combine_ert(body) remove_oldminipage(body) diff --git a/lib/lyx2lyx/parser_tools.py b/lib/lyx2lyx/parser_tools.py index 5acd869497..d657ba9f56 100644 --- a/lib/lyx2lyx/parser_tools.py +++ b/lib/lyx2lyx/parser_tools.py @@ -88,6 +88,18 @@ def get_paragraph(lines, i): count = count-1 i = i-1 +# Finds the matching \end_inset +def skip_inset(lines, i): + count = 1 + i = i+1 + while count > 0: + i = find_tokens(lines, ["\\end_inset", "\\begin_inset"], i) + if check_token(lines[i], "\\begin_inset"): + count = count+1 + else: + count = count-1 + i = i+1 + return i def is_nonempty_line(line): return line != " "*len(line)