mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-22 21:21:32 +00:00
Add limits to searches in convert_TeX_brace_to_Argument.
This commit is contained in:
parent
d863a76f45
commit
eb26d85dc9
@ -120,21 +120,28 @@ def convert_TeX_brace_to_Argument(document, line, n, nmax, inset, environment, o
|
|||||||
|
|
||||||
Todo: this routine can currently handle only one mandatory argument of environments
|
Todo: this routine can currently handle only one mandatory argument of environments
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
end_layout = find_end_of_layout(document.body, line)
|
||||||
lineERT = line
|
lineERT = line
|
||||||
endn = line
|
endn = line
|
||||||
loop = 1
|
loop = 1
|
||||||
while lineERT != -1 and n < nmax + 1:
|
while n < nmax + 1:
|
||||||
lineERT = find_token(document.body, "\\begin_inset ERT", lineERT)
|
lineERT = find_token(document.body, "\\begin_inset ERT", lineERT, end_layout)
|
||||||
if environment == False and lineERT != -1:
|
if lineERT == -1:
|
||||||
bracePair = -1
|
break
|
||||||
|
if environment == False:
|
||||||
|
end_ERT = find_end_of_inset(document.body, lineERT)
|
||||||
|
if end_ERT == -1:
|
||||||
|
document.warning("Can't find end of ERT!!")
|
||||||
|
break
|
||||||
|
# Note that this only checks for ][ or }{ at the beginning of a line
|
||||||
if opt:
|
if opt:
|
||||||
bracePair = find_token(document.body, "][", lineERT)
|
bracePair = find_token(document.body, "][", lineERT, end_ERT)
|
||||||
else:
|
else:
|
||||||
bracePair = find_token(document.body, "}{", lineERT)
|
bracePair = find_token(document.body, "}{", lineERT, end_ERT)
|
||||||
# assure that the "}{" is in this ERT
|
if bracePair != -1:
|
||||||
if bracePair == lineERT + 5:
|
|
||||||
end = find_token(document.body, "\\end_inset", bracePair)
|
end = find_token(document.body, "\\end_inset", bracePair)
|
||||||
document.body[lineERT : end + 1] = ["\\end_layout", "", "\\end_inset"]
|
document.body[lineERT : end_ERT + 1] = ["\\end_layout", "", "\\end_inset"]
|
||||||
if loop == 1:
|
if loop == 1:
|
||||||
# in the case that n > 1 we have optional arguments before
|
# in the case that n > 1 we have optional arguments before
|
||||||
# therefore detect them if any
|
# therefore detect them if any
|
||||||
@ -156,24 +163,22 @@ def convert_TeX_brace_to_Argument(document, line, n, nmax, inset, environment, o
|
|||||||
document.body[line + 1 : line + 1] = ["\\begin_inset Argument " + str(n), "status open", "", "\\begin_layout Plain Layout"]
|
document.body[line + 1 : line + 1] = ["\\begin_inset Argument " + str(n), "status open", "", "\\begin_layout Plain Layout"]
|
||||||
else:
|
else:
|
||||||
document.body[line + 4 : line + 4] = ["\\begin_inset Argument " + str(n), "status open", "", "\\begin_layout Plain Layout"]
|
document.body[line + 4 : line + 4] = ["\\begin_inset Argument " + str(n), "status open", "", "\\begin_layout Plain Layout"]
|
||||||
else:
|
else: # if loop != 1
|
||||||
document.body[endn : endn] = ["\\begin_inset Argument " + str(n), "status open", "", "\\begin_layout Plain Layout"]
|
document.body[endn : endn] = ["\\begin_inset Argument " + str(n), "status open", "", "\\begin_layout Plain Layout"]
|
||||||
n += 1
|
n += 1
|
||||||
endn = end
|
endn = end
|
||||||
loop = loop + 1
|
loop += 1
|
||||||
# now check the case that we have "}" + "{" in two ERTs
|
# now check the case that we have "}" + "{" in two ERTs
|
||||||
else:
|
else: # no brace pair found
|
||||||
endBrace = -1
|
|
||||||
if opt:
|
if opt:
|
||||||
endBrace = find_token(document.body, "]", lineERT)
|
endBrace = find_token(document.body, "]", lineERT, end_layout)
|
||||||
else:
|
else:
|
||||||
endBrace = find_token(document.body, "}", lineERT)
|
endBrace = find_token(document.body, "}", lineERT, end_layout)
|
||||||
if endBrace == lineERT + 5:
|
if endBrace == lineERT + 5:
|
||||||
beginBrace = -1
|
|
||||||
if opt:
|
if opt:
|
||||||
beginBrace = find_token(document.body, "[", endBrace)
|
beginBrace = find_token(document.body, "[", endBrace, end_layout)
|
||||||
else:
|
else:
|
||||||
beginBrace = find_token(document.body, "{", endBrace)
|
beginBrace = find_token(document.body, "{", endBrace, end_layout)
|
||||||
# assure that the ERTs are consecutive (11 or 12 depending if there is a space between the ERTs or not)
|
# assure that the ERTs are consecutive (11 or 12 depending if there is a space between the ERTs or not)
|
||||||
if beginBrace == endBrace + 11 or beginBrace == endBrace + 12:
|
if beginBrace == endBrace + 11 or beginBrace == endBrace + 12:
|
||||||
end = find_token(document.body, "\\end_inset", beginBrace)
|
end = find_token(document.body, "\\end_inset", beginBrace)
|
||||||
@ -212,27 +217,32 @@ def convert_TeX_brace_to_Argument(document, line, n, nmax, inset, environment, o
|
|||||||
lineERT += 1
|
lineERT += 1
|
||||||
else:
|
else:
|
||||||
lineERT += 1
|
lineERT += 1
|
||||||
if environment == True and lineERT != -1:
|
if environment == True:
|
||||||
opening = -1
|
end_ERT = find_end_of_inset(document.body, lineERT)
|
||||||
|
if end_ERT == -1:
|
||||||
|
document.warning("Can't find end of ERT!!")
|
||||||
|
break
|
||||||
|
# Note that this only checks for [ or { at the beginning of a line
|
||||||
if opt:
|
if opt:
|
||||||
opening = find_token(document.body, "[", lineERT)
|
opening = find_token(document.body, "[", lineERT, end_ERT)
|
||||||
else:
|
else:
|
||||||
opening = find_token(document.body, "{", lineERT)
|
opening = find_token(document.body, "{", lineERT, end_ERT)
|
||||||
if opening == lineERT + 5: # assure that the "{" is in this ERT
|
if opening != -1:
|
||||||
end = find_token(document.body, "\\end_inset", opening)
|
document.body[lineERT : end_ERT + 1] = ["\\begin_inset Argument " + str(n), "status open", "", "\\begin_layout Plain Layout"]
|
||||||
document.body[lineERT : end + 1] = ["\\begin_inset Argument " + str(n), "status open", "", "\\begin_layout Plain Layout"]
|
|
||||||
n += 1
|
n += 1
|
||||||
lineERT2 = find_token(document.body, "\\begin_inset ERT", lineERT)
|
lineERT2 = find_token(document.body, "\\begin_inset ERT", end_ERT, end_layout)
|
||||||
closing = -1
|
if lineERT2 != -1:
|
||||||
|
end_ERT2 = find_end_of_inset(document.body, lineERT)
|
||||||
|
if end_ERT2 == -1:
|
||||||
|
document.warning("Can't find end of second ERT!!")
|
||||||
|
break
|
||||||
if opt:
|
if opt:
|
||||||
closing = find_token(document.body, "]", lineERT)
|
closing = find_token(document.body, "]", lineERT2, end_ERT2)
|
||||||
else:
|
else:
|
||||||
closing = find_token(document.body, "}", lineERT2)
|
closing = find_token(document.body, "}", lineERT2, end_ERT2)
|
||||||
if closing == lineERT2 + 5: # assure that the "}" is in this ERT
|
if closing != -1: # assure that the "}" is in this ERT
|
||||||
end2 = find_token(document.body, "\\end_inset", closing)
|
end2 = find_token(document.body, "\\end_inset", closing)
|
||||||
document.body[lineERT2 : end2 + 1] = ["\\end_layout", "", "\\end_inset"]
|
document.body[lineERT2 : end2 + 1] = ["\\end_layout", "", "\\end_inset"]
|
||||||
else:
|
|
||||||
lineERT += 1
|
|
||||||
|
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
Loading…
Reference in New Issue
Block a user