]> git.lyx.org Git - lyx.git/blobdiff - lib/scripts/layout2layout.py
configure.py: Replace 'ltx' by 'log' case insensitively
[lyx.git] / lib / scripts / layout2layout.py
index d9f8cabc46f8495cd874f7e58905fe58cca38cff..585538d2edaf62006897255a2071c0c6b0cf2fdf 100644 (file)
@@ -122,6 +122,19 @@ import os, re, string, sys
 # Incremented to format 35, 28 March 2011 by rgh
 # Try to add "Flex:" to any flex insets that don't have it.
 
+# Incremented to format 36, 7 December 2011, by rgh
+# Added HTMLStyles and AddToHTMLStyles tags.
+
+# Incremented to format 37, 29 February 2012 by jrioux
+# Implement the citation engine machinery in layouts.
+# Change CiteFormat to CiteFormat (default|authoryear|numerical).
+
+# Incremented to format 38, 08 April 2012 by gb
+# Introduce LangPreamble and BabelPreamble for InsetLayout.
+
+# Incremented to format 39, 15 April 2012 by sanda
+# Introduce styling of branches via "InsetLayout Branch:".
+
 # Do not forget to document format change in Customization
 # Manual (section "Declaring a new text class").
 
@@ -129,7 +142,7 @@ import os, re, string, sys
 # development/tools/updatelayouts.sh script to update all
 # layout files to the new format.
 
-currentFormat = 35
+currentFormat = 39
 
 
 def usage(prog_name):
@@ -152,7 +165,7 @@ def trim_bom(line):
 
 def read(source):
     " Read input file and strip lineendings."
-    lines = source.read().splitlines()
+    lines = source.read().splitlines() or ['']
     lines[0] = trim_bom(lines[0])
     return lines
 
@@ -203,6 +216,7 @@ def convert(lines):
     re_End = re.compile(r'^(\s*)(End)(\s*)$', re.IGNORECASE)
     re_Provides = re.compile(r'^(\s*)Provides(\S+)(\s+)(\S+)', re.IGNORECASE)
     re_CharStyle = re.compile(r'^(\s*)CharStyle(\s+)(\S+)$', re.IGNORECASE)
+    re_CiteFormat = re.compile(r'^(\s*)(CiteFormat)(?:(\s*)()|(\s+)(default|authoryear|numerical))', re.IGNORECASE)
     re_AMSMaths = re.compile(r'^\s*Input ams(?:math|def)s.inc\s*')
     re_AMSMathsPlain = re.compile(r'^\s*Input amsmaths-plain.inc\s*')
     re_AMSMathsSeq = re.compile(r'^\s*Input amsmaths-seq.inc\s*')
@@ -224,6 +238,7 @@ def convert(lines):
     # 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}",
@@ -269,6 +284,7 @@ def convert(lines):
     format = 1
     formatline = 0
     usemodules = []
+    flexstyles = []
 
     while i < len(lines):
         # Skip comments and empty lines
@@ -312,13 +328,41 @@ def convert(lines):
                 i += 1
             continue
 
+        if format == 38:
+          i += 1
+          continue
+
+        if format == 37:
+          i += 1
+          continue
+
+        if format == 36:
+            match = re_CiteFormat.match(lines[i]);
+            if match and match.group(4) == "":
+                lines[i] = match.group(0) + " default"
+            i += 1
+            continue
+
+        if format == 35:
+          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":
@@ -334,6 +378,7 @@ def convert(lines):
               break
 
           if isflex:
+            flexstyles.append(name)
             lines[i] = "InsetLayout \"Flex:" + name + "\""
 
           i += 1
@@ -741,6 +786,8 @@ def convert(lines):
 
         i += 1
 
+    if only_comment:
+        lines.insert(i, "Format 2")
     if usemodules:
         i = formatline + 1
         for mod in usemodules: