Skip to content

Commit

Permalink
load syntax files from plugin directory
Browse files Browse the repository at this point in the history
  • Loading branch information
szensk committed Feb 24, 2018
1 parent a20b471 commit eb6e1c9
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
25 changes: 25 additions & 0 deletions QuickLook.Plugin/QuickLook.Plugin.TextViewer/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,14 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

using System;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Windows;
using System.Xml;
using ICSharpCode.AvalonEdit.Highlighting;
using ICSharpCode.AvalonEdit.Highlighting.Xshd;
using QuickLook.Common.Plugin;

namespace QuickLook.Plugin.TextViewer
Expand All @@ -30,6 +35,26 @@ public class Plugin : IViewer

public void Init()
{
HighlightingManager hlm = HighlightingManager.Instance;

string assemblyPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
if (string.IsNullOrEmpty(assemblyPath)) return;

string syntaxPath = Path.Combine(assemblyPath, "Syntax");
if (!Directory.Exists(syntaxPath)) return;

foreach (string file in Directory.EnumerateFiles(syntaxPath, "*.xshd"))
{
string lang = Path.GetFileNameWithoutExtension(file);
using (Stream s = File.OpenRead(Path.GetFullPath(file)))
using (XmlTextReader reader = new XmlTextReader(s))
{
XshdSyntaxDefinition xshd = HighlightingLoader.LoadXshd(reader);
IHighlightingDefinition highlightingDefinition = HighlightingLoader.Load(xshd, hlm);
if (xshd.Extensions.Count > 0)
hlm.RegisterHighlighting(lang, xshd.Extensions.ToArray(), highlightingDefinition);
}
}
}

public bool CanHandle(string path)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xaml" />
<Reference Include="System.Xml" />
<Reference Include="UtfUnknown, Version=1.0.0.0, Culture=neutral, PublicKeyToken=90217ce7a23260d4, processorArchitecture=MSIL">
<HintPath>..\..\packages\UTF.Unknown.1.0.0-beta1\lib\net40\UtfUnknown.dll</HintPath>
</Reference>
Expand Down

0 comments on commit eb6e1c9

Please sign in to comment.