Skip to content

Commit

Permalink
reuse defined langcode. refs #65
Browse files Browse the repository at this point in the history
  • Loading branch information
whistyun committed Jun 28, 2023
1 parent 8c5e35a commit 05b31f8
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
6 changes: 4 additions & 2 deletions MdXaml.Plugins/HighlightDefinition.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
Expand All @@ -8,7 +9,8 @@ namespace MdXaml.Plugins
{
public class Definition
{
public string Alias { get; set; }
public Uri Resource { get; set; }
public string? Alias { get; set; }
public Uri? Resource { get; set; }
public string? RealName { get; set; }
}
}
20 changes: 19 additions & 1 deletion MdXaml/Highlighting/InternalHighlightManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,25 @@ private static Stream Open(Uri path)

public void Register(Definition def)
{
var definition = Load(def.Resource);
if (def.Alias is null)
throw new ArgumentException("Definition.Alias must not be null.");

if ((def.Resource is not null && def.RealName is not null))
throw new ArgumentException("Only one of Definition.Resource and Definition.RealName must be set.");

IHighlightingDefinition definition;
if (def.Resource is not null)
definition = Load(def.Resource);

else if (def.RealName is not null)
if (Get(def.RealName) is { } d)
definition = d;
else
throw new ArgumentException($"syntax highlighting `{def.RealName}` is not found.");

else
throw new ArgumentException("Only one of Definition.Resource and Definition.RealName must be set.");


foreach (var alias in def.Alias.Split(','))
{
Expand Down
3 changes: 2 additions & 1 deletion samples/MdXaml.Demo/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
<mdagif:AnimatedGifPluginSetup/>

<mdplugins:MdXamlPlugins.Highlights>
<mdplugins:Definition Alias="pegasus,peg" Resource="pack://application:,,,/Asset/Pegasus-Mode.xshd" />
<mdplugins:Definition Alias="pegasus,peg" Resource="pack://application:,,,/Asset/Pegasus-Mode.xshd" />
<mdplugins:Definition Alias="typescript,ts" RealName="javascript" />
</mdplugins:MdXamlPlugins.Highlights>
</mdplugins:MdXamlPlugins>
</Application.Resources>
Expand Down

0 comments on commit 05b31f8

Please sign in to comment.