]> git.lyx.org Git - lyx.git/blobdiff - lib/scripts/layout2layout.py
Let TeXFiles.py handle symbolic links.
[lyx.git] / lib / scripts / layout2layout.py
index 79c75419995394bb5b2cde3c8b83ba224d79dc42..5e9d3483dee51f3871fcc7dd7ba3ef9b889ee765 100644 (file)
@@ -11,7 +11,7 @@
 # This script will update a .layout file to current format
 
 # The latest layout format is also defined in src/TextClass.cpp
-currentFormat = 63
+currentFormat = 75
 
 
 # Incremented to format 4, 6 April 2007, lasgouttes
@@ -49,7 +49,7 @@ currentFormat = 63
 # Rename I18NPreamble to BabelPreamble and add LangPreamble
 
 # Incremented to format 15, 28 May 2009 by lasgouttes
-# Add new tag OutputFormat; modules can be conditioned on feature 
+# Add new tag OutputFormat; modules can be conditioned on feature
 # "from->to".
 
 # Incremented to format 16, 5 June 2009 by rgh
@@ -212,6 +212,46 @@ currentFormat = 63
 # - New textclass tags CiteFramework, MaxCiteNames (for cite engines)
 # - Extended InsetCite syntax.
 
+# Incremented to format 64, 30 August 2017 by rgh
+# Strip leading and trailing spaces from LabelString,
+# LabelStringAppendix, and EndLabelString, and LabelCounter,
+# to conform to what we used to do.
+
+# Incremented to format 65, 16 October 2017 by spitz
+# Color collapsable -> collapsible
+
+# Incremented to format 66, 28 December 2017 by spitz
+# New Layout tags "AutoNests ... EndAutoNests" and
+# "IsAutoNestedBy ... EndIsAutoNestedBy"
+
+# Incremented to format 67, 14 April 2018 by spitz
+# New Layout tag "NeedsCProtect"
+
+# Incremented to format 68, 21 May 2018 by spitz
+# New Layout tag "AddToCiteEngine"
+
+# Incremented to format 69, 16 August 2018 by spitz
+# New argument type "listpreamble"
+
+# Incremented to format 70, 5 June 2018 by rkh
+# New InsetLayout tag EditExternal
+
+# Incremented to format 71, 12 March 2019 by spitz
+# New [Inset]Layout tag NeedMBoxProtect
+
+# Incremented to format 72, 26 March 2019 by spitz
+# New TextClass tag TableStyle
+
+# Incremented to format 73, 18 April 2019 by spitz
+# New InsetLayout tag MenuString
+
+# Incremented to format 74, 18 April 2019 by spitz
+# New InsetLayout and Argument tag NewlineCmd
+
+# Incremented to format 75, 2 June 2019 by spitz
+# New Argument tags FreeSpacing, InsertOnNewline
+# New InsetLayout tag ParbreakIgnored
+
 # Do not forget to document format change in Customization
 # Manual (section "Declaring a new text class").
 
@@ -338,13 +378,18 @@ def convert(lines, end_format):
     # Arguments
     re_OptArgs = re.compile(b'^(\\s*)OptionalArgs(\\s+)(\\d+)\\D*$', re.IGNORECASE)
     re_ReqArgs = re.compile(b'^(\\s*)RequiredArgs(\\s+)(\\d+)\\D*$', re.IGNORECASE)
-    
+
     # various changes associated with changing how chapters are handled
     re_LabelTypeIsCounter = re.compile(b'^(\\s*)LabelType(\\s*)Counter\\s*$', re.IGNORECASE)
     re_TopEnvironment = re.compile(b'^(\\s*)LabelType(\\s+)Top_Environment\\s*$', re.IGNORECASE)
     re_CenteredEnvironment = re.compile(b'^(\\s*)LabelType(\\s+)Centered_Top_Environment\\s*$', re.IGNORECASE)
     re_ChapterStyle = re.compile(b'^\\s*Style\\s+Chapter\\s*$', re.IGNORECASE)
     re_InsetLayout_CaptionLTNN = re.compile(b'^(\\s*InsetLayout\\s+)(Caption:LongTableNonumber)', re.IGNORECASE)
+    # for format 64
+    re_trimLabelString = re.compile(b'^(\\s*LabelString\s+)"\\s*(.*?)\\s*"\\s*$')
+    re_trimLabelStringAppendix  = re.compile(b'^(\\s*LabelStringAppendix\s+)"\\s*(.*?)\\s*"\\s*$')
+    re_trimEndLabelString = re.compile(b'^(\\s*EndLabelString\s+)"\\s*(.*?)\\s*"\\s*$')
+    re_trimLabelCounter = re.compile(b'^(\\s*LabelCounter\s+)"\\s*(.*?)\\s*"\\s*$')
 
 
     # counters for sectioning styles (hardcoded in 1.3)
@@ -416,7 +461,7 @@ def convert(lines, end_format):
                       lcat = ConvDict[lcat]
                   lines[i] = lpre + b"{" + lnam + b"}"
                   lines.insert(i+1, b"#  \\DeclareCategory{" + lcat + b"}")
-                  i += 1 
+                  i += 1
           i += 1
           continue
 
@@ -456,6 +501,31 @@ def convert(lines, end_format):
                 i += 1
             continue
 
+        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
@@ -625,7 +695,7 @@ def convert(lines, end_format):
             lines[i] = b"InsetLayout Caption:Standard"
           i += 1
           continue
-        
+
         if format == 41:
             # nothing to do.
             i += 1
@@ -694,7 +764,7 @@ def convert(lines, end_format):
                 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.
@@ -726,7 +796,7 @@ def convert(lines, end_format):
               i += 1
               continue
             style = match.group(2)
-            
+
             if flexstyles.count(style):
               lines[i] = match.group(1) + b"\"Flex:" + style + b"\""
             i += 1
@@ -797,7 +867,7 @@ def convert(lines, end_format):
                   lines[i] = b"\tCopyStyle \"Flex:" + match.group(1) + b"\""
           i += 1
           continue
-        
+
         # Only new features
         if format >= 24 and format <= 27:
           i += 1
@@ -842,8 +912,8 @@ def convert(lines, end_format):
                 cmd = b"listoffigures"
               # else unknown, which is why we're doing this
             i += 1
-          continue              
-          
+          continue
+
         # This just involved new features, not any changes to old ones
         if format >= 14 and format <= 22:
           i += 1
@@ -1172,14 +1242,14 @@ def main(argv):
 
     parser = argparse.ArgumentParser(**args)
 
-    parser.add_argument("-t", "--to", type=int, dest="format",
+    parser.add_argument("-t", "--to", type=int, dest="format", default= currentFormat,
                         help=("destination layout format, default %i (latest)") % currentFormat)
     parser.add_argument("input_file", nargs='?', type=cmd_arg, default=None,
                         help="input file (default stdin)")
     parser.add_argument("output_file", nargs='?', type=cmd_arg, default=None,
                         help="output file (default stdout)")
 
-    options = parser.parse_args()
+    options = parser.parse_args(argv[1:])
 
     # Open files
     if options.input_file:
@@ -1192,19 +1262,14 @@ def main(argv):
     else:
         output = sys.stdout
 
-    if options.format:
-        end_format = options.format
-    else:
-        end_format = currentFormat
-
-    if end_format > currentFormat:
-        error("Format %i does not exist" % end_format);
+    if options.format > currentFormat:
+        error("Format %i does not exist" % options.format);
 
     # Do the real work
     lines = read(source)
     format = 1
-    while (format < end_format):
-        format = convert(lines, end_format)
+    while (format < options.format):
+        format = convert(lines, options.format)
     write(output, lines)
 
     # Close files