mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-25 19:07:45 +00:00
Clean up split index reversion routine.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@36026 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
ab80a57edd
commit
3bb4bbd8b8
@ -682,9 +682,12 @@ def revert_splitindex(document):
|
|||||||
return
|
return
|
||||||
indices = get_value(document.header, "\\use_indices", i)
|
indices = get_value(document.header, "\\use_indices", i)
|
||||||
preamble = ""
|
preamble = ""
|
||||||
if indices == "true":
|
useindices = (indices == "true")
|
||||||
|
if useindices:
|
||||||
preamble += "\\usepackage{splitidx}\n"
|
preamble += "\\usepackage{splitidx}\n"
|
||||||
del document.header[i]
|
del document.header[i]
|
||||||
|
|
||||||
|
# deal with index declarations in the preamble
|
||||||
i = 0
|
i = 0
|
||||||
while True:
|
while True:
|
||||||
i = find_token(document.header, "\\index", i)
|
i = find_token(document.header, "\\index", i)
|
||||||
@ -694,17 +697,20 @@ def revert_splitindex(document):
|
|||||||
if k == -1:
|
if k == -1:
|
||||||
document.warning("Malformed LyX document: Missing \\end_index.")
|
document.warning("Malformed LyX document: Missing \\end_index.")
|
||||||
return
|
return
|
||||||
line = document.header[i]
|
if useindices:
|
||||||
l = re.compile(r'\\index (.*)$')
|
line = document.header[i]
|
||||||
m = l.match(line)
|
l = re.compile(r'\\index (.*)$')
|
||||||
iname = m.group(1)
|
m = l.match(line)
|
||||||
ishortcut = get_value(document.header, '\\shortcut', i, k)
|
iname = m.group(1)
|
||||||
if ishortcut != "" and indices == "true":
|
ishortcut = get_value(document.header, '\\shortcut', i, k)
|
||||||
preamble += "\\newindex[" + iname + "]{" + ishortcut + "}\n"
|
if ishortcut != "":
|
||||||
|
preamble += "\\newindex[" + iname + "]{" + ishortcut + "}\n"
|
||||||
del document.header[i:k + 1]
|
del document.header[i:k + 1]
|
||||||
i = 0
|
|
||||||
if preamble != "":
|
if preamble != "":
|
||||||
insert_to_preamble(0, document, preamble)
|
insert_to_preamble(0, document, preamble)
|
||||||
|
|
||||||
|
# deal with index insets
|
||||||
|
# these need to have the argument removed
|
||||||
i = 0
|
i = 0
|
||||||
while True:
|
while True:
|
||||||
i = find_token(document.body, "\\begin_inset Index", i)
|
i = find_token(document.body, "\\begin_inset Index", i)
|
||||||
@ -719,13 +725,17 @@ def revert_splitindex(document):
|
|||||||
else:
|
else:
|
||||||
k = find_end_of_inset(document.body, i)
|
k = find_end_of_inset(document.body, i)
|
||||||
if k == -1:
|
if k == -1:
|
||||||
return
|
document.warning("Can't find end of index inset!")
|
||||||
|
i += 1
|
||||||
|
continue
|
||||||
content = lyx2latex(document, document.body[i:k])
|
content = lyx2latex(document, document.body[i:k])
|
||||||
# escape quotes
|
# escape quotes
|
||||||
content = content.replace('"', r'\"')
|
content = content.replace('"', r'\"')
|
||||||
subst = [old_put_cmd_in_ert("\\sindex[" + itype + "]{" + content + "}")]
|
subst = put_cmd_in_ert("\\sindex[" + itype + "]{" + content + "}")
|
||||||
document.body[i:k + 1] = subst
|
document.body[i:k + 1] = subst
|
||||||
i = i + 1
|
i = i + 1
|
||||||
|
|
||||||
|
# deal with index_print insets
|
||||||
i = 0
|
i = 0
|
||||||
while True:
|
while True:
|
||||||
i = find_token(document.body, "\\begin_inset CommandInset index_print", i)
|
i = find_token(document.body, "\\begin_inset CommandInset index_print", i)
|
||||||
@ -736,10 +746,10 @@ def revert_splitindex(document):
|
|||||||
if ptype == "idx":
|
if ptype == "idx":
|
||||||
j = find_token(document.body, "type", i, k)
|
j = find_token(document.body, "type", i, k)
|
||||||
del document.body[j]
|
del document.body[j]
|
||||||
elif indices == "false":
|
elif not useindices:
|
||||||
del document.body[i:k + 1]
|
del document.body[i:k + 1]
|
||||||
else:
|
else:
|
||||||
subst = [old_put_cmd_in_ert("\\printindex[" + ptype + "]{}")]
|
subst = put_cmd_in_ert("\\printindex[" + ptype + "]{}")
|
||||||
document.body[i:k + 1] = subst
|
document.body[i:k + 1] = subst
|
||||||
i = i + 1
|
i = i + 1
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user