diff --git a/lib/lyx2lyx/lyx_2_0.py b/lib/lyx2lyx/lyx_2_0.py index 27c4415c38..171fa634e7 100644 --- a/lib/lyx2lyx/lyx_2_0.py +++ b/lib/lyx2lyx/lyx_2_0.py @@ -1415,27 +1415,65 @@ def revert_math_output(document): def revert_inset_preview(document): " Dissolves the preview inset " i = 0 - j = 0 - k = 0 while True: i = find_token(document.body, "\\begin_inset Preview", i) if i == -1: return - j = find_end_of_inset(document.body, i) - if j == -1: + iend = find_end_of_inset(document.body, i) + if iend == -1: document.warning("Malformed LyX document: Could not find end of Preview inset.") - return - #If the layout is Standard we need to remove it, otherwise there - #will be paragraph breaks that shouldn't be there. - k = find_token(document.body, "\\begin_layout Standard", i) - if k == i + 2: - del document.body[i:i + 3] - del document.body[j - 5:j - 2] - i -= 6 - else: - del document.body[i] - del document.body[j - 1] - i -= 2 + i += 1 + continue + + del document.body[iend] + del document.body[i] + + # This does not work. The problem is that the last layout may not be + # standard, in which case the material following the preview, which + # might be in this same paragraph, will now be in whatever that was. + # Moreover, the right action might depend upon what layout we are in, + # and that is not easy to find out. It is much harder to fix that kind + # of problem than to remove a paragraph break. + # So I am disabling all of this for now, at least. If someone wants to + # fix it, then feel free. + + ## If the first layout is Standard we need to remove it, otherwise there + ## will be paragraph breaks that shouldn't be there. + #blay = find_token(document.body, "\\begin_layout", i, iend) + #if blay == -1: + #document.warning("Can't find layout for preview inset!") + ## always do the later one first... + #del document.body[iend] + #del document.body[i] + ## deletions mean we do not need to reset i + #continue + #lay = document.body[blay].split(None, 1)[1] + #if lay != "Standard": + #del document.body[iend] + #del document.body[i] + ## deletions mean we do not need to reset i + #continue + + ## we want to delete the last \\end_layout in this inset, too. + ## note that this may not be the \\end_layout that goes with blay!! + #bend = find_end_of_layout(document.body, blay) + ##while True: + ##tmp = find_token(document.body, "\\end_layout", bend + 1, iend) + ##if tmp == -1: + ##break + ##bend = tmp + ##if bend == blay: + #if bend == -1: + #document.warning("Unable to find last layout in preview inset!") + #del document.body[iend] + #del document.body[i] + ## deletions mean we do not need to reset i + #continue + ## always do the later one first... + #del [iend] + #del document.body[bend] + #del document.body[i:blay + 1] + # we do not need to reset i def revert_equalspacing_xymatrix(document):