X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=lib%2Fscripts%2Flayout2layout.py;h=48a1e03f213b8f31cda58b6ce239ec04aa444527;hb=2ee880ff21ae663630e2ef3a2baab4bb32cc42ad;hp=e5b0da9674bba2954a88b5710a583c8d65fc6c7a;hpb=583e62836c1c72d64f25bef8aae208253284f3be;p=lyx.git diff --git a/lib/scripts/layout2layout.py b/lib/scripts/layout2layout.py index e5b0da9674..48a1e03f21 100644 --- a/lib/scripts/layout2layout.py +++ b/lib/scripts/layout2layout.py @@ -1,4 +1,3 @@ -#! /usr/bin/env python # -*- coding: utf-8 -*- # file layout2layout.py @@ -49,7 +48,7 @@ import os, re, string, sys # Rename I18NPreamble to BabelPreamble and add LangPreamble # Incremented to format 15, 28 May 2009 by lasgouttes -# Add new tag OutputFormat; modules can be conditionned on feature +# Add new tag OutputFormat; modules can be conditioned on feature # "from->to". # Incremented to format 16, 5 June 2009 by rgh @@ -62,12 +61,146 @@ import os, re, string, sys # HTMLTag, HTMLAttr, HTMLStyle, and HTMLPreamble # For Floats: # HTMLType, HTMLClass, HTMLStyle -# These are still to be documented, once everything stabilizes. + +# Incremented to format 17, 12 August 2009 by rgh +# Add IfStyle and IfCounter tags for layout. + +# Incremented to format 18, 27 October 2009 by rgh +# Added some new tags for HTML output. + +# Incremented to format 19, 17 November 2009 by rgh +# Added InPreamble tag. + +# Incremented to format 20, 17 December 2009 by rgh +# Added ContentAsLabel tag. + +# Incremented to format 21, 12 January 2010 by rgh +# 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. + +# 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:". + +# Incremented to format 40, 10 October 2012 by rgh +# Re-do layout names for layout categories + +# Incremented to format 41, 20 November 2012 by spitz +# New Argument syntax + +# Incremented to format 42, 22 December 2012 by spitz +# New Style tag "ItemCommand" + +# Incremented to format 43, 30 December 2012 by spitz +# Extended InsetCaption format + +# Incremented to format 44, 9 February 2013 by rgh +# Remove COUNTER label style; rename as STATIC +# Rename TOP_ENVIRONMENT to ABOVE and CENTERED_TOP_ENVIRONMENT to CENTERED + +# Incremented to format 45, 12 February 2013 by rgh +# New Tag "NoInsetLayout" + +# Incremented to format 46, 15 May 2013 by gb +# New Tag "ForceLocal" + +# Incremented to format 47, 23 May 2013 by rgh +# Add PackageOptions tag + +# Incremented to format 48, 31 May 2013 by rgh +# Add InitialValue tag for counters + +# Incremented to format 49, 10 Feb 2014 by gb +# Change default of "ResetsFont" tag to false + +# Incremented to format 50, 9 May 2014 by forenr +# Removal of "Separator" layouts + +# Incremented to format 51, 29 May 2014 by spitz +# New Style tag "ToggleIndent" + +# Incremented to format 52, 1 December 2014 by spitz +# New InsetLayout tag "ForceOwnlines" + +# Incremented to format 53, 7 December 2014 by spitz +# New InsetLayout tag "ObsoletedBy" + +# Incremented to format 54, 11 Jan 2014 by gb +# New InsetLayout tag "FixedWidthPreambleEncoding" + +# Incremented to format 55, 20 April 2015 by spitz +# New InsetLayout and Layout tags "PassThruChars" + +# Incremented to format 56, 20 May 2015 by spitz +# New Float tags "AllowedPlacement", "AllowsWide", "AllowsSideways" + +# Incremented to format 57, 30 May 2015 by spitz +# New Layout tag "ParagraphGroup" + +# Incremented to format 58, 5 December 2015, by rgh +# New Layout tag "ProvideStyle" +# Change "IfStyle" to "ModifyStyle" # Do not forget to document format change in Customization # Manual (section "Declaring a new text class"). -currentFormat = 16 +# You might also want to consider running the +# development/tools/updatelayouts.py script to update all +# layout files to the new format. + +currentFormat = 58 def usage(prog_name): @@ -80,32 +213,24 @@ def error(message): sys.exit(1) -def trim_eol(line): - " Remove end of line char(s)." - if line[-2:-1] == '\r': - return line[:-2] - elif line[-1:] == '\r' or line[-1:] == '\n': - return line[:-1] +def trim_bom(line): + " Remove byte order mark." + if line[0:3] == "\357\273\277": + return line[3:] else: - # file with no EOL in last line return line -def read(input): +def read(source): " Read input file and strip lineendings." - lines = list() - while 1: - line = input.readline() - if not line: - break - lines.append(trim_eol(line)) + lines = source.read().splitlines() or [''] + lines[0] = trim_bom(lines[0]) return lines def write(output, lines): " Write output file with native lineendings." - for line in lines: - output.write(line + os.linesep) + output.write(os.linesep.join(lines) + os.linesep) # Concatenates old and new in an intelligent way: @@ -144,17 +269,52 @@ def convert(lines): re_LabelStringAppendix = re.compile(r'^(\s*)(LabelStringAppendix)(\s+)(("[^"]+")|(\S+))', re.IGNORECASE) re_LatexType = re.compile(r'^(\s*)(LatexType)(\s+)(\S+)', re.IGNORECASE) re_Style = re.compile(r'^(\s*)(Style)(\s+)(\S+)', re.IGNORECASE) + re_IfStyle = re.compile(r'^(\s*)IfStyle(\s+\S+)', re.IGNORECASE) re_CopyStyle = re.compile(r'^(\s*)(CopyStyle)(\s+)(\S+)', re.IGNORECASE) re_NoStyle = re.compile(r'^(\s*)(NoStyle)(\s+)(\S+)', re.IGNORECASE) 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_AMSMaths = re.compile(r'^\s*Input amsmaths.inc\s*') + 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*') 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) + re_ResetsFont = re.compile(r'^(\s*)ResetsFont(\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*$') + re_Separator = re.compile(r'^(?:(-*)|(\s*))(Separator|EndOfSlide)(?:(-*)|(\s*))$', re.IGNORECASE) + # for categories + re_Declaration = re.compile(r'^#\s*\\Declare\w+Class.*$') + re_ExtractCategory = re.compile(r'^(#\s*\\Declare\w+Class(?:\[[^]]*?\])?){([^(]+?)\s+\(([^)]+?)\)\s*}\s*$') + ConvDict = {"article": "Articles", "book" : "Books", "letter" : "Letters", "report": "Reports", \ + "presentation" : "Presentations", "curriculum vitae" : "Curricula Vitae", "handout" : "Handouts"} + # Arguments + re_OptArgs = re.compile(r'^(\s*)OptionalArgs(\s+)(\d+)\D*$', re.IGNORECASE) + re_ReqArgs = re.compile(r'^(\s*)RequiredArgs(\s+)(\d+)\D*$', re.IGNORECASE) + + # various changes associated with changing how chapters are handled + re_LabelTypeIsCounter = re.compile(r'^(\s*)LabelType(\s*)Counter\s*$', re.IGNORECASE) + re_TopEnvironment = re.compile(r'^(\s*)LabelType(\s+)Top_Environment\s*$', re.IGNORECASE) + re_CenteredEnvironment = re.compile(r'^(\s*)LabelType(\s+)Centered_Top_Environment\s*$', re.IGNORECASE) + re_ChapterStyle = re.compile(r'^\s*Style\s+Chapter\s*$', re.IGNORECASE) + # counters for sectioning styles (hardcoded in 1.3) counters = {"part" : "\\Roman{part}", @@ -174,7 +334,7 @@ def convert(lines): "subparagraph" : "\\arabic{section}.\\arabic{subsection}.\\arabic{subsubsection}.\\arabic{paragraph}.\\arabic{subparagraph}"} # Value of TocLevel for sectioning styles - toclevels = {"part" : 0, + toclevels = {"part" : -1, "chapter" : 0, "section" : 1, "subsection" : 2, @@ -200,12 +360,34 @@ def convert(lines): format = 1 formatline = 0 usemodules = [] + flexstyles = [] + opts = 0 + reqs = 0 + inchapter = False + isflexlayout = False # only used for 48 -> 49 + # Whether a style is inherited (works only for CopyStyle currently, + # not for true inherited styles, see bug 8920 + inherited = False # only used for 48 -> 49 + resetsfont_found = False # only used for 48 -> 49 while i < len(lines): # Skip comments and empty lines - if re_Comment.match(lines[i]) or re_Empty.match(lines[i]): - i += 1 - continue + if (re_Comment.match(lines[i]) or re_Empty.match(lines[i])): + # We need to deal with this conversion here, because it happens + # inside the initial comment block. + if only_comment and format == 39: + match = re_ExtractCategory.match(lines[i]) + if match: + lpre = match.group(1) + lcat = match.group(2) + lnam = match.group(3) + if lcat in ConvDict: + lcat = ConvDict[lcat] + lines[i] = lpre + "{" + lnam + "}" + lines.insert(i+1, "# \\DeclareCategory{" + lcat + "}") + i += 1 + i += 1 + continue # insert file format if not already there if (only_comment): @@ -220,7 +402,7 @@ def convert(lines): # nothing to do return format else: - error('Cannot convert file format %s' % format) + error('Cannot convert file format %s to %s' % (format, currentFormat)) else: lines.insert(i, "Format 2") only_comment = 0 @@ -243,8 +425,376 @@ def convert(lines): i += 1 continue + + if format == 57: + match = re_IfStyle.match(lines[i]) + if not match: + i += 1 + continue + # r'^(\s*)IfStyle(\s+\S+) + lead = match.group(1) + trail = match.group(2) + lines[i] = lead + "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 = string.lower(match.group(4)) + 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 = string.lower(match.group(4)) + 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 = string.lower(match.group(4)) + 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] = [' Category MainText', + ' KeepEmpty 1', + ' Margin Dynamic', + ' LatexType Paragraph', + ' LatexName dummy', + ' ParIndent MM', + ' Align Block', + ' LabelType Static', + ' LabelString "--- Separate Environment ---"', + ' LabelFont', + ' Family Roman', + ' Series Medium', + ' Size Normal', + ' Color Blue', + ' EndFont', + ' 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 = string.lower(match.group(1)) + if name != "flex" and name != "\"flex\"" and name[0:5] != "flex:" and name [0:6] != "\"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, "\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) + "LabelType" + match.group(2) + "Above" + else: + lines[i] = match.group(1) + "LabelType" + match.group(2) + "Static" + + match = re_TopEnvironment.match(lines[i]) + if match: + lines[i] = match.group(1) + "LabelType" + match.group(2) + "Above" + + match = re_CenteredEnvironment.match(lines[i]) + if match: + lines[i] = match.group(1) + "LabelType" + match.group(2) + "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] == "InsetLayout Caption": + lines[i] = "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 + "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 = [ '%sArgument 1' % (space1), + '%s\tLabelString\t\"Optional Layout Argument\"' % (space1), + '%sEndArgument' % (space1)] + elif opts > 1: + actopt = 1 + while actopt < (opts + 1): + newarg += [ '%sArgument %d' % (space1, actopt), + '%s\tLabelString\t\"Optional Layout Argument %d\"' % (space1, actopt), + '%sEndArgument' % (space1)] + actopt += 1 + # Now the mandatories + if reqs > 0: + actopt = opts + 1 + while actopt < (opts + reqs + 1): + newarg += [ '%sArgument %d' % (space1, actopt), + '%s\tLabelString\t"Required Layout Argument %d"' % (space1, actopt - opts), + '%s\tMandatory\t1' % (space1), + '%sEndArgument' % (space1)] + actopt += 1 + # Since we replace the "End" line, re-add this line + if len(newarg) > 1: + newarg += ['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) == "": + lines[i] = match.group(0) + " 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) + "\"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 or format == 15: + if format >= 14 and format <= 22: i += 1 continue @@ -524,7 +1074,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 @@ -533,7 +1083,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 @@ -548,12 +1098,14 @@ def convert(lines): i += 1 # Add the TocLevel setting for sectioning styles - if toclevel == "" and toclevels.has_key(style) and maxcounter <= toclevels[style]: - lines.insert(i, '%sTocLevel %d' % (space1, toclevels[style])) + if toclevel == "" and style in toclevels and maxcounter <= toclevels[style]: + lines.insert(i, '%s\tTocLevel %d' % (space1, toclevels[style])) i += 1 i += 1 + if only_comment: + lines.insert(i, "Format 2") if usemodules: i = formatline + 1 for mod in usemodules: @@ -567,16 +1119,16 @@ def main(argv): # Open files if len(argv) == 1: - input = sys.stdin + source = sys.stdin output = sys.stdout elif len(argv) == 3: - input = open(argv[1], 'rb') + source = open(argv[1], 'rb') output = open(argv[2], 'wb') else: error(usage(argv[0])) # Do the real work - lines = read(input) + lines = read(source) format = 1 while (format < currentFormat): format = convert(lines) @@ -584,7 +1136,7 @@ def main(argv): # Close files if len(argv) == 3: - input.close() + source.close() output.close() return 0