コード例 #1
0
        private string GetThemeValues(Themes.Theme theme, string setting = null)
        {
            IDictionary <string, string> dictionary = GetThemeValuesDictionary(theme, setting);
            StringBuilder sb = new StringBuilder();

            if (setting != null)
            {
                sb.Append("label:").Append(GetLabel(setting)).Append(';');
            }
            foreach (KeyValuePair <string, string> kvp in dictionary)
            {
                sb.Append(kvp.Key).Append(':').Append(kvp.Value).Append(';');
            }
            return(sb.ToString());
        }
コード例 #2
0
        private async Task InitThemeCss()
        {
            string themeName = Theme ?? DefaultSettings.DefaultTheme;
            string uri       = themeName.ToLower().StartsWith("http") ? themeName : "_content/BlazorPrettyCode/" + themeName + ".json";

            string strJson = await GetFromCacheOrNetwork(uri);

            Themes.Theme theme = JsonSerializer.Deserialize <Themes.Theme>(strJson);
            _showLineNumbers = ShowLineNumbers ?? DefaultSettings.ShowLineNumbers;

            _styled.AddGoogleFonts(GetFonts(theme));

            StringBuilder sb = new StringBuilder();

            sb.Append("overflow-y: auto;");
            sb.Append("margin-bottom: 1em;");
            IDictionary <string, string> settings = GetThemeValuesDictionary(theme);

            if (settings.ContainsKey("background-color"))
            {
                sb.Append("background-color: ").Append(settings["background-color"]).Append(';');
            }

            _baseDiv                  = _styled.Css(sb.ToString());
            _themePreClass            = _styled.Css(GetThemeValues(theme));
            _themeTagSymbolsClass     = _styled.Css(GetThemeValues(theme, "Tag symbols"));
            _themeTagNameClass        = _styled.Css(GetThemeValues(theme, "Tag name"));
            _themeAttributeNameClass  = _styled.Css(GetThemeValues(theme, "Attribute name"));
            _themeAttributeValueClass = _styled.Css(GetThemeValues(theme, "Attribute value"));
            _themeQuotedStringClass   = _styled.Css(GetThemeValues(theme, "String"));
            _themeRazorKeywordClass   = _styled.Css(GetThemeValues(theme, "Razor Keyword"));
            _themeTextClass           = _styled.Css(GetThemeValues(theme, "Text"));
            _themeCssProperty         = _styled.Css(GetThemeValues(theme, "CSS Propery"));
            _themeCssClass            = _styled.Css(GetThemeValues(theme, "CSS Class"));

            _highlightLines = GetLineNumbers(HighlightLines);
            if (_highlightLines.Count > 0)
            {
                _themeRowHighlight = _styled.Css(GetThemeValues(theme, "Row Highlight"));

                IDictionary <string, string> dictionary = GetThemeValuesDictionary(theme, "Row Highlight");
                string color  = dictionary.ContainsKey("background-color") ? dictionary["background-color"] : "rgba(0, 0, 0, 0.9)";
                string border = $"border-left: 0.5rem solid {color};";
                _themeRowHighlightBorder = _styled.Css(border);
            }
        }
コード例 #3
0
        private List <GoogleFont> GetFonts(Themes.Theme theme)
        {
            List <GoogleFont> list  = new List <GoogleFont>();
            List <Setting>    fonts = (from s in theme.Settings
                                       where s.Name != null && s.Name.ToLower() == "font"
                                       select s).ToList();

            foreach (Setting font in fonts)
            {
                GoogleFont googleFont = new GoogleFont
                {
                    Name   = font.Settings["font-family"],
                    Styles = font.Settings["font-weight"].Split(',').ToList()
                };
                list.Add(googleFont);
            }

            return(list);
        }
コード例 #4
0
        private IDictionary <string, string> GetThemeValuesDictionary(Themes.Theme theme, string setting = null)
        {
            IDictionary <string, string> dictionary = new Dictionary <string, string>();
            Setting settings = (from s in theme.Settings
                                where s.Name == null
                                select s).SingleOrDefault();

            if (settings != null)
            {
                foreach (KeyValuePair <string, string> kvp in settings.Settings)
                {
                    dictionary.Add(kvp.Key.ToLower(), kvp.Value);
                }
            }

            if (setting != null)
            {
                settings = (from s in theme.Settings
                            where s.Name != null && s.Name.ToLower() == setting.ToLower()
                            select s).SingleOrDefault();

                if (settings != null)
                {
                    foreach (KeyValuePair <string, string> kvp in settings.Settings)
                    {
                        if (!dictionary.ContainsKey(kvp.Key.ToLower()))
                        {
                            dictionary.Add(kvp.Key.ToLower(), kvp.Value);
                        }
                        else
                        {
                            dictionary[kvp.Key.ToLower()] = kvp.Value;
                        }
                    }
                }
            }
            return(dictionary);
        }