Ejemplo n.º 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);
        }
Ejemplo n.º 2
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"));
            }
        }
Ejemplo n.º 3
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;
                }
            ");
        }