private void RenderDocument() { _codeView.Blocks.Clear(); _formatter = new RichTextBlockFormatter(); _formatter.FormatRichTextBlock(_displayedText, _language, _codeView); _rendered = true; }
public static async Task Open(string content) { var dialog = new DumpJsonDialog(content); var formatter = new RichTextBlockFormatter(); formatter.FormatRichTextBlock(content, Languages.JavaScript, dialog.TextBox_DumpContent); _ = await dialog.ShowAsync(); }
protected override void Render(RichTextBlock richBlock) { richBlock.Blocks.Clear(); richBlock.Blocks.Add(Paragraph); if (!string.IsNullOrEmpty(_codeBlock.Language) && Languages.FindById(_codeBlock.Language) is { } language) { var a = new RichTextBlockFormatter(ElementTheme.Dark); a.FormatInlines(_codeBlock.Content, language, Paragraph.Inlines); }
private void RenderDocument() { if (codeView != null) { codeView.Blocks?.Clear(); formatter = new RichTextBlockFormatter(ActualTheme); formatter.FormatRichTextBlock(ViewModel.TextValue, ViewModel.CodeLanguage, codeView); } }
private RichTextBlockFormatter GenerateRichTextFormatter() { var formatter = new RichTextBlockFormatter(App.ActualTheme); if (App.ActualTheme == ElementTheme.Dark) { UpdateFormatterDarkThemeColors(formatter); } return(formatter); }
private RichTextBlockFormatter GenerateRichTextFormatter() { ElementTheme currentTheme = ThemeHelper.IsDarkTheme() ? ElementTheme.Dark : ElementTheme.Light; RichTextBlockFormatter formatter = new RichTextBlockFormatter(currentTheme); if (currentTheme == ElementTheme.Dark) { UpdateFormatterDarkThemeColors(formatter); } return(formatter); }
private void RenderDocument() { if (_codeView != null) { #if HAS_UNO _codeView.Text = _displayedText ?? string.Empty; #else _codeView.Blocks?.Clear(); _formatter = new RichTextBlockFormatter(_theme); _formatter.FormatRichTextBlock(_displayedText, _language, _codeView); #endif _rendered = true; } }
/// <summary> /// Called when a Code Block is being rendered. /// </summary> /// <returns>Parsing was handled Successfully</returns> bool ICodeBlockResolver.ParseSyntax(InlineCollection inlineCollection, string text, string codeLanguage) { var eventArgs = new CodeBlockResolvingEventArgs(inlineCollection, text, codeLanguage); CodeBlockResolving?.Invoke(this, eventArgs); try { var result = eventArgs.Handled; if (UseSyntaxHighlighting && !result && codeLanguage != null) { var language = Languages.FindById(codeLanguage); if (language != null) { RichTextBlockFormatter formatter; if (CodeStyling != null) { formatter = new RichTextBlockFormatter(CodeStyling); } else { //var theme = themeListener.CurrentTheme == ApplicationTheme.Dark ? ElementTheme.Dark : ElementTheme.Light; //if (RequestedTheme != ElementTheme.Default) //{ // theme = RequestedTheme; //} var theme = ActualTheme; if (RequestedTheme != ElementTheme.Default) { theme = RequestedTheme; } formatter = new RichTextBlockFormatter(theme); } formatter.FormatInlines(text, language, inlineCollection); return(true); } } return(result); } catch { return(false); } }
private async void Render() { PresentationBlock.Blocks.Clear(); var result = await GetCodeFileText(); if (result == null) { return; } var formatter = new RichTextBlockFormatter(MainGrid.RequestedTheme); var plainText = formatter.Styles[ScopeName.PlainText]; MainGrid.Background = (plainText?.Background ?? StyleDictionary.White).GetSolidColorBrush(); formatter.FormatRichTextBlock(result.Item1, result.Item2, PresentationBlock); }
private void UpdateFormatterDarkThemeColors(RichTextBlockFormatter formatter) { // Replace the default dark theme resources with ones that more closely align to VS Code dark theme. formatter.Styles.Remove(formatter.Styles[ScopeName.XmlAttribute]); formatter.Styles.Remove(formatter.Styles[ScopeName.XmlAttributeQuotes]); formatter.Styles.Remove(formatter.Styles[ScopeName.XmlAttributeValue]); formatter.Styles.Remove(formatter.Styles[ScopeName.HtmlComment]); formatter.Styles.Remove(formatter.Styles[ScopeName.XmlDelimiter]); formatter.Styles.Remove(formatter.Styles[ScopeName.XmlName]); formatter.Styles.Add(new ColorCode.Styling.Style(ScopeName.XmlAttribute) { Foreground = "#FF87CEFA", ReferenceName = "xmlAttribute" }); formatter.Styles.Add(new ColorCode.Styling.Style(ScopeName.XmlAttributeQuotes) { Foreground = "#FFFFA07A", ReferenceName = "xmlAttributeQuotes" }); formatter.Styles.Add(new ColorCode.Styling.Style(ScopeName.XmlAttributeValue) { Foreground = "#FFFFA07A", ReferenceName = "xmlAttributeValue" }); formatter.Styles.Add(new ColorCode.Styling.Style(ScopeName.HtmlComment) { Foreground = "#FF6B8E23", ReferenceName = "htmlComment" }); formatter.Styles.Add(new ColorCode.Styling.Style(ScopeName.XmlDelimiter) { Foreground = "#FF808080", ReferenceName = "xmlDelimiter" }); formatter.Styles.Add(new ColorCode.Styling.Style(ScopeName.XmlName) { Foreground = "#FF5F82E8", ReferenceName = "xmlName" }); }
private async void PrintButton_Click(object sender, RoutedEventArgs e) { SampleController.Current.DisplayWaitRing = true; var printblock = new RichTextBlock { FontFamily = _codeView.FontFamily, RequestedTheme = ElementTheme.Light }; var printFormatter = new RichTextBlockFormatter(ElementTheme.Light); printFormatter.FormatRichTextBlock(_displayedText, _language, printblock); _printHelper = new PrintHelper(_container); _printHelper.AddFrameworkElementToPrint(printblock); _printHelper.OnPrintFailed += PrintHelper_OnPrintFailed; _printHelper.OnPrintSucceeded += PrintHelper_OnPrintSucceeded; _printHelper.OnPrintCanceled += PrintHelper_OnPrintCanceled; await _printHelper.ShowPrintUIAsync("Windows Community Toolkit Sample App"); }