#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- find_tokens, find_tokens_backwards, find_beginning_of, find_end_of, find_re, \
+ find_tokens, find_tokens_backwards, \
+ find_beginning_of, find_end_of, find_re, \
# Private helper functions
def get_layout(line, default_layout):
# Private helper functions
def get_layout(line, default_layout):
tokens = ["\\begin_inset", "\\layout", "\\end_float", "\\the_end"]
while i != -1:
tokens = ["\\begin_inset", "\\layout", "\\end_float", "\\the_end"]
while i != -1:
return find_beginning_of(lines, i, "\\begin_inset", "\\end_inset")
return find_beginning_of(lines, i, "\\begin_inset", "\\end_inset")
return find_end_of(lines, i, "\\begin_inset", "\\end_inset")
def find_end_of_tabular(lines, i):
return find_end_of(lines, i, "\\begin_inset", "\\end_inset")
def find_end_of_tabular(lines, i):
return find_end_of(lines, i, "<lyxtabular", "</lyxtabular")
def get_tabular_lines(lines, i):
return find_end_of(lines, i, "<lyxtabular", "</lyxtabular")
def get_tabular_lines(lines, i):
-#
-# Change \begin_float .. \end_float into \begin_inset Float .. \end_inset
-#
-def remove_oldfloat(file):
- lines = file.body
+def remove_oldfloat(document):
+ " Change \begin_float .. \end_float into \begin_inset Float .. \end_inset"
+ lines = document.body
# There are no nested floats, so finding the end of the float is simple
j = find_token(lines, "\\end_float", i+1)
# There are no nested floats, so finding the end of the float is simple
j = find_token(lines, "\\end_float", i+1)
# as extra '\foo default' commands are ignored.
# In fact, it might be safer to output '\foo default' for all
# font attributes.
# as extra '\foo default' commands are ignored.
# In fact, it might be safer to output '\foo default' for all
# font attributes.
flag = 0
for token in font_tokens:
if find_token(lines, token, k, i) != -1:
flag = 0
for token in font_tokens:
if find_token(lines, token, k, i) != -1:
pextra_type2_rexp2 = re.compile(r".*(\\layout|\\pextra_type\s+2)")
pextra_widthp = re.compile(r"\\pextra_widthp")
pextra_type2_rexp2 = re.compile(r".*(\\layout|\\pextra_type\s+2)")
pextra_widthp = re.compile(r"\\pextra_widthp")
i = 0
while 1:
i = find_tokens(lines, ["\\latex latex", "\\layout LaTeX"], i)
i = 0
while 1:
i = find_tokens(lines, ["\\latex latex", "\\layout LaTeX"], i)
-# ERT insert are hidden feature of lyx 1.1.6. This might be removed in the future.
-def remove_oldertinset(file):
- lines = file.body
+def remove_oldertinset(document):
+ " ERT insert are hidden feature of lyx 1.1.6. This might be removed in the future."
+ lines = document.body
break
j = find_end_of_inset(lines, i)
k = find_token(lines, "\\layout", i+1)
break
j = find_end_of_inset(lines, i)
k = find_token(lines, "\\layout", i+1)
oldunits = ["pt", "cm", "in", "text%", "col%"]
def get_length(lines, name, start, end):
oldunits = ["pt", "cm", "in", "text%", "col%"]
def get_length(lines, name, start, end):
i = find_token(lines, name, start, end)
if i == -1:
return ""
i = find_token(lines, name, start, end)
if i == -1:
return ""
return x[2]+oldunits[int(x[1])]
def write_attribute(x, token, value):
return x[2]+oldunits[int(x[1])]
def write_attribute(x, token, value):
- if ( len(string.split(lines[i])) > 2 ):
- lyxwidth = string.split(lines[i])[3]+"pt"
- lyxheight = string.split(lines[i])[4]+"pt"
+ if ( len(lines[i].split()) > 2 ):
+ lyxwidth = lines[i].split()[3]+"pt"
+ lyxheight = lines[i].split()[4]+"pt"
for k in get_tabular_lines(lines, i):
if check_token(lines[k], "<lyxtabular"):
for k in get_tabular_lines(lines, i):
if check_token(lines[k], "<lyxtabular"):
if line_re.match(lines[k]):
lines[k] = re.sub(attr_re, "", lines[k])
if line_re.match(lines[k]):
lines[k] = re.sub(attr_re, "", lines[k])
def setHeaderFooterRows(hr, fhr, fr, lfr, rows_, row_info):
def setHeaderFooterRows(hr, fhr, fr, lfr, rows_, row_info):
longtable_re = re.compile(r'islongtable="(\w)"')
ltvalues_re = re.compile(r'endhead="(-?\d*)" endfirsthead="(-?\d*)" endfoot="(-?\d*)" endlastfoot="(-?\d*)"')
lt_features_re = re.compile(r'(endhead="-?\d*" endfirsthead="-?\d*" endfoot="-?\d*" endlastfoot="-?\d*")')
longtable_re = re.compile(r'islongtable="(\w)"')
ltvalues_re = re.compile(r'endhead="(-?\d*)" endfirsthead="(-?\d*)" endfoot="(-?\d*)" endlastfoot="(-?\d*)"')
lt_features_re = re.compile(r'(endhead="-?\d*" endfirsthead="-?\d*" endfoot="-?\d*" endlastfoot="-?\d*")')
-# Figure insert are hidden feature of lyx 1.1.6. This might be removed in the future.
-def fix_oldfloatinset(file):
- lines = file.body
+def fix_oldfloatinset(document):
+ " Figure insert are hidden feature of lyx 1.1.6. This might be removed in the future."
+ lines = document.body
new = ["\\begin_inset Note", "collapsed true", ""]
j = find_token(lines, "\\end_inset", i)
if j == -1:
new = ["\\begin_inset Note", "collapsed true", ""]
j = find_token(lines, "\\end_inset", i)
if j == -1:
- new = new + ['\layout %s' % file.default_layout, ""]
- tmp = string.split(line, '\\')
+ new = new + ['\layout %s' % document.default_layout, ""]
+ tmp = line.split('\\')
convert = [[220, [change_header, change_listof, fix_oldfloatinset,
update_tabular, update_longtables, remove_pextra,
remove_oldfloat, remove_figinset, remove_oldertinset,
convert = [[220, [change_header, change_listof, fix_oldfloatinset,
update_tabular, update_longtables, remove_pextra,
remove_oldfloat, remove_figinset, remove_oldertinset,