+ if format >= 65 and format <= 74:
+ # nothing to do.
+ i += 1
+ continue
+
+ if format == 64:
+ match = re.compile(b'(\\s*Color\\s+)(\\w+)', re.IGNORECASE).match(lines[i])
+ if not match:
+ i += 1
+ continue
+ col = match.group(2)
+ if col == "collapsable":
+ lines[i] = match.group(1) + "collapsible"
+ i += 1
+ continue
+
+ if format == 63:
+ for r in (re_trimLabelString, re_trimLabelStringAppendix,\
+ re_trimEndLabelString, re_trimLabelCounter):
+ m = r.match(lines[i])
+ if m:
+ lines[i] = m.group(1) + b'"' + m.group(2) + b'"'
+ i += 1
+ continue
+
+ if format >= 60 and format <= 62:
+ # nothing to do.
+ i += 1
+ continue
+
+ if format == 59:
+ match = re_InsetLayout_CaptionLTNN.match(lines[i])
+ if not match:
+ i += 1
+ continue
+ # '^(\s*InsetLayout\s+)(Caption:LongTableNonumber)'
+ lead = match.group(1)
+ lines[i] = lead + b"Caption:Unnumbered"
+ i += 1
+ continue
+
+ if format == 58:
+ # nothing to do.
+ i += 1
+ continue
+
+ if format == 57:
+ match = re_IfStyle.match(lines[i])
+ if not match:
+ i += 1
+ continue
+ # b'^(\\s*)IfStyle(\\s+\\S+)
+ lead = match.group(1)
+ trail = match.group(2)
+ lines[i] = lead + b"ModifyStyle" + trail
+ i += 1
+ continue
+
+ if format >= 50 and format <= 56:
+ # nothing to do.
+ i += 1
+ continue
+
+ if format == 49:
+ separator = []
+
+ # delete separator styles
+ match = re_Style.match(lines[i])
+ if match:
+ style = match.group(4).lower()
+ if re_Separator.match(style):
+ del lines[i]
+ while i < len(lines) and not re_End.match(lines[i]):
+ separator.append(lines[i])
+ del lines[i]
+ if i == len(lines):
+ error('Incomplete separator style.')
+ else:
+ del lines[i]
+ continue
+
+ # delete undefinition of separator styles
+ match = re_NoStyle.match(lines[i])
+ if match:
+ style = match.group(4).lower()
+ if re_Separator.match(style):
+ del lines[i]
+ continue
+
+ # replace the CopyStyle statement with the definition of the real
+ # style. This may result in duplicate statements, but that is OK
+ # since the second one will overwrite the first one.
+ match = re_CopyStyle.match(lines[i])
+ if match:
+ style = match.group(4).lower()
+ if re_Separator.match(style):
+ if len(separator) > 0:
+ lines[i:i+1] = separator
+ else:
+ # FIXME: If this style was redefined in an include file,
+ # we should replace the real style and not this default.
+ lines[i:i+1] = [b' Category MainText',
+ b' KeepEmpty 1',
+ b' Margin Dynamic',
+ b' LatexType Paragraph',
+ b' LatexName dummy',
+ b' ParIndent MM',
+ b' Align Block',
+ b' LabelType Static',
+ b' LabelString "--- Separate Environment ---"',
+ b' LabelFont',
+ b' Family Roman',
+ b' Series Medium',
+ b' Size Normal',
+ b' Color Blue',
+ b' EndFont',
+ b' HTMLLabel NONE']
+ i += 1
+ continue
+
+ if format == 48:
+ # The default of ResetsFont in LyX changed from true to false,
+ # because it is now used for all InsetLayouts, not only flex ones.
+ # Therefore we need to set it to true for all flex insets which do
+ # do not already have a ResetsFont.
+ match = re_InsetLayout2.match(lines[i])
+ if not match:
+ i += 1
+ continue
+
+ name = match.group(1).lower()
+ if name != b"flex" and name != b"\"flex\"" and name[0:5] != b"flex:" and name [0:6] != b"\"flex:":
+ i += 1
+ continue
+
+ resetsfont_found = False
+ inherited = False
+ notdone = True
+ while i < len(lines):
+ match = re_ResetsFont.match(lines[i])
+ if match:
+ resetsfont_found = True
+ else:
+ match = re_CopyStyle.match(lines[i])
+ if match:
+ inherited = True
+ else:
+ match = re_End.match(lines[i])
+ if match:
+ break
+ i += 1
+ if not resetsfont_found and not inherited:
+ lines.insert(i, b"\tResetsFont true")
+
+ continue
+
+ if format >= 44 and format <= 47:
+ # nothing to do.
+ i += 1
+ continue
+
+ if format == 43:
+ match = re_LabelTypeIsCounter.match(lines[i])
+ if match:
+ if inchapter:
+ lines[i] = match.group(1) + b"LabelType" + match.group(2) + b"Above"
+ else:
+ lines[i] = match.group(1) + b"LabelType" + match.group(2) + b"Static"
+
+ match = re_TopEnvironment.match(lines[i])
+ if match:
+ lines[i] = match.group(1) + b"LabelType" + match.group(2) + b"Above"
+
+ match = re_CenteredEnvironment.match(lines[i])
+ if match:
+ lines[i] = match.group(1) + b"LabelType" + match.group(2) + b"Centered"
+
+ if inchapter:
+ match = re_Style.match(lines[i])
+ if match:
+ inchapter = False
+ else:
+ match = re_ChapterStyle.match(lines[i])
+ if match:
+ inchapter = True
+
+ i += 1
+ continue
+
+ if format == 42:
+ if lines[i] == b"InsetLayout Caption":
+ lines[i] = b"InsetLayout Caption:Standard"
+ i += 1
+ continue
+
+ if format == 41:
+ # nothing to do.
+ i += 1
+ continue
+
+ if format == 40:
+ # reset counters on Style beginning
+ match = re_Style.match(lines[i])
+ if match:
+ opts = 0
+ reqs = 0
+ i += 1
+ continue
+ match = re_OptArgs.match(lines[i])
+ if match:
+ # Save number of optional arguments
+ space1 = match.group(1)
+ opts = int(match.group(3))
+ # OptionalArgs 0 > ResetArgs 1
+ if opts == 0:
+ lines[i] = space1 + b"ResetArgs\t1"
+ i += 1
+ else:
+ del lines[i]
+ continue
+ match = re_ReqArgs.match(lines[i])
+ if match:
+ # Save number of required arguments
+ space1 = match.group(1)
+ reqs = int(match.group(3))
+ del lines[i]
+ continue
+ # Insert the required number of arguments at the end of the style definition
+ match = re_End.match(lines[i])
+ if match:
+ newarg = ['']
+ # First the optionals (this is the required order pre 2.1)
+ if opts > 0:
+ if opts == 1:
+ newarg = [ b'%sArgument 1' % (space1),
+ b'%s\tLabelString\t\"Optional Layout Argument\"' % (space1),
+ b'%sEndArgument' % (space1)]
+ elif opts > 1:
+ actopt = 1
+ while actopt < (opts + 1):
+ newarg += [ b'%sArgument %d' % (space1, actopt),
+ b'%s\tLabelString\t\"Optional Layout Argument %d\"' % (space1, actopt),
+ b'%sEndArgument' % (space1)]
+ actopt += 1
+ # Now the mandatories
+ if reqs > 0:
+ actopt = opts + 1
+ while actopt < (opts + reqs + 1):
+ newarg += [ b'%sArgument %d' % (space1, actopt),
+ b'%s\tLabelString\t"Required Layout Argument %d"' % (space1, actopt - opts),
+ b'%s\tMandatory\t1' % (space1),
+ b'%sEndArgument' % (space1)]
+ actopt += 1
+ # Since we replace the "End" line, re-add this line
+ if len(newarg) > 1:
+ newarg += [b'End']
+ lines[i:i+1] = newarg
+ i += len(newarg)
+ # Reset the counters
+ opts = 0
+ reqs = 0
+ i += 1
+ continue
+
+ if format == 39:
+ # There is a conversion with format 40, but it is done within the
+ # initial comment block and so is above.
+ i += 1
+ continue
+
+ if format == 37 or format == 38:
+ i += 1
+ continue
+
+ if format == 36:
+ match = re_CiteFormat.match(lines[i]);
+ if match and match.group(4) == b"":
+ lines[i] = match.group(0) + b" default"
+ i += 1
+ continue
+
+ if format == 35:
+ i += 1
+ continue
+
+ if format == 34:
+ match = re_QInsetLayout2.match(lines[i])
+ if not match:
+ match = re_InsetLayout2.match(lines[i])
+ if not match:
+ match = re_CopyStyle2.match(lines[i])
+ if not match:
+ i += 1
+ continue
+ style = match.group(2)
+
+ if flexstyles.count(style):
+ lines[i] = match.group(1) + b"\"Flex:" + style + b"\""
+ i += 1
+ continue
+
+ name = match.group(1)
+ names = name.split(b":", 1)
+ if len(names) > 1 and names[0] == b"Flex":
+ i += 1
+ continue
+
+ isflex = False
+ for j in range(i + 1, len(lines)):
+ if re_IsFlex.match(lines[j]):
+ isflex = True
+ break
+ if re_End.match(lines[j]):
+ break
+
+ if isflex:
+ flexstyles.append(name)
+ lines[i] = b"InsetLayout \"Flex:" + name + b"\""
+
+ i += 1
+ continue
+
+ if format == 33:
+ m = re_Fill.match(lines[i])
+ if m:
+ lines[i] = b""
+ i += 1
+ continue
+
+ if format == 32:
+ match = re_NeedsFloatPkg.match(lines[i])
+ if match:
+ space = match.group(1)
+ val = match.group(2)
+ lines[i] = space + b"UsesFloatPkg " + val
+ newval = b'true'
+ if val == b'1' or val.lower() == b'true':
+ newval = b'false'
+ lines.insert(i, space + b"IsPredefined " + newval)
+ i += 1
+ i += 1
+ continue
+
+ # Only new features
+ if format >= 29 and format <= 31:
+ i += 1
+ continue
+
+ if format == 28:
+ match = re_InsetLayout.match(lines[i])
+ if match:
+ lines[i] = b"InsetLayout Flex:" + match.group(1)
+ else:
+ match = re_QInsetLayout.match(lines[i])
+ if match:
+ lines[i] = b"InsetLayout \"Flex:" + match.group(1) + b"\""
+ else:
+ match = re_InsetLayout_CopyStyle.match(lines[i])
+ if match:
+ lines[i] = b"\tCopyStyle Flex:" + match.group(1)
+ else:
+ match = re_QInsetLayout_CopyStyle.match(lines[i])
+ if match:
+ lines[i] = b"\tCopyStyle \"Flex:" + match.group(1) + b"\""
+ i += 1
+ continue
+
+ # Only new features
+ if format >= 24 and format <= 27:
+ i += 1
+ continue
+
+ if format == 23:
+ match = re_Float.match(lines[i])
+ i += 1
+ if not match:
+ continue
+ # we need to do two things:
+ # (i) Convert Builtin to NeedsFloatPkg
+ # (ii) Write ListCommand lines for the builtin floats table and figure
+ builtin = False
+ cmd = b""
+ while True and i < len(lines):
+ m1 = re_End.match(lines[i])
+ if m1:
+ if builtin and cmd:
+ line = b" ListCommand " + cmd
+ lines.insert(i, line)
+ i += 1
+ break
+ m2 = re_Builtin.match(lines[i])
+ if m2:
+ builtin = True
+ ws1 = m2.group(1)
+ arg = m2.group(2)
+ newarg = b""
+ if re_True.match(arg):
+ newarg = b"false"
+ else:
+ newarg = b"true"
+ lines[i] = ws1 + b"NeedsFloatPkg " + newarg
+ m3 = re_Type.match(lines[i])
+ if m3:
+ fltype = m3.group(1)
+ fltype = fltype.lower()
+ if fltype == b"table":
+ cmd = b"listoftables"
+ elif fltype == b"figure":
+ cmd = b"listoffigures"
+ # else unknown, which is why we're doing this
+ i += 1
+ continue
+