]> git.lyx.org Git - features.git/commitdiff
Clean up empty ERTs that are produced in comples beamer argument conversions
authorJuergen Spitzmueller <spitz@lyx.org>
Sun, 25 May 2014 20:46:42 +0000 (22:46 +0200)
committerJuergen Spitzmueller <spitz@lyx.org>
Sun, 25 May 2014 20:46:42 +0000 (22:46 +0200)
lib/lyx2lyx/lyx_2_1.py

index cc08727f09babb6b0d4c56437be9e80eadbd3393..49993684cbb8ad3142bd57e81f282a55550ec207 100644 (file)
@@ -2515,6 +2515,42 @@ def convert_quote_args(document):
             i = j
 
 
+def cleanup_beamerargs(document):
+    " Clean up empty ERTs (conversion artefacts) "
+
+    beamer_classes = ["beamer", "article-beamer", "scrarticle-beamer"]
+    if document.textclass not in beamer_classes:
+        return
+
+    i = 0
+    while True:
+        i = find_token(document.body, "\\begin_inset Argument", i)
+        if i == -1:
+            return
+        j = find_end_of_inset(document.body, i)
+        if j == -1:
+            document.warning("Malformed LyX document: Can't find end of Argument inset")
+            i += 1
+            continue
+        while True:
+            ertbeg = find_token(document.body, "\\begin_inset ERT", i, j)
+            if ertbeg == -1:
+                break
+            ertend = find_end_of_inset(document.body, ertbeg)
+            if ertend == -1:
+                document.warning("Malformed LyX document: Can't find end of ERT inset")
+                break
+            stripped = [line for line in document.body[ertbeg : ertend + 1] if line.strip()]
+            if len(stripped) == 5:
+                # This is an empty ERT
+                offset = len(document.body[ertbeg : ertend + 1])
+                del document.body[ertbeg : ertend + 1]
+                j = j - offset
+            else:
+                i = ertend
+        i += 1
+
+
 def revert_beamerargs(document):
     " Reverts beamer arguments to old layout "
     
@@ -4702,7 +4738,7 @@ convert = [
            [471, [convert_cite_engine_type_default]],
            [472, []],
            [473, []],
-           [474, [convert_chunks]],
+           [474, [convert_chunks, cleanup_beamerargs]],
           ]
 
 revert =  [