]> git.lyx.org Git - lyx.git/blobdiff - lib/lyx2lyx/parser_tools.py
Factor out some common code.
[lyx.git] / lib / lyx2lyx / parser_tools.py
index 3c4a4bdcd7c4c47971e9d0808ada7101500ac12f..43ebcd091c3d90625e483bed50fd3a408014ab04 100644 (file)
@@ -242,3 +242,18 @@ def find_end_of_inset(lines, i):
 def find_end_of_layout(lines, i):
     " Find end of layout, where lines[i] is included."
     return find_end_of(lines, i, "\\begin_layout", "\\end_layout")
+
+
+# checks if line i is in the inset e.g., "\\begin_inset CommandInset ref"
+# if so, returns starting and ending lines
+# otherwise, returns (-1, -1)
+def get_containing_inset(lines, i, inset):
+    defval = (-1, -1)
+    stins = find_token_backwards(lines, inset, i)
+    if stins == -1:
+      return defval
+    endins = find_end_of_inset(lines, stins)
+    # note that this includes the notfound case.
+    if endins < i:
+      return defval
+    return (stins, endins)