private void CreateStylesheet()
        {
            //variable names kept for parity with python
            var t2c = new Dictionary<TokenType, string>()
            {
                {TokenTypes.Token, ""}
            };
            var c2s = new Dictionary<string, ClassToStyle>();

            var style = new StringBuilder();

            foreach (var kvp in _style)
            {
                var ttype = kvp.Key;
                var ndef = kvp.Value;

                var name = GetCssClass(ttype);
                style.Clear();

                if (!string.IsNullOrEmpty(ndef.Color))
                    style.AppendFormat("color: #{0}; ", ndef.Color);
                if (ndef.Bold)
                    style.Append("font-weight: bold; ");
                if (ndef.Italic)
                    style.Append("font-style: italic; ");
                if (ndef.Underline)
                    style.Append("text-decoration: underline; ");
                if (!string.IsNullOrEmpty(ndef.BackgroundColor))
                    style.AppendFormat("background-color: #{0}; ", ndef.BackgroundColor);
                if (!string.IsNullOrEmpty(ndef.BorderColor))
                    style.AppendFormat("border-color: #{0}; ", ndef.BorderColor);
                if (style.Length > 0)
                {
                    style.Length = style.Length - 2; //delete trailing "; "
                    t2c[ttype] = name;
                    c2s[name] = new ClassToStyle {StyleRules = style.ToString(), TokenType = ttype};
                }
            }

            _tokenToClassMap = new TokenTypeMap(t2c);
            _cssToStyleMap = c2s;

        }
Example #2
0
        static TokenTypeMap()
        {
            Instance = new TokenTypeMap();
            Instance._map[TokenTypes.Token] = "";
            Instance._map[TokenTypes.Text] = "";
            Instance._map[TokenTypes.Whitespace] = "w";
            Instance._map[TokenTypes.Escape] = "esc";
            Instance._map[TokenTypes.Error] = "err";
            Instance._map[TokenTypes.Other] = "x";
            Instance._map[TokenTypes.Keyword] = "k";
            Instance._map[TokenTypes.Keyword.Constant] = "kc";
            Instance._map[TokenTypes.Keyword.Declaration] = "kd";
            Instance._map[TokenTypes.Keyword.Namespace] = "kn";
            Instance._map[TokenTypes.Keyword.Pseudo] = "kp";
            Instance._map[TokenTypes.Keyword.Reserved] = "kr";
            Instance._map[TokenTypes.Keyword.Type] = "kt";
            Instance._map[TokenTypes.Name] = "n";
            Instance._map[TokenTypes.Name.Attribute] = "na";
            Instance._map[TokenTypes.Name.Builtin] = "nb";
            Instance._map[TokenTypes.Name.Builtin.Pseudo] = "bp";
            Instance._map[TokenTypes.Name.Class] = "nc";
            Instance._map[TokenTypes.Name.Constant] = "no";
            Instance._map[TokenTypes.Name.Decorator] = "nd";
            Instance._map[TokenTypes.Name.Entity] = "ni";
            Instance._map[TokenTypes.Name.Exception] = "ne";
            Instance._map[TokenTypes.Name.Function] = "nf";
            Instance._map[TokenTypes.Name.Property] = "py";
            Instance._map[TokenTypes.Name.Label] = "nl";
            Instance._map[TokenTypes.Name.Namespace] = "nn";
            Instance._map[TokenTypes.Name.Other] = "nx";
            Instance._map[TokenTypes.Name.Tag] = "nt";
            Instance._map[TokenTypes.Name.Variable] = "nv";
            Instance._map[TokenTypes.Name.Variable.Class] = "vc";
            Instance._map[TokenTypes.Name.Variable.Global] = "vg";
            Instance._map[TokenTypes.Name.Variable.Instance] = "vi";
            Instance._map[TokenTypes.Literal] = "l";
            Instance._map[TokenTypes.Literal.Date] = "ld";
            Instance._map[TokenTypes.String] = "s";
            Instance._map[TokenTypes.String.Backtick] = "sb";
            Instance._map[TokenTypes.String.Char] = "sc";
            Instance._map[TokenTypes.String.Doc] = "sd";
            Instance._map[TokenTypes.String.Double] = "s2";
            Instance._map[TokenTypes.String.Escape] = "se";
            Instance._map[TokenTypes.String.Heredoc] = "sh";
            Instance._map[TokenTypes.String.Interpol] = "si";
            Instance._map[TokenTypes.String.Other] = "sx";
            Instance._map[TokenTypes.String.Regex] = "sr";
            Instance._map[TokenTypes.String.Single] = "s1";
            Instance._map[TokenTypes.String.Symbol] = "ss";
            Instance._map[TokenTypes.Number] = "m";
            Instance._map[TokenTypes.Number.Bin] = "mb";
            Instance._map[TokenTypes.Number.Float] = "mf";
            Instance._map[TokenTypes.Number.Hex] = "mh";
            Instance._map[TokenTypes.Number.Integer] = "mi";
            Instance._map[TokenTypes.Number.Integer.Long] = "il";
            Instance._map[TokenTypes.Number.Oct] = "mo";
            Instance._map[TokenTypes.Operator] = "o";
            Instance._map[TokenTypes.Operator.Word] = "ow";
            Instance._map[TokenTypes.Punctuation] = "p";
            Instance._map[TokenTypes.Comment] = "c";
            Instance._map[TokenTypes.Comment.Hashbang] = "ch";
            Instance._map[TokenTypes.Comment.Multiline] = "cm";
            Instance._map[TokenTypes.Comment.Preproc] = "cp";
            Instance._map[TokenTypes.Comment.PreprocFile] = "cpf";
            Instance._map[TokenTypes.Comment.Single] = "c1";
            Instance._map[TokenTypes.Comment.Special] = "cs";
            Instance._map[TokenTypes.Generic] = "g";
            Instance._map[TokenTypes.Generic.Deleted] = "gd";
            Instance._map[TokenTypes.Generic.Emph] = "ge";
            Instance._map[TokenTypes.Generic.Error] = "gr";
            Instance._map[TokenTypes.Generic.Heading] = "gh";
            Instance._map[TokenTypes.Generic.Inserted] = "gi";
            Instance._map[TokenTypes.Generic.Output] = "go";
            Instance._map[TokenTypes.Generic.Prompt] = "gp";
            Instance._map[TokenTypes.Generic.Strong] = "gs";
            Instance._map[TokenTypes.Generic.Subheading] = "gu";
            Instance._map[TokenTypes.Generic.Traceback] = "gt";

        }
Example #3
0
 static TokenTypeMap()
 {
     Instance = new TokenTypeMap();
     Instance._map[TokenTypes.Token]                  = "";
     Instance._map[TokenTypes.Text]                   = "";
     Instance._map[TokenTypes.Whitespace]             = "w";
     Instance._map[TokenTypes.Escape]                 = "esc";
     Instance._map[TokenTypes.Error]                  = "err";
     Instance._map[TokenTypes.Other]                  = "x";
     Instance._map[TokenTypes.Keyword]                = "k";
     Instance._map[TokenTypes.Keyword.Constant]       = "kc";
     Instance._map[TokenTypes.Keyword.Declaration]    = "kd";
     Instance._map[TokenTypes.Keyword.Namespace]      = "kn";
     Instance._map[TokenTypes.Keyword.Pseudo]         = "kp";
     Instance._map[TokenTypes.Keyword.Reserved]       = "kr";
     Instance._map[TokenTypes.Keyword.Type]           = "kt";
     Instance._map[TokenTypes.Name]                   = "n";
     Instance._map[TokenTypes.Name.Attribute]         = "na";
     Instance._map[TokenTypes.Name.Builtin]           = "nb";
     Instance._map[TokenTypes.Name.Builtin.Pseudo]    = "bp";
     Instance._map[TokenTypes.Name.Class]             = "nc";
     Instance._map[TokenTypes.Name.Constant]          = "no";
     Instance._map[TokenTypes.Name.Decorator]         = "nd";
     Instance._map[TokenTypes.Name.Entity]            = "ni";
     Instance._map[TokenTypes.Name.Exception]         = "ne";
     Instance._map[TokenTypes.Name.Function]          = "nf";
     Instance._map[TokenTypes.Name.Property]          = "py";
     Instance._map[TokenTypes.Name.Label]             = "nl";
     Instance._map[TokenTypes.Name.Namespace]         = "nn";
     Instance._map[TokenTypes.Name.Other]             = "nx";
     Instance._map[TokenTypes.Name.Tag]               = "nt";
     Instance._map[TokenTypes.Name.Variable]          = "nv";
     Instance._map[TokenTypes.Name.Variable.Class]    = "vc";
     Instance._map[TokenTypes.Name.Variable.Global]   = "vg";
     Instance._map[TokenTypes.Name.Variable.Instance] = "vi";
     Instance._map[TokenTypes.Literal]                = "l";
     Instance._map[TokenTypes.Literal.Date]           = "ld";
     Instance._map[TokenTypes.String]                 = "s";
     Instance._map[TokenTypes.String.Backtick]        = "sb";
     Instance._map[TokenTypes.String.Char]            = "sc";
     Instance._map[TokenTypes.String.Doc]             = "sd";
     Instance._map[TokenTypes.String.Double]          = "s2";
     Instance._map[TokenTypes.String.Escape]          = "se";
     Instance._map[TokenTypes.String.Heredoc]         = "sh";
     Instance._map[TokenTypes.String.Interpol]        = "si";
     Instance._map[TokenTypes.String.Other]           = "sx";
     Instance._map[TokenTypes.String.Regex]           = "sr";
     Instance._map[TokenTypes.String.Single]          = "s1";
     Instance._map[TokenTypes.String.Symbol]          = "ss";
     Instance._map[TokenTypes.Number]                 = "m";
     Instance._map[TokenTypes.Number.Bin]             = "mb";
     Instance._map[TokenTypes.Number.Float]           = "mf";
     Instance._map[TokenTypes.Number.Hex]             = "mh";
     Instance._map[TokenTypes.Number.Integer]         = "mi";
     Instance._map[TokenTypes.Number.Integer.Long]    = "il";
     Instance._map[TokenTypes.Number.Oct]             = "mo";
     Instance._map[TokenTypes.Operator]               = "o";
     Instance._map[TokenTypes.Operator.Word]          = "ow";
     Instance._map[TokenTypes.Punctuation]            = "p";
     Instance._map[TokenTypes.Comment]                = "c";
     Instance._map[TokenTypes.Comment.Hashbang]       = "ch";
     Instance._map[TokenTypes.Comment.Multiline]      = "cm";
     Instance._map[TokenTypes.Comment.Preproc]        = "cp";
     Instance._map[TokenTypes.Comment.PreprocFile]    = "cpf";
     Instance._map[TokenTypes.Comment.Single]         = "c1";
     Instance._map[TokenTypes.Comment.Special]        = "cs";
     Instance._map[TokenTypes.Generic]                = "g";
     Instance._map[TokenTypes.Generic.Deleted]        = "gd";
     Instance._map[TokenTypes.Generic.Emph]           = "ge";
     Instance._map[TokenTypes.Generic.Error]          = "gr";
     Instance._map[TokenTypes.Generic.Heading]        = "gh";
     Instance._map[TokenTypes.Generic.Inserted]       = "gi";
     Instance._map[TokenTypes.Generic.Output]         = "go";
     Instance._map[TokenTypes.Generic.Prompt]         = "gp";
     Instance._map[TokenTypes.Generic.Strong]         = "gs";
     Instance._map[TokenTypes.Generic.Subheading]     = "gu";
     Instance._map[TokenTypes.Generic.Traceback]      = "gt";
 }