示例#1
0
        private string GetCounterReset()
        {
            try
            {
                if (!_KeepOriginalLineNumbers)
                {
                    return(string.Empty);
                }

                if (_lineNumbers.Count >= _lineNum)
                {
                    return(" " + Styled.Css($"counter-reset: linenum {_lineNumbers[_lineNum - 1] - 1};"));
                }
                if (_addedCodeString && _lineNum == _lineNumbers.Count + 1)
                {
                    return(string.Empty);
                }
                if (_lineNumbers.Count + _codeLineNumbers.Count >= _lineNum)
                {
                    int baseCount = _addedCodeString ? _lineNumbers.Count + 1 : _lineNumbers.Count;
                    int offset    = _addedCodeString ? 1 : 0;
                    return(" " + Styled.Css($"counter-reset: linenum {_codeLineNumbers[_lineNum - baseCount - 1] - offset};"));
                }
            }
            catch (Exception)
            {
                //ignored
            }
            return(string.Empty);
        }
        protected async Task RefreshStyles()
        {
            SetColorScheme(ColorScheme?.ToLower() ?? "gray");

            var parametersDict = GetPropertiesDict();

            if (string.IsNullOrEmpty(className))
            {
                className = await Styled.CssAsync(GetCss(parametersDict));
            }
            else
            {
                await Styled.CssAsync(className, GetCss(parametersDict));
            }

            await ApplyPseudoClasses(this, className);
        }
        private async Task ApplyPseudoClasses(StyledComponentBase component, string _className)
        {
            var pseudoClassDict = component.GetPseudoClassesWithProperties();

            foreach (var key in pseudoClassDict.Keys)
            {
                var subComponent = pseudoClassDict[key];
                if (subComponent == null)
                {
                    continue;
                }
                var pseudoClassName = ApplyPseudoClass(key, _className);

                Console.WriteLine($"{ApplyPseudoClass(key, _className)}: {GetCss(subComponent.GetPropertiesDict())}");
                await Styled.CssAsync(
                    pseudoClassName,
                    GetCss(subComponent.GetPropertiesDict()));

                await ApplyPseudoClasses(subComponent, pseudoClassName);
            }
        }
示例#4
0
        protected override async Task OnInitializedAsync()
        {
            _styled       = Styled.WithId("pretty-code");
            _unsubscriber = DefaultSettings.Subscribe(this);
            bool debug         = Debug ?? DefaultSettings.IsDevelopmentMode;
            bool showException = ShowException ?? DefaultSettings.ShowException;

            InitSettings();

            await InitSourceFile(showException);

            if (debug)
            {
                PrintToConsole();
            }

            InitCSS();
            await InitThemeCss();

            _shouldRender = true;
        }
示例#5
0
        protected override async Task OnAfterRenderAsync(bool firstRender)
        {
            if (firstRender)
            {
                _currentTheme = SlidesAPI.State.Theme;
            }
            if (_currentTheme != SlidesAPI.State.Theme)
            {
                IStyled themeStyled = Styled.WithId("BlazorSlidesTheme", 200_000);
                await themeStyled.ClearStylesAsync();

                _currentTheme = SlidesAPI.State.Theme;
                _rendered     = false;
            }
            if (_classname != null && _previousClassname != _classname && !_rendered)
            {
                _previousClassname = _classname;
                _rendered          = true;
                Classname          = _classname;
                await ClassnameChanged.InvokeAsync(Classname);
            }
        }
示例#6
0
        private async Task InitThemeCss()
        {
            string themeName = Theme ?? DefaultConfig.DefaultTheme;
            string uri       = themeName.ToLower().StartsWith("http") ? themeName : "_content/BlazorPrettyCode/" + themeName + ".json";

            string strJson = await HttpClient.GetStringAsync(uri);

            Theme theme = JsonSerializer.Parse <Theme>(strJson);

            _showLineNumbers = ShowLineNumbers ?? DefaultConfig.ShowLineNumbers;

            foreach (string font in getFonts(theme))
            {
                await Styled.Fontface(font);
            }

            _themePreClass = await Styled.Css(getThemeValues(theme));

            _themeTagSymbolsClass = await Styled.Css(getThemeValues(theme, "Tag symbols"));

            _themeTagNameClass = await Styled.Css(getThemeValues(theme, "Tag name"));

            _themeAttributeNameClass = await Styled.Css(getThemeValues(theme, "Attribute name"));

            _themeAttributeValueClass = await Styled.Css(getThemeValues(theme, "Attribute value"));

            _themeQuotedStringClass = await Styled.Css(getThemeValues(theme, "String"));

            _themeRazorKeywordClass = await Styled.Css(getThemeValues(theme, "Razor Keyword"));

            _themeTextClass = await Styled.Css(getThemeValues(theme, "Text"));

            _highlightLines = GetLineNumbers(HighlightLines);
            if (_highlightLines.Count > 0)
            {
                _themeRowHighlight = await Styled.Css(getThemeValues(theme, "Row Highlight"));
            }
        }
示例#7
0
        private async Task InitCSS()
        {
            _basePreClass = await Styled.Css(@"
                display: table;
                table-layout: fixed;
                width: 100%; /* anything but auto, otherwise fixed layout not guaranteed */
                white-space: pre-wrap;
                -webkit-border-radius: 5px;
                @media only screen and (min-width: 320px) and (max-width: 480px) {
                    font-size: 50%;
                }
                @media (min-width: 481px) and (max-width: 1223px) {
                    font-size: 80%;
                }
                &:before {
                    counter-reset: linenum;
                }
            ");

            //Code Row

            _baseRowSpan = await Styled.Css(@"
                display: table-row;
                counter-increment: linenum;
            ");

            _baseLineNumbersCell = await Styled.Css(@"
                display: table-cell;
                user-select: none;
                -moz-user-select: none;
                -webkit-user-select: none;
                width: 4em;
                border-right-style: solid;
                border-right-width: 1px;
                border-right-color: rgb(223, 225, 230);
                &:before {
                    content: counter(linenum) '.';
                    text-align: right;
                    display: block;
                }
            ");

            _baseCodeCell = await Styled.Css(@"
                display: table-cell;
                padding-left: 1em;
            ");

            //Title Row

            _baseRowSpanTitle = await Styled.Css(@"
                display: table-row;
            ");

            _baseCellSpacer = await Styled.Css(@"
                display: table-cell;
                user-select: none;
                -moz-user-select: none;
                -webkit-user-select: none;
                width: 4em;
                border-bottom-style: solid;
                border-bottom-width: 1px;
                border-bottom-color: rgb(223, 225, 230);
            ");

            _baseCellTitle = await Styled.Css(@"
                display: table-cell;
                padding: 0.4em 1em 0.4em;
                font-weight: bold;
                border-bottom-style: solid;
                border-bottom-width: 1px;
                border-bottom-color: rgb(223, 225, 230);
            ");

            // Expand / Collapse

            _baseCollapse = await Styled.Css(@"
                font-weight: normal;
                font-size: 0.8em;
                display: table-cell;
                width: 10em;
                &:hover {
                    text-decoration: underline;
                    cursor: pointer;
                }
            ");
        }