]> git.lyx.org Git - lyx.git/blobdiff - lib/scripts/layout2layout.py
cmake: move CMakeLists.txt into source dir (multiple steps)
[lyx.git] / lib / scripts / layout2layout.py
index ad6fefb6ffde97c28e7235f90f01cc578c8fc1e2..a59dfcfae2afbd3425278d44a4f8ee17edf69e90 100644 (file)
@@ -76,7 +76,51 @@ import os, re, string, sys
 # Added ContentAsLabel tag.
 
 # Incremented to format 21, 12 January 2010 by rgh
-# Added HTMLTocLayout tag.
+# Added HTMLTocLayout and HTMLTitle tags.
+
+# Incremented to format 22, 20 January 2010 by rgh
+# Added HTMLFormat tag to Counters.
+
+# Incremented to format 23, 13 February 2010 by spitz
+# Added Spellcheck tag.
+
+# Incremented to format 24, 5 March 2010 by rgh
+# Changed LaTeXBuiltin tag to NeedsFloatPkg and
+# added new tag ListCommand.
+
+# Incremented to format 25, 12 March 2010 by rgh
+# Added RefPrefix tag for layouts and floats.
+
+# Incremented to format 26, 29 March 2010 by rgh
+# Added CiteFormat.
+
+# Incremented to format 27, 4 June 2010 by rgh
+# Added RequiredArgs tag.
+
+# Incremented to format 28, 6 August 2010 by lasgouttes
+# Added ParbreakIsNewline tag for Layout and InsetLayout.
+
+# Incremented to format 29, 10 August 2010 by rgh
+# Changed Custom:Style, CharStyle:Style, and Element:Style
+# uniformly to Flex:Style.
+
+# Incremented to format 30, 13 August 2010 by rgh
+# Introduced ResetsFont tag for InsetLayout.
+
+# Incremented to format 31, 12 January 2011 by rgh
+# Introducted NoCounter tag.
+
+# Incremented to format 32, 30 January 2011 by forenr
+# Added Display tag for InsetLayout
+
+# Incremented to format 33, 2 February 2011 by rgh
+# Changed NeedsFloatPkg to UsesFloatPkg
+
+# Incremented to format 34, 28 March 2011 by rgh
+# Remove obsolete Fill_(Top|Bottom) tags
+
+# Incremented to format 35, 28 March 2011 by rgh
+# Try to add "Flex:" to any flex insets that don't have it.
 
 # Do not forget to document format change in Customization
 # Manual (section "Declaring a new text class").
@@ -85,7 +129,7 @@ import os, re, string, sys
 # development/tools/updatelayouts.sh script to update all
 # layout files to the new format.
 
-currentFormat = 21
+currentFormat = 35
 
 
 def usage(prog_name):
@@ -165,6 +209,22 @@ def convert(lines):
     re_TocLevel = re.compile(r'^(\s*)(TocLevel)(\s+)(\S+)', re.IGNORECASE)
     re_I18nPreamble = re.compile(r'^(\s*)I18nPreamble', re.IGNORECASE)
     re_EndI18nPreamble = re.compile(r'^(\s*)EndI18nPreamble', re.IGNORECASE)
+    re_Float = re.compile(r'^\s*Float\s*$', re.IGNORECASE)
+    re_Type = re.compile(r'\s*Type\s+(\w+)', re.IGNORECASE)
+    re_Builtin = re.compile(r'^(\s*)LaTeXBuiltin\s+(\w*)', re.IGNORECASE)
+    re_True = re.compile(r'^\s*(?:true|1)\s*$', re.IGNORECASE)
+    re_InsetLayout = re.compile(r'^\s*InsetLayout\s+(?:Custom|CharStyle|Element):(\S+)\s*$', re.IGNORECASE)
+    # with quotes
+    re_QInsetLayout = re.compile(r'^\s*InsetLayout\s+"(?:Custom|CharStyle|Element):([^"]+)"\s*$', re.IGNORECASE)
+    re_InsetLayout_CopyStyle = re.compile(r'^\s*CopyStyle\s+(?:Custom|CharStyle|Element):(\S+)\s*$', re.IGNORECASE)
+    re_QInsetLayout_CopyStyle = re.compile(r'^\s*CopyStyle\s+"(?:Custom|CharStyle|Element):([^"]+)"\s*$', re.IGNORECASE)
+    re_NeedsFloatPkg = re.compile(r'^(\s*)NeedsFloatPkg\s+(\w+)\s*$', re.IGNORECASE)
+    re_Fill = re.compile(r'^\s*Fill_(?:Top|Bottom).*$', re.IGNORECASE)
+    re_InsetLayout2 = re.compile(r'^\s*InsetLayout\s+(\S+)\s*$', re.IGNORECASE)
+    # with quotes
+    re_QInsetLayout2 = re.compile(r'^\s*InsetLayout\s+"([^"]+)"\s*$', re.IGNORECASE)
+    re_IsFlex = re.compile(r'\s*LyXType.*$', re.IGNORECASE)
+    re_CopyStyle2 = re.compile(r'(\s*CopyStyle\s+)"?([^"]+)"?\s*$')
 
     # counters for sectioning styles (hardcoded in 1.3)
     counters = {"part"          : "\\Roman{part}",
@@ -210,6 +270,7 @@ def convert(lines):
     format = 1
     formatline = 0
     usemodules = []
+    flexstyles = []
 
     while i < len(lines):
         # Skip comments and empty lines
@@ -253,8 +314,136 @@ def convert(lines):
                 i += 1
             continue
 
+        if format == 34:
+          match = re_InsetLayout2.match(lines[i])
+          if not match:
+            match = re_QInsetLayout2.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) + "\"Flex:" + style + "\""
+            i += 1
+            continue
+
+          name = match.group(1)
+          names = name.split(":", 1)
+          if len(names) > 1 and names[0] == "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] = "InsetLayout \"Flex:" + name + "\""
+
+          i += 1
+          continue
+
+        if format == 33:
+          m = re_Fill.match(lines[i])
+          if m:
+            lines[i] = ""
+          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 + "UsesFloatPkg " + val
+            newval = 'true'
+            if val == '1' or val.lower() == 'true':
+              newval = 'false'
+            lines.insert(i, space + "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] = "InsetLayout Flex:" + match.group(1)
+          else:
+            match = re_QInsetLayout.match(lines[i])
+            if match:
+              lines[i] = "InsetLayout \"Flex:" + match.group(1) + "\""
+            else:
+              match = re_InsetLayout_CopyStyle.match(lines[i])
+              if match:
+                lines[i] = "\tCopyStyle Flex:" + match.group(1)
+              else:
+                match = re_QInsetLayout_CopyStyle.match(lines[i])
+                if match:
+                  lines[i] = "\tCopyStyle \"Flex:" + match.group(1) + "\""
+          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 = ""
+          while True and i < len(lines):
+            m1 = re_End.match(lines[i])
+            if m1:
+              if builtin and cmd:
+                line = "    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 = ""
+              if re_True.match(arg):
+                newarg = "false"
+              else:
+                newarg = "true"
+              lines[i] = ws1 + "NeedsFloatPkg " + newarg
+            m3 = re_Type.match(lines[i])
+            if m3:
+              fltype = m3.group(1)
+              fltype = fltype.lower()
+              if fltype == "table":
+                cmd = "listoftables"
+              elif fltype == "figure":
+                cmd = "listoffigures"
+              # else unknown, which is why we're doing this
+            i += 1
+          continue              
+          
         # This just involved new features, not any changes to old ones
-        if format >= 14 and format <= 20:
+        if format >= 14 and format <= 22:
           i += 1
           continue
 
@@ -534,7 +723,7 @@ def convert(lines):
             # This emulates the hardcoded article style numbering of 1.3
             #
             if counter != "":
-                if counters.has_key(style):
+                if style in counters:
                     if labelstring_line < 0:
                         lines.insert(i, '%sLabelString "%s"' % (space1, counters[style]))
                         i += 1
@@ -543,7 +732,7 @@ def convert(lines):
                         lines[labelstring_line] = re_LabelString.sub(
                                 r'\1\2\3%s' % new_labelstring.replace("\\", "\\\\"),
                                 lines[labelstring_line])
-                if appendixcounters.has_key(style):
+                if style in appendixcounters:
                     if labelstringappendix_line < 0:
                         lines.insert(i, '%sLabelStringAppendix "%s"' % (space1, appendixcounters[style]))
                         i += 1
@@ -558,7 +747,7 @@ def convert(lines):
                 i += 1
 
             # Add the TocLevel setting for sectioning styles
-            if toclevel == "" and toclevels.has_key(style) and maxcounter <= toclevels[style]:
+            if toclevel == "" and style in toclevels and maxcounter <= toclevels[style]:
                 lines.insert(i, '%s\tTocLevel %d' % (space1, toclevels[style]))
                 i += 1