Skip to content

Commit

Permalink
Merge pull request #75 from cuiliang/mergeToUpstream
Browse files Browse the repository at this point in the history
Support customized hilighting for dark theme
  • Loading branch information
whistyun authored Nov 14, 2023
2 parents d7bfa17 + 71e7710 commit c101963
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
10 changes: 10 additions & 0 deletions MdXaml/Highlighting/InternalHighlightManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,16 @@ public void Register(Definition def)

public IHighlightingDefinition? Get(string langcode)
{
// If provided, try the method of customized syntax highlighting first.
if (MarkdownCustomHighlighting.HighlightingResolver != null)
{
var def = MarkdownCustomHighlighting.HighlightingResolver(langcode);
if (def != null)
{
return def;
}
}

return HighlightingManager.Instance.GetDefinitionByExtension("." + langcode)
?? GetHighlight(langcode);
}
Expand Down
27 changes: 27 additions & 0 deletions MdXaml/Highlighting/MarkdownCustomHighlighting.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ICSharpCode.AvalonEdit.Highlighting;

namespace MdXaml.Highlighting
{
/// <summary>
/// customized syntax highlighting
/// </summary>
public static class MarkdownCustomHighlighting
{
/// <summary>
/// delegate for customize highlighting
/// </summary>
/// <param name="langcode">language code to highlight</param>
/// <returns>IHighlightingDefinition for the langcode</returns>
public delegate IHighlightingDefinition? GetHighlightingFunc(string langcode);

/// <summary>
/// customized highlighting method
/// </summary>
public static GetHighlightingFunc? HighlightingResolver { get; set; } = null;
}
}

0 comments on commit c101963

Please sign in to comment.