Skip to content

Commit

Permalink
Catch exception from xshd loader
Browse files Browse the repository at this point in the history
1. New xshd for dark mode
2. Moved xshd sign to https://github.com/QL-Win/QuickLook/wiki/On-the-Shoulders-of-Giants
  • Loading branch information
emako committed Jan 1, 2025
1 parent 31325e3 commit fd60013
Show file tree
Hide file tree
Showing 87 changed files with 264 additions and 845 deletions.
30 changes: 19 additions & 11 deletions QuickLook.Plugin/QuickLook.Plugin.TextViewer/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
using ICSharpCode.AvalonEdit.Highlighting.Xshd;
using QuickLook.Common.Helpers;
using QuickLook.Common.Plugin;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
Expand All @@ -46,8 +47,8 @@ public void Init()
// pre-load
var _ = new TextEditor();

_hlmLight = getHighlightingManager(Themes.Light, "Light");
_hlmDark = getHighlightingManager(Themes.Dark, "Dark");
_hlmLight = GetHighlightingManager(Themes.Light, "Light");
_hlmDark = GetHighlightingManager(Themes.Dark, "Dark");
}

public bool CanHandle(string path)
Expand Down Expand Up @@ -117,7 +118,7 @@ private static bool IsText(IReadOnlyList<byte> buffer, int size)
return true;
}

private HighlightingManager getHighlightingManager(Themes theme, string dirName)
private HighlightingManager GetHighlightingManager(Themes theme, string dirName)
{
var hlm = new HighlightingManager();

Expand All @@ -131,15 +132,22 @@ private HighlightingManager getHighlightingManager(Themes theme, string dirName)

foreach (var file in Directory.EnumerateFiles(syntaxPath, "*.xshd").OrderBy(f => f))
{
Debug.WriteLine(file);
var ext = Path.GetFileNameWithoutExtension(file);
using (Stream s = File.OpenRead(Path.GetFullPath(file)))
using (var reader = new XmlTextReader(s))
try
{
var xshd = HighlightingLoader.LoadXshd(reader);
var highlightingDefinition = HighlightingLoader.Load(xshd, hlm);
if (xshd.Extensions.Count > 0)
hlm.RegisterHighlighting(ext, xshd.Extensions.ToArray(), highlightingDefinition);
Debug.WriteLine(file);
var ext = Path.GetFileNameWithoutExtension(file);
using (Stream s = File.OpenRead(Path.GetFullPath(file)))
using (var reader = new XmlTextReader(s))
{
var xshd = HighlightingLoader.LoadXshd(reader);
var highlightingDefinition = HighlightingLoader.Load(xshd, hlm);
if (xshd.Extensions.Count > 0)
hlm.RegisterHighlighting(ext, xshd.Extensions.ToArray(), highlightingDefinition);
}
}
catch (Exception e)
{
ProcessHelper.WriteLog(e.ToString());
}
}

Expand Down
206 changes: 206 additions & 0 deletions QuickLook.Plugin/QuickLook.Plugin.TextViewer/Syntax/Dark/Batch.xshd
Original file line number Diff line number Diff line change
@@ -0,0 +1,206 @@
<?xml version="1.0" encoding="utf-8"?>

<SyntaxDefinition name="Batch" extensions=".bat;.cmd">

<Environment>
<Default color="White" bgcolor="#000000"/>
<Selection color="#000080" bgcolor="#C3C3FF"/>
<LineNumbers color="#A9A9A9" bgcolor="#000000"/>
<CaretMarker color="#A9A9A9"/>
<VRuler color="#808080"/>

<FoldLine color="#D3D3D3" bgcolor="#000000"/>
<FoldMarker color="#D3D3D3" bgcolor="#000000"/>
<SelectedFoldLine color="#D3D3D3" bgcolor="#000000"/>

<EOLMarkers color="#A9A9A9"/>
<SpaceMarkers color="#A9A9A9"/>
<TabMarkers color="#A9A9A9"/>
<InvalidLines color="#A9A9A9"/>
</Environment>

<Properties>
<Property name="LineComment" value="REM "/>
</Properties>

<Digits name="Digits" color="White" bold="false" italic="false"/>

<RuleSets>
<RuleSet ignorecase="true">

<Delimiters>@+*\/=|'&lt;&gt;?;</Delimiters>

<Span name="LineComment1" stopateol="true" color="#00FF00" bold="false" italic="false">
<Begin singleword="true">REM </Begin>
</Span>

<Span name="LineComment2" stopateol="true" color="#00FF00" bold="false" italic="false">
<Begin startofline="true">::</Begin>
</Span>

<Span name="Label" stopateol="true" color="#FF0000" bgcolor="#FFFF80" bold="false" italic="false">
<Begin startofline="true">:</Begin>
</Span>

<Span name="Output" stopateol="true" color="White" bold="false" italic="false">
<Begin color="Blue">echo</Begin>
</Span>

<KeyWords name="Keywords1" color="Blue" bold="false" italic="false">
<Key word="aux"/>
<Key word="baud"/>
<Key word="break"/>
<Key word="call"/>
<Key word="cd"/>
<Key word="chcp"/>
<Key word="chdir"/>
<Key word="choice"/>
<Key word="cls"/>
<Key word="cmdextversion"/>
<Key word="cols"/>
<Key word="com"/>
<Key word="con"/>
<Key word="copy"/>
<Key word="cp"/>
<Key word="cut"/>
<Key word="data"/>
<Key word="defined"/>
<Key word="del"/>
<Key word="delay"/>
<Key word="dir"/>
<Key word="do"/>
<Key word="dtr"/>
<Key word="echo"/>
<Key word="else"/>
<Key word="end"/>
<Key word="equ"/>
<Key word="erase"/>
<Key word="errorlevel"/>
<Key word="exist"/>
<Key word="exists"/>
<Key word="exit"/>
<Key word="for"/>
<Key word="geq"/>
<Key word="goto"/>
<Key word="gtr"/>
<Key word="hs"/>
<Key word="idsr"/>
<Key word="if"/>
<Key word="in"/>
<Key word="leq"/>
<Key word="lfnfor"/>
<Key word="lines"/>
<Key word="loadfix"/>
<Key word="loadhigh"/>
<Key word="lock"/>
<Key word="low"/>
<Key word="lpt"/>
<Key word="lpt1"/>
<Key word="lss"/>
<Key word="max"/>
<Key word="md"/>
<Key word="min"/>
<Key word="mkdir"/>
<Key word="move"/>
<Key word="neq"/>
<Key word="normal"/>
<Key word="not"/>
<Key word="nul"/>
<Key word="octs"/>
<Key word="odsr"/>
<Key word="off"/>
<Key word="on"/>
<Key word="parity"/>
<Key word="path"/>
<Key word="pause"/>
<Key word="pause"/>
<Key word="prn"/>
<Key word="prompt"/>
<Key word="rate"/>
<Key word="rd"/>
<Key word="realtime"/>
<Key word="ren"/>
<Key word="rename"/>
<Key word="rmd"/>
<Key word="rmdir"/>
<Key word="rts"/>
<Key word="select"/>
<Key word="separate"/>
<Key word="set"/>
<Key word="sgn"/>
<Key word="shared"/>
<Key word="shift"/>
<Key word="status"/>
<Key word="stop"/>
<Key word="tg"/>
<Key word="then"/>
<Key word="time"/>
<Key word="to"/>
<Key word="truename"/>
<Key word="type"/>
<Key word="unlock"/>
<Key word="ver"/>
<Key word="verify"/>
<Key word="verify"/>
<Key word="vol"/>
<Key word="wait"/>
<Key word="xon"/>
</KeyWords>

<KeyWords name="Keywords2" color="#008080" bold="false" italic="false">
<Key word="append"/>
<Key word="assoc"/>
<Key word="at"/>
<Key word="attrib"/>
<Key word="begin"/>
<Key word="cacls"/>
<Key word="chkdsk"/>
<Key word="chkntfs"/>
<Key word="cmd"/>
<Key word="color"/>
<Key word="comp"/>
<Key word="compact"/>
<Key word="convert"/>
<Key word="ctty"/>
<Key word="date"/>
<Key word="delims"/>
<Key word="diskcomp"/>
<Key word="diskcopy"/>
<Key word="doskey"/>
<Key word="enableextensions"/>
<Key word="endlocal"/>
<Key word="eol"/>
<Key word="fc"/>
<Key word="find"/>
<Key word="findstr"/>
<Key word="format"/>
<Key word="ftype"/>
<Key word="graftabl"/>
<Key word="help"/>
<Key word="keyb"/>
<Key word="label"/>
<Key word="mklink"/>
<Key word="mode"/>
<Key word="more"/>
<Key word="other"/>
<Key word="ping"/>
<Key word="popd"/>
<Key word="print"/>
<Key word="pushd"/>
<Key word="recover"/>
<Key word="replace"/>
<Key word="restore"/>
<Key word="setlocal"/>
<Key word="skip"/>
<Key word="sort"/>
<Key word="start"/>
<Key word="subst"/>
<Key word="title"/>
<Key word="tokens"/>
<Key word="tree"/>
<Key word="ttrib"/>
<Key word="xcopy"/>
</KeyWords>
</RuleSet>
</RuleSets>
</SyntaxDefinition>
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="utf-8" ?>

<SyntaxDefinition name="Lyric" extensions=".lrc" xmlns="http://icsharpcode.net/sharpdevelop/syntaxdefinition/2008">
<Color name="Number" foreground="#B5CEA8" exampleText="3.14" />
<Color name="Punctuation1" foreground="#DA66BE" />
<Color name="Punctuation2" foreground="#FFD710" />
<Color name="Punctuation3" foreground="#FFFFFF" />

<RuleSet name="Object">
<Span color="Punctuation3" ruleSet="Expression">
<Begin>:</Begin>
</Span>
</RuleSet>

<RuleSet name="Array">
<Import ruleSet="Expression"/>
<Span color="Punctuation3">
<Begin>,</Begin>
</Span>
</RuleSet>

<RuleSet name="Expression">
<Span color="Punctuation1" ruleSet="Object" multiline="true">
<Begin>\{</Begin>
<End>\}</End>
</Span>
<Span color="Punctuation2" ruleSet="Array" multiline="true">
<Begin>\[</Begin>
<End>\]</End>
</Span>
<Rule color="Number">
\b0[xX][0-9a-fA-F]+|(\b\d+(\.[0-9]+)?|\.[0-9]+)([eE][+-]?[0-9]+)?
</Rule>
</RuleSet>

<RuleSet>
<Import ruleSet="Expression"/>
</RuleSet>
</SyntaxDefinition>
Original file line number Diff line number Diff line change
@@ -1,15 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>

<!--
ANTLR syntax highlighting
Written by Ezra Altahan
Created 20/06/2016 | Updated 16/10/2016
Version 1.0
hello@exr.be
https://github.com/ei
-->

<SyntaxDefinition name="ANTLR" extensions=".g;.g3;.g4">

<Environment>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>

<!--
ActionScript syntax highlighting
Written by Ezra Altahan
Created 17/01/2013 | Updated 16/10/2016
Version 1.2
hello@exr.be
https://github.com/ei
-->

<SyntaxDefinition name="ActionScript" extensions=".as;.mx">

<Environment>
Expand Down
10 changes: 0 additions & 10 deletions QuickLook.Plugin/QuickLook.Plugin.TextViewer/Syntax/Light/Ada.xshd
Original file line number Diff line number Diff line change
@@ -1,15 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>

<!--
Ada syntax highlighting
Written by Ezra Altahan
Created 15/01/2013 | Updated 16/10/2016
Version 1.0
hello@exr.be
https://github.com/ei
-->

<SyntaxDefinition name="Ada" extensions=".ada;.ads;.adb">

<Environment>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>

<!--
Assembly syntax highlighting
Written by Ezra Altahan
Created 03/01/2011 | Updated 23/10/2016
Version 1.6
hello@exr.be
https://github.com/ei
-->

<SyntaxDefinition name="Assembly" extensions=".asm">

<Environment>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>

<!--
AutoHotkey syntax highlighting
Written by Ezra Altahan
Created 19/01/2015 | Updated 7/11/2016
Version 1.2
Hello@exr.be
https://github.com/ei
-->

<SyntaxDefinition name="AutoHotkey" extensions=".ahk">

<Environment>
Expand Down
Loading

0 comments on commit fd60013

Please sign in to comment.