- if (document.body[i] == "LatexCommand nocite"):
- j = find_end_of_inset(document.body, i + 1)
- if j == -1:
- #this should not happen
- document.warning("End of CommandInset citation not found in revert_nocite!")
- revert_nocite_key(document.body, i + 1, len(document.body))
- return
- revert_nocite_key(document.body, i + 1, j)
- document.body[i-1] = "\\begin_inset ERT"
- document.body[i:i+1] = ["status collapsed", "", "\\begin_layout Standard"]
- document.body[j+1:j+1] = ["\\end_layout", ""]
- i = j
+ if (document.body[i] != "LatexCommand nocite"):
+ # note that we already incremented i
+ continue
+ j = find_end_of_inset(document.body, i + 1)
+ if j == -1:
+ #this should not happen
+ document.warning("End of CommandInset citation not found in revert_nocite!")
+ return
+ # NOTE The order of these is important.
+ document.body[i-1] = "\\begin_inset ERT"
+ # Do this before we insert lines before j+1
+ document.body[j+1:j+1] = ["\\end_layout", ""]
+ # Do this before we insert lines before i+1
+ addedlines = revert_nocite_key(document.body, i + 1, j)
+ # Nothing has been inserted before this one
+ document.body[i:i+1] = ["status collapsed", "", "\\begin_layout Standard"]
+ i = j + 3 + addedlines