from parser_tools import find_token, find_re, check_token
-def space_before_layout(lines):
+def space_before_layout(file):
+ lines = file.body
i = 2 # skip first layout
while 1:
i = find_token(lines, '\\layout', i)
i = i + 1
-def formula_inset_space_eat(lines):
+def formula_inset_space_eat(file):
+ lines = file.body
i=0
while 1:
i = find_token(lines, "\\begin_inset Formula", i)
# Update from tabular format 2 to 4
-def update_tabular(lines):
+def update_tabular(file):
+ lines = file.body
lyxtable_re = re.compile(r".*\\LyXTable$")
i=0
while 1:
i = i + 1
-def final_dot(lines):
+def final_dot(file):
+ lines = file.body
i = 0
while i < len(lines):
if lines[i][-1:] == '.' and lines[i+1][:1] != '\\' and lines[i+1][:1] != ' ' and len(lines[i]) + len(lines[i+1])<= 72 and lines[i+1] != '':
i = i + 1
-def update_inset_label(lines):
+def update_inset_label(file):
+ lines = file.body
i = 0
while 1:
i = find_token(lines, '\\begin_inset Label', i)
i = i + 1
-def update_latexdel(lines):
+def update_latexdel(file):
+ lines = file.body
i = 0
while 1:
i = find_token(lines, '\\begin_inset LatexDel', i)
i = i + 1
-def update_vfill(lines):
+def update_vfill(file):
+ lines = file.body
for i in range(len(lines)):
lines[i] = string.replace(lines[i],'\\fill_top','\\added_space_top vfill')
lines[i] = string.replace(lines[i],'\\fill_bottom','\\added_space_bottom vfill')
-def update_space_units(lines):
+def update_space_units(file):
+ lines = file.body
added_space_bottom = re.compile(r'\\added_space_bottom ([^ ]*)')
added_space_top = re.compile(r'\\added_space_top ([^ ]*)')
for i in range(len(lines)):
lines[i] = string.replace(lines[i], old, new)
-def update_inset_accent(lines):
- pass
-
-
-def remove_cursor(lines):
+def remove_cursor(file):
+ lines = file.body
i = 0
cursor_re = re.compile(r'.*(\\cursor \d*)')
while 1:
i = i + 1
-def remove_empty_insets(lines):
+def remove_empty_insets(file):
+ lines = file.body
i = 0
while 1:
i = find_token(lines, '\\begin_inset ',i)
i = i + 1
-def remove_formula_latex(lines):
+def remove_formula_latex(file):
+ lines = file.body
i = 0
while 1:
i = find_token(lines, '\\latex formula_latex ', i)
del lines[i]
-def add_end_document(lines):
+def add_end_document(file):
+ lines = file.body
i = find_token(lines, '\\the_end', 0)
if i == -1:
lines.append('\\the_end')
-def header_update(lines, file):
+def header_update(file):
+ lines = file.header
i = 0
l = len(lines)
while i < l:
i = i + 1
-def update_latexaccents(body):
+def update_latexaccents(file):
+ body = file.body
i = 1
while 1:
i = find_token(body, '\\i ', i)
contents = string.strip(body[i][2:])
+ if string.find(contents, '{') != -1 and string.find(contents, '}') != -1:
+ i = i + 1
+ continue
+
if len(contents) == 2:
contents = contents + '{}'
elif len(contents) == 3:
i = i + 1
-def convert(file):
- header_update(file.header, file)
- add_end_document(file.body)
- remove_cursor(file.body)
- final_dot(file.body)
- update_inset_label(file.body)
- update_latexdel(file.body)
- update_space_units(file.body)
- update_inset_accent(file.body)
- space_before_layout(file.body)
- formula_inset_space_eat(file.body)
- update_tabular(file.body)
- update_vfill(file.body)
- remove_empty_insets(file.body)
- remove_formula_latex(file.body)
- update_latexaccents(file.body)
- file.format = 215
-
-
-def revert(file):
- file.error("The convertion to an older format (%s) is not implemented." % file.format)
+convert = [[215, [header_update, add_end_document, remove_cursor,
+ final_dot, update_inset_label, update_latexdel,
+ update_space_units, space_before_layout,
+ formula_inset_space_eat, update_tabular,
+ update_vfill, remove_empty_insets,
+ remove_formula_latex, update_latexaccents]]]
+revert = []
if __name__ == "__main__":