]> git.lyx.org Git - features.git/commitdiff
Remove latexdel insets comming from sgml2lyx (ref, url and htmlurl).
authorJosé Matox <jamatos@lyx.org>
Fri, 8 Jul 2005 08:49:29 +0000 (08:49 +0000)
committerJosé Matox <jamatos@lyx.org>
Fri, 8 Jul 2005 08:49:29 +0000 (08:49 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@10148 a592a061-630c-0410-9148-cb99ea01b6c8

lib/lyx2lyx/ChangeLog
lib/lyx2lyx/lyx_1_1_5.py

index aa294eb98b662e5ed6d99ee0dce8e75b895ce7a8..fd9b28f0bd88e6b91e85352ba12c3b492b66ad64 100644 (file)
@@ -1,3 +1,8 @@
+2005-07-08  José Matos  <jamatos@lyx.org>
+
+       * lyx_1_1_5.py (latexdel_getargs, update_ref, update_latexdel):
+       Remove latexdel insets comming from sgml2lyx (ref, url and htmlurl).
+
 2005-06-21  Georg Baum  <Georg.Baum@post.rwth-aachen.de>
 
        * lyx_1_4.py (convert_french): change language frenchb to french
index 00b84d2a3fafd9c2fc42f4e7307cae2610303bf0..645c1657d47eb49c7503659991574bfada1bc618 100644 (file)
@@ -159,9 +159,87 @@ def remove_space_in_units(file):
             i = i + 1
 
 
+def latexdel_getargs(file, i):
+    lines = file.body
+
+    # play safe, clean empty lines
+    while 1:
+        if lines[i]:
+            break
+        del lines[i]
+
+    j = find_token(lines, '\\end_inset', i)
+
+    if i == j:
+        del lines[i]
+    else:
+        file.warning("Unexpected end of inset.")
+    j = find_token(lines, '\\begin_inset LatexDel }{', i)
+
+    ref = string.join(lines[i:j])
+    del lines[i:j + 1]
+
+    # play safe, clean empty lines
+    while 1:
+        if lines[i]:
+            break
+        del lines[i]
+
+    j = find_token(lines, '\\end_inset', i - 1)
+    if i == j:
+        del lines[i]
+    else:
+        file.warning("Unexpected end of inset.")
+    j = find_token(lines, '\\begin_inset LatexDel }', i)
+    label = string.join(lines[i:j])
+    del lines[i:j + 1]
+
+    return ref, label
+
+
+def update_ref(file):
+    lines = file.body
+    i = 0
+    while 1:
+        i = find_token(lines, '\\begin_inset LatexCommand', i)
+        if i == -1:
+            return
+
+        if string.split(lines[i])[-1] == "\\ref{":
+            i = i + 1
+            ref, label = latexdel_getargs(file, i)
+            lines[i - 1] = "%s[%s]{%s}" % (lines[i - 1][:-1], ref, label)
+
+        i = i + 1
+
+
+def update_latexdel(file):
+    lines = file.body
+    i = 0
+    latexdel_re = re.compile(r".*\\begin_inset LatexDel")
+    while 1:
+        i = find_re(lines, latexdel_re, i)
+        if i == -1:
+            return
+        lines[i] = string.replace(lines[i],'\\begin_inset LatexDel', '\\begin_inset LatexCommand')
+
+        j = string.find(lines[i],'\\begin_inset')
+        lines.insert(i+1, lines[i][j:])
+        lines[i] = string.strip(lines[i][:j])
+        i = i + 1
+
+        if string.split(lines[i])[-1] in ("\\url{", "\\htmlurl{"):
+            i = i + 1
+
+            ref, label = latexdel_getargs(file, i)
+            lines[i -1] = "%s[%s]{%s}" % (lines[i-1][:-1], label, ref)
+
+        i = i + 1
+
+
 convert = [[216, [first_layout, remove_vcid, remove_cursor, update_toc,
                   replace_protected_separator, merge_formula_inset,
-                  update_tabular, remove_space_in_units]]]
+                  update_tabular, remove_space_in_units, update_ref, update_latexdel]]]
 revert  = []
 
 if __name__ == "__main__":