]> git.lyx.org Git - lyx.git/blobdiff - src/Layout.cpp
Account for old versions of Pygments
[lyx.git] / src / Layout.cpp
index 17be45c2270fc77efd999c7da41acd8f260b3ffa..3d1d78136018f859af6d41d801ab3854443b37c1 100644 (file)
@@ -105,19 +105,26 @@ enum LayoutTags {
        LT_SPELLCHECK,
        LT_REFPREFIX,
        LT_RESETARGS,
+       LT_RESUMECOUNTER,
+       LT_STEPMASTERCOUNTER,
        LT_RIGHTDELIM,
        LT_FORCELOCAL,
        LT_TOGGLE_INDENT,
+       LT_ADDTOTOC,
+       LT_ISTOCCAPTION,
        LT_INTITLE // keep this last!
 };
 
 /////////////////////
 
 Layout::Layout()
+       : add_to_toc_(false), is_toc_caption_(false)
 {
        unknown_ = false;
        margintype = MARGIN_STATIC;
        latextype = LATEX_PARAGRAPH;
+       resumecounter = false;
+       stepmastercounter = false;
        intitle = false;
        inpreamble = false;
        needprotect = false;
@@ -180,6 +187,7 @@ bool Layout::readIgnoreForcelocal(Lexer & lex, TextClass const & tclass)
 {
        // This table is sorted alphabetically [asierra 30March96]
        LexerKeyword layoutTags[] = {
+               { "addtotoc",       LT_ADDTOTOC },
                { "align",          LT_ALIGN },
                { "alignpossible",  LT_ALIGNPOSSIBLE },
                { "argument",       LT_ARGUMENT },
@@ -209,6 +217,7 @@ bool Layout::readIgnoreForcelocal(Lexer & lex, TextClass const & tclass)
                { "innertag",       LT_INNERTAG },
                { "inpreamble",     LT_INPREAMBLE },
                { "intitle",        LT_INTITLE },
+               { "istoccaption",   LT_ISTOCCAPTION },
                { "itemcommand",    LT_ITEMCOMMAND },
                { "itemsep",        LT_ITEMSEP },
                { "itemtag",        LT_ITEMTAG },
@@ -244,10 +253,12 @@ bool Layout::readIgnoreForcelocal(Lexer & lex, TextClass const & tclass)
                { "refprefix",      LT_REFPREFIX },
                { "requires",       LT_REQUIRES },
                { "resetargs",      LT_RESETARGS },
+               { "resumecounter",  LT_RESUMECOUNTER },
                { "rightdelim",     LT_RIGHTDELIM },
                { "rightmargin",    LT_RIGHTMARGIN },
                { "spacing",        LT_SPACING },
                { "spellcheck",     LT_SPELLCHECK },
+               { "stepmastercounter",  LT_STEPMASTERCOUNTER },
                { "textfont",       LT_TEXTFONT },
                { "toclevel",       LT_TOCLEVEL },
                { "toggleindent",   LT_TOGGLE_INDENT },
@@ -362,6 +373,14 @@ bool Layout::readIgnoreForcelocal(Lexer & lex, TextClass const & tclass)
                        }
                        break;
 
+               case LT_RESUMECOUNTER:
+                       lex >> resumecounter;
+                       break;
+
+               case LT_STEPMASTERCOUNTER:
+                       lex >> stepmastercounter;
+                       break;
+
                case LT_ARGUMENT:
                        readArgument(lex);
                        break;
@@ -446,15 +465,15 @@ bool Layout::readIgnoreForcelocal(Lexer & lex, TextClass const & tclass)
                        break;
 
                case LT_PREAMBLE:
-                       preamble_ = from_utf8(lex.getLongString("EndPreamble"));
+                       preamble_ = lex.getLongString(from_ascii("EndPreamble"));
                        break;
 
                case LT_LANGPREAMBLE:
-                       langpreamble_ = from_utf8(lex.getLongString("EndLangPreamble"));
+                       langpreamble_ = lex.getLongString(from_ascii("EndLangPreamble"));
                        break;
 
                case LT_BABELPREAMBLE:
-                       babelpreamble_ = from_utf8(lex.getLongString("EndBabelPreamble"));
+                       babelpreamble_ = lex.getLongString(from_ascii("EndBabelPreamble"));
                        break;
 
                case LT_LABELTYPE:
@@ -616,7 +635,7 @@ bool Layout::readIgnoreForcelocal(Lexer & lex, TextClass const & tclass)
                        break;
                        
                case LT_HTMLSTYLE:
-                       htmlstyle_ = from_utf8(lex.getLongString("EndHTMLStyle"));
+                       htmlstyle_ = lex.getLongString(from_ascii("EndHTMLStyle"));
                        break;
 
                case LT_HTMLFORCECSS:
@@ -624,7 +643,7 @@ bool Layout::readIgnoreForcelocal(Lexer & lex, TextClass const & tclass)
                        break;
 
                case LT_HTMLPREAMBLE:
-                       htmlpreamble_ = from_utf8(lex.getLongString("EndPreamble"));
+                       htmlpreamble_ = lex.getLongString(from_ascii("EndPreamble"));
                        break;
                
                case LT_HTMLTITLE:
@@ -638,6 +657,16 @@ bool Layout::readIgnoreForcelocal(Lexer & lex, TextClass const & tclass)
                case LT_FORCELOCAL:
                        lex >> forcelocal;
                        break;
+
+               case LT_ADDTOTOC:
+                       lex >> toc_type_;
+                       add_to_toc_ = !toc_type_.empty();
+                       break;
+
+               case LT_ISTOCCAPTION:
+                       lex >> is_toc_caption_;
+                       break;
+
                }
        }
        lex.popTable();
@@ -951,6 +980,8 @@ void Layout::readArgument(Lexer & lex)
        bool finished = false;
        arg.font = inherit_font;
        arg.labelfont = inherit_font;
+       arg.is_toc_caption = false;
+       arg.passthru = PT_INHERITED;
        string id;
        lex >> id;
        bool const itemarg = prefixIs(id, "item:");
@@ -1011,6 +1042,18 @@ void Layout::readArgument(Lexer & lex)
                } else if (tok == "passthruchars") {
                        lex.next();
                        arg.pass_thru_chars = lex.getDocString();
+               } else if (tok == "passthru") {
+                       lex.next();
+                       docstring value = lex.getDocString();
+                       if (value == "true" || value == "1")
+                               arg.passthru = PT_TRUE;
+                       else if (value == "false" || value == "0")
+                               arg.passthru = PT_FALSE;
+                       else
+                               arg.passthru = PT_INHERITED;
+               } else if (tok == "istoccaption") {
+                       lex.next();
+                       arg.is_toc_caption = lex.getBool();
                } else {
                        lex.printError("Unknown tag");
                        error = true;
@@ -1062,6 +1105,17 @@ void writeArgument(ostream & os, string const & id, Layout::latexarg const & arg
                lyxWrite(os, arg.font, "Font", 2);
        if (arg.labelfont != inherit_font)
                lyxWrite(os, arg.labelfont, "LabelFont", 2);
+       switch (arg.passthru) {
+               case PT_TRUE:
+                       os << "\t\tPassThru true\n";
+                       break;
+               case PT_FALSE:
+                       os << "\t\tPassThru false\n";
+                       break;
+               case PT_INHERITED:
+                       os << "\t\tPassThru inherited\n";
+                       break;
+       }
        if (!arg.pass_thru_chars.empty())
                os << "\t\tPassThruChars \"" << to_utf8(arg.pass_thru_chars) << "\"\n";
        os << "\tEndArgument\n";
@@ -1070,7 +1124,7 @@ void writeArgument(ostream & os, string const & id, Layout::latexarg const & arg
 
 void Layout::write(ostream & os) const
 {
-       os << "Style " << to_utf8(name_) << '\n';
+       os << "Style \"" << to_utf8(name_) << "\"\n";
        if (!category_.empty() && obsoleted_by_.empty())
                os << "\tCategory \"" << to_utf8(category_) << "\"\n";
        // Can't deduce Copystyle here :-(
@@ -1120,7 +1174,9 @@ void Layout::write(ostream & os) const
        }
        os << "\tInTitle " << intitle << "\n"
              "\tInPreamble " << inpreamble << "\n"
-             "\tTocLevel " << toclevel << '\n';
+             "\tTocLevel " << toclevel << "\n"
+             "\tResumeCounter " << resumecounter << "\n"
+            "\tStepMasterCounter " << stepmastercounter << '\n';
        // ResetArgs does not make sense here
        for (LaTeXArgMap::const_iterator it = latexargs_.begin();
             it != latexargs_.end(); ++it)
@@ -1265,8 +1321,6 @@ void Layout::write(ostream & os) const
                bool first = true;
                os << "\tAlignPossible";
                if (alignpossible & LYX_ALIGN_BLOCK) {
-                       if (!first)
-                               os << ',';
                        os << " Block";
                        first = false;
                }
@@ -1370,6 +1424,13 @@ void Layout::write(ostream & os) const
 }
 
 
+bool Layout::hasArgs() const
+{
+       return !latexargs_.empty() || !postcommandargs_.empty() ||
+               !itemargs_.empty();
+}
+
+
 Layout::LaTeXArgMap Layout::args() const
 {
        LaTeXArgMap args = latexargs_;