Skip to content

Commit

Permalink
Merge branch 'default-style-from-theme'
Browse files Browse the repository at this point in the history
  • Loading branch information
elvirbrk committed Jul 21, 2017
2 parents 22c2835 + e574084 commit d6a17dc
Show file tree
Hide file tree
Showing 18 changed files with 267 additions and 157 deletions.
3 changes: 3 additions & 0 deletions GenerateHighlightContent/HighLightSection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ public override bool IsReadOnly()
[ConfigurationProperty("ProcessName", DefaultValue = "highlight.exe")]
public string ProcessName { get { return base["ProcessName"].ToString(); } }

[ConfigurationProperty("ThemeFolder", DefaultValue = "themes")]
public string ThemeFolder { get { return base["ThemeFolder"].ToString(); } }

[ConfigurationProperty("GeneralArguments", IsRequired = true, IsDefaultCollection = true)]
public GeneralArgumentsCollection GeneralArguments
{
Expand Down
4 changes: 2 additions & 2 deletions GenerateHighlightContent/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// 您可以指定所有的值,也可以依照以下的方式,使用 '*' 將組建和修訂編號
// 指定為預設值:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("2.0.0.0")]
[assembly: AssemblyFileVersion("2.0.0.0")]
[assembly: AssemblyVersion("2.3.0.0")]
[assembly: AssemblyFileVersion("2.3.0.0")]
27 changes: 22 additions & 5 deletions NoteHighlightAddin/AddIn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -294,9 +294,24 @@ public XDocument InsertHighLightCode(string htmlContent, string[] position, High
XElement cell2 = new XElement(ns + "Cell");
cell2.Add(new XAttribute("shadingColor", colorString));

string defaultStyle = "";

var arrayLine = htmlContent.Split(new string[] { Environment.NewLine }, StringSplitOptions.None);
foreach (var item in arrayLine)
foreach (var it in arrayLine)
{
string item = it;

if(item.StartsWith("<pre"))
{
defaultStyle = item.Substring(0,item.IndexOf("<span"));
item = item.Substring(item.IndexOf("<span"));
}

if (item == "</pre>")
{
continue;
}

var itemNr = "";
var itemLine = "";
if (parameters.ShowLineNumber)
Expand All @@ -313,8 +328,9 @@ public XDocument InsertHighLightCode(string htmlContent, string[] position, High
itemLine = item;
}

string nr = string.Format(@"<body style=""font-family:{0}"">", GenerateHighlightContent.GenerateHighLight.Config.OutputArguments["Font"].Value) +
itemNr.Replace("&apos;", "'") + "</body>";
//string nr = string.Format(@"<body style=""font-family:{0}"">", GenerateHighlightContent.GenerateHighLight.Config.OutputArguments["Font"].Value) +
// itemNr.Replace("&apos;", "'") + "</body>";
string nr = defaultStyle + itemNr.Replace("&apos;", "'") + "</pre>";

cell1.Add(new XElement(ns + "OEChildren",
new XElement(ns + "OE",
Expand All @@ -326,8 +342,9 @@ public XDocument InsertHighLightCode(string htmlContent, string[] position, High
itemLine = item;
}
//string s = item.Replace(@"style=""", string.Format(@"style=""font-family:{0}; ", GenerateHighlightContent.GenerateHighLight.Config.OutputArguments["Font"].Value));
string s = string.Format(@"<body style=""font-family:{0}"">", GenerateHighlightContent.GenerateHighLight.Config.OutputArguments["Font"].Value) +
itemLine.Replace("&apos;", "'") + "</body>";
//string s = string.Format(@"<body style=""font-family:{0}"">", GenerateHighlightContent.GenerateHighLight.Config.OutputArguments["Font"].Value) +
// itemLine.Replace("&apos;", "'") + "</body>";
string s = defaultStyle + itemLine.Replace("&apos;", "'") + "</body>";

cell2.Add(new XElement(ns + "OEChildren",
new XElement(ns + "OE",
Expand Down
5 changes: 3 additions & 2 deletions NoteHighlightAddin/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<section name="NoteHighLightForm.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false"/>
</sectionGroup>
<section name="HighLightSection" type="GenerateHighlightContent.HighLightSection, GenerateHighlightContent, Version=2.0.0.0, Culture=neutral, PublicKeyToken=77d9ec1ac4fb0cdc"/>
<section name="HighLightSection" type="GenerateHighlightContent.HighLightSection, GenerateHighlightContent, Version=2.3.0.0, Culture=neutral, PublicKeyToken=77d9ec1ac4fb0cdc"/>
</configSections>
<userSettings>
<NoteHighLightForm.Properties.Settings>
Expand All @@ -23,12 +23,13 @@
</NoteHighLightForm.Properties.Settings>
</userSettings>
<!--highlight CLI options Document:http://www.andre-simon.de/doku/highlight/en/highlight.html -->
<HighLightSection FolderName="highlight" ProcessName="highlight.exe">
<HighLightSection FolderName="highlight" ProcessName="highlight.exe" ThemeFolder="themes">
<GeneralArguments>
<add Name="InputFile" Key="-i" Value="{inputFileName}"/>
<add Name="Syntax" Key="-S" Value="{codeType}"/>
<add Name="OutputFile" Key="-o" Value="{outputFileName}"/>
<add Name="InlineCss" Key="--inline-css" Value=""/>
<add Name="EnclosePre" Key="--enclose-pre" Value=""/>
</GeneralArguments>
<OutputArguments>
<add Name="Fragment" Key="-f" Value=""/>
Expand Down
95 changes: 41 additions & 54 deletions NoteHighlightAddin/MainForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 30 additions & 0 deletions NoteHighlightAddin/MainForm.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
using GenerateHighlightContent;
using Helper;
using ICSharpCode.TextEditor.Document;
using NoteHighLightForm;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
Expand Down Expand Up @@ -52,7 +55,34 @@ public MainForm(string codeType, string fileName)
_codeType = codeType;
_fileName = fileName;
InitializeComponent();
LoadThemes();

}

private void LoadThemes()
{
try
{
Configuration c = ConfigurationManager.OpenExeConfiguration(Assembly.GetCallingAssembly().Location);
HighLightSection section = c.GetSection("HighLightSection") as HighLightSection;

var workingDirectory = Path.Combine(ProcessHelper.GetDirectoryFromPath(Assembly.GetCallingAssembly().Location), section.FolderName, section.ThemeFolder);

string[] files = Directory.GetFiles(workingDirectory, "*.theme");

foreach (var item in files)
{
cbx_style.Items.Add(Path.GetFileNameWithoutExtension(item));
}
}
catch (Exception e)
{
MessageBox.Show("Exception from MainForm.LoadThemes:" + e.Message);
return;
}



}

#endregion
Expand Down
4 changes: 2 additions & 2 deletions NoteHighlightAddin/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("2.2.*")]
[assembly: AssemblyFileVersion("2.2.*")]
[assembly: AssemblyVersion("2.3.*")]
[assembly: AssemblyFileVersion("2.3.*")]
Loading

0 comments on commit d6a17dc

Please sign in to comment.