Fix problem with chunk lyx2lyx conversion spotted by Scott.

We assume chunks come at us in a certain form. If not, then
we cannot handle the conversion. In that case, we just leave
the chunks as they were and they will appear as unknown layouts.
This commit is contained in:
Richard Heck 2013-06-03 13:01:39 -04:00
parent 9a6c402a82
commit 89ced5c3c3

View File

@ -4262,7 +4262,7 @@ def convert_chunks(document):
document.warning("Malformed LyX documents. Can't find end of Chunk layout!") document.warning("Malformed LyX documents. Can't find end of Chunk layout!")
break break
thischunk = "".join(document.body[i + 1:j]) thischunk = "".join(document.body[i + 1:j])
contents.append(thischunk) contents.append(document.body[i + 1:j])
if thischunk == "@": if thischunk == "@":
break break
@ -4276,7 +4276,6 @@ def convert_chunks(document):
layout = get_value(document.body, "\\begin_layout", i) layout = get_value(document.body, "\\begin_layout", i)
#sys.stderr.write(layout+ '\n') #sys.stderr.write(layout+ '\n')
if layout != "Chunk": if layout != "Chunk":
k = i
break break
if j == -1: if j == -1:
@ -4286,16 +4285,18 @@ def convert_chunks(document):
end = j + 1 end = j + 1
k = end k = end
sys.stderr.write('\n'.join(contents) + '\n\n')
# the last chunk should simply have an "@" in it # the last chunk should simply have an "@" in it
# we could check that
if ''.join(contents[-1]) != "@":
document.warning("Unexpected chunk contents.")
continue
contents.pop() contents.pop()
# the first item should look like: <<FROGS>>= # the first item should look like: <<FROGS>>=
# we want the inside # we want the inside
optarg = contents[0] optarg = ' '.join(contents[0])
optarg.strip() optarg.strip()
match = first_re.search(optarg) match = first_re.search(optarg)
if match: if match:
@ -4322,7 +4323,8 @@ def convert_chunks(document):
newstuff.extend(['', '\\begin_layout Plain Layout', '']) newstuff.extend(['', '\\begin_layout Plain Layout', ''])
else: else:
didone = True didone = True
newstuff.extend([c, '\\end_layout']) newstuff.extend(c)
newstuff.append('\\end_layout')
newstuff.extend(['', '\\end_inset', '', '\\end_layout', '']) newstuff.extend(['', '\\end_inset', '', '\\end_layout', ''])