mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-25 05:55:34 +00:00
Cleanup
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@5027 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
72f30959c1
commit
839002cb96
@ -47,7 +47,7 @@ floats = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
font_tokens = ["\\family", "\\series", "\\shape", "\\size", "\\emph",
|
font_tokens = ["\\family", "\\series", "\\shape", "\\size", "\\emph",
|
||||||
"\\bar", "\\noun", "\\color", "\\lang"]
|
"\\bar", "\\noun", "\\color", "\\lang", "\\latex"]
|
||||||
|
|
||||||
#
|
#
|
||||||
# Change \begin_float .. \end_float into \begin_inset Float .. \end_inset
|
# Change \begin_float .. \end_float into \begin_inset Float .. \end_inset
|
||||||
@ -59,7 +59,9 @@ def remove_oldfloat(lines, language):
|
|||||||
i = find_token(lines, "\\begin_float", i)
|
i = find_token(lines, "\\begin_float", i)
|
||||||
if i == -1:
|
if i == -1:
|
||||||
break
|
break
|
||||||
|
# There are no nested floats, so finding the end of the float is simple
|
||||||
j = find_token(lines, "\\end_float", i+1)
|
j = find_token(lines, "\\end_float", i+1)
|
||||||
|
|
||||||
floattype = string.split(lines[i])[1]
|
floattype = string.split(lines[i])[1]
|
||||||
if not floats.has_key(floattype):
|
if not floats.has_key(floattype):
|
||||||
sys.stderr.write("Error! Unknown float type "+floattype+"\n")
|
sys.stderr.write("Error! Unknown float type "+floattype+"\n")
|
||||||
@ -70,11 +72,12 @@ def remove_oldfloat(lines, language):
|
|||||||
while check_token(lines[i2], "\\end_deeper"):
|
while check_token(lines[i2], "\\end_deeper"):
|
||||||
i2 = i2+1
|
i2 = i2+1
|
||||||
if i2 > i+1:
|
if i2 > i+1:
|
||||||
j2 = find_token(lines, "\\layout", j+1)
|
j2 = get_next_paragraph(lines, j+1)
|
||||||
lines[j2:j2] = ["\\end_deeper "]*(i2-(i+1))
|
lines[j2:j2] = ["\\end_deeper "]*(i2-(i+1))
|
||||||
|
|
||||||
new = floats[floattype]+[""]
|
new = floats[floattype]+[""]
|
||||||
new = new+lines[i2:j]+["\\end_inset ", ""]
|
new = new+lines[i2:j]+["\\end_inset ", ""]
|
||||||
|
|
||||||
# After a float, all font attribute are reseted.
|
# After a float, all font attribute are reseted.
|
||||||
# We need to output '\foo default' for every attribute foo
|
# We need to output '\foo default' for every attribute foo
|
||||||
# whose value is not default before the float.
|
# whose value is not default before the float.
|
||||||
@ -92,11 +95,11 @@ def remove_oldfloat(lines, language):
|
|||||||
flag = 1
|
flag = 1
|
||||||
new.append("")
|
new.append("")
|
||||||
if token == "\\lang":
|
if token == "\\lang":
|
||||||
new.append(token+" "+language+" ")
|
new.append(token+" "+language)
|
||||||
else:
|
else:
|
||||||
new.append(token+" default ")
|
new.append(token+" default ")
|
||||||
lines[i:j+1]= new
|
|
||||||
|
|
||||||
|
lines[i:j+1] = new
|
||||||
i = i+1
|
i = i+1
|
||||||
|
|
||||||
def remove_oldminipage(lines):
|
def remove_oldminipage(lines):
|
||||||
@ -401,12 +404,12 @@ def convert(header, body):
|
|||||||
language = "english"
|
language = "english"
|
||||||
|
|
||||||
change_preamble(header)
|
change_preamble(header)
|
||||||
remove_oldertinset(body)
|
|
||||||
remove_oldert(body)
|
|
||||||
combine_ert(body)
|
|
||||||
remove_oldminipage(body)
|
remove_oldminipage(body)
|
||||||
remove_oldfloat(body, language)
|
remove_oldfloat(body, language)
|
||||||
remove_figinset(body)
|
remove_figinset(body)
|
||||||
|
remove_oldertinset(body)
|
||||||
|
remove_oldert(body)
|
||||||
|
combine_ert(body)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
pass
|
pass
|
||||||
|
@ -74,33 +74,44 @@ def get_value(lines, token, start, end = 0):
|
|||||||
return string.split(lines[i])[1]
|
return string.split(lines[i])[1]
|
||||||
|
|
||||||
# Finds the paragraph that contains line i.
|
# Finds the paragraph that contains line i.
|
||||||
import sys
|
|
||||||
def get_paragraph(lines, i):
|
def get_paragraph(lines, i):
|
||||||
while 1:
|
while 1:
|
||||||
i = find_tokens_backwards(lines, ["\\end_inset", "\\layout"], i)
|
i = find_tokens_backwards(lines, ["\\end_inset", "\\layout"], i)
|
||||||
if check_token(lines[i], "\\layout"):
|
if check_token(lines[i], "\\layout"):
|
||||||
return i
|
return i
|
||||||
count = 1
|
i = find_beginning_of_inset(lines, i)
|
||||||
while count > 0:
|
|
||||||
i = find_tokens_backwards(lines, ["\\end_inset", "\\begin_inset"], i-1)
|
# Finds the paragraph after the paragraph that contains line i.
|
||||||
if check_token(lines[i], "\\end_inset"):
|
def get_next_paragraph(lines, i):
|
||||||
count = count+1
|
while 1:
|
||||||
else:
|
i = find_tokens(lines, ["\\begin_inset", "\\layout"], i)
|
||||||
count = count-1
|
if check_token(lines[i], "\\layout"):
|
||||||
|
return i
|
||||||
|
i = find_end_of_inset(lines, i)
|
||||||
|
|
||||||
# Finds the matching \end_inset
|
# Finds the matching \end_inset
|
||||||
def find_end_of_inset(lines, i):
|
def find_end_of_inset(lines, i):
|
||||||
count = 1
|
count = 1
|
||||||
i = i+1
|
|
||||||
while 1:
|
while 1:
|
||||||
i = find_tokens(lines, ["\\end_inset", "\\begin_inset"], i)
|
i = find_tokens(lines, ["\\end_inset", "\\begin_inset"], i+1)
|
||||||
if check_token(lines[i], "\\begin_inset"):
|
if check_token(lines[i], "\\begin_inset"):
|
||||||
count = count+1
|
count = count+1
|
||||||
else:
|
else:
|
||||||
count = count-1
|
count = count-1
|
||||||
if count == 0:
|
if count == 0:
|
||||||
return i
|
return i
|
||||||
i = i+1
|
|
||||||
|
# Finds the matching \end_inset
|
||||||
|
def find_beginning_of_inset(lines, i):
|
||||||
|
count = 1
|
||||||
|
while 1:
|
||||||
|
i = find_tokens_backwards(lines, ["\\end_inset", "\\begin_inset"], i-1)
|
||||||
|
if check_token(lines[i], "\\end_inset"):
|
||||||
|
count = count+1
|
||||||
|
else:
|
||||||
|
count = count-1
|
||||||
|
if count == 0:
|
||||||
|
return i
|
||||||
|
|
||||||
def is_nonempty_line(line):
|
def is_nonempty_line(line):
|
||||||
return line != " "*len(line)
|
return line != " "*len(line)
|
||||||
@ -113,7 +124,6 @@ def find_nonempty_line(lines, start, end = 0):
|
|||||||
return i
|
return i
|
||||||
return -1
|
return -1
|
||||||
|
|
||||||
|
|
||||||
def set_comment(lines, number):
|
def set_comment(lines, number):
|
||||||
x = int(number)
|
x = int(number)
|
||||||
if x < 216:
|
if x < 216:
|
||||||
|
Loading…
Reference in New Issue
Block a user