private void SetupSyntaxHighlighting() { var colorizer = new MarkdownHighlightingColorizer(); var blockBackgroundRenderer = new BlockBackgroundRenderer(); TextChanged += (s, e) => { try { AbstractSyntaxTree = GenerateAbstractSyntaxTree(Text); colorizer.UpdateAbstractSyntaxTree(AbstractSyntaxTree); blockBackgroundRenderer.UpdateAbstractSyntaxTree(AbstractSyntaxTree); // The block nature of markdown causes edge cases in the syntax hightlighting. // This is the nuclear option but it doesn't seem to cause issues. EditBox.TextArea.TextView.Redraw(); } catch (Exception ex) { // See #159 Notify.Alert($"Abstract Syntax Tree generation failed: {ex.ToString()}"); } }; ThemeChanged += (s, e) => { colorizer.OnThemeChanged(e.Theme); blockBackgroundRenderer.OnThemeChanged(e.Theme); }; EditBox.TextArea.TextView.LineTransformers.Add(colorizer); EditBox.TextArea.TextView.BackgroundRenderers.Add(blockBackgroundRenderer); }
private void SetupSyntaxHighlighting() { var colorizer = new MarkdownHighlightingColorizer(); var blockBackgroundRenderer = new BlockBackgroundRenderer(); TextChanged += (s, e) => { AbstractSyntaxTree = Markdown.GenerateAbstractSyntaxTree(Text); colorizer.UpdateAbstractSyntaxTree(AbstractSyntaxTree); blockBackgroundRenderer.UpdateAbstractSyntaxTree(AbstractSyntaxTree); }; ThemeChanged += (s, e) => { colorizer.OnThemeChanged(e.Theme); blockBackgroundRenderer.OnThemeChanged(e.Theme); }; EditBox.TextArea.TextView.LineTransformers.Add(colorizer); EditBox.TextArea.TextView.BackgroundRenderers.Add(blockBackgroundRenderer); }