Skip to content

Commit

Permalink
Merge branch 'fix-asian-character-spacing'
Browse files Browse the repository at this point in the history
  • Loading branch information
elvirbrk committed Feb 8, 2018
2 parents b12b4b5 + b0af636 commit 8d2ca8e
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 13 deletions.
6 changes: 6 additions & 0 deletions GenerateHighlightContent/HighLightSection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ public override bool IsReadOnly()
[ConfigurationProperty("LineNrReplaceCh", DefaultValue = "", IsRequired =false)]
public string LineNrReplaceCh { get { return base["LineNrReplaceCh"].ToString(); } }

[ConfigurationProperty("AsianBeforeSpace", DefaultValue = "", IsRequired = false)]
public string AsianBeforeSpace { get { return base["AsianBeforeSpace"].ToString(); } }

[ConfigurationProperty("AsianAfterSpace", DefaultValue = "", IsRequired = false)]
public string AsianAfterSpace { get { return base["AsianAfterSpace"].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.5.0.0")]
[assembly: AssemblyFileVersion("2.5.0.0")]
[assembly: AssemblyVersion("2.6.0.0")]
[assembly: AssemblyFileVersion("2.6.0.0")]
32 changes: 23 additions & 9 deletions NoteHighlightAddin/AddIn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ private void InsertHighLightCodeToCurrentSide(string fileName, HighLightParamete
position = GetMousePointPosition(existingPageId);
}

var page = InsertHighLightCode(htmlContent, position, parameters, outline, selectedTextFormated, (new GenerateHighLight()).Config.LineNrReplaceCh, IsSelectedTextInline(existingPageId));
var page = InsertHighLightCode(htmlContent, position, parameters, outline, selectedTextFormated, IsSelectedTextInline(existingPageId));
page.Root.SetAttributeValue("ID", existingPageId);

OneNoteApplication.UpdatePageContent(page.ToString(), DateTime.MinValue);
Expand Down Expand Up @@ -416,9 +416,9 @@ private bool IsSelectedTextInline(string pageID)
/// 產生 XML 插入至 OneNote
/// Generate XML Insert To OneNote
/// </summary>
public XDocument InsertHighLightCode(string htmlContent, string[] position, HighLightParameter parameters, XElement outline, bool selectedTextFormated, string lineNrReplacementCh, bool isInline)
public XDocument InsertHighLightCode(string htmlContent, string[] position, HighLightParameter parameters, XElement outline, bool selectedTextFormated, bool isInline)
{
XElement children = PrepareFormatedContent(htmlContent, parameters, lineNrReplacementCh, isInline);
XElement children = PrepareFormatedContent(htmlContent, parameters, isInline);

bool update = false;
if (outline == null)
Expand Down Expand Up @@ -496,8 +496,10 @@ private XElement CreateOutline(string[] position, XElement children)
return outline;
}

private XElement PrepareFormatedContent(string htmlContent, HighLightParameter parameters, string lineNrReplacementCh, bool isInline)
private XElement PrepareFormatedContent(string htmlContent, HighLightParameter parameters, bool isInline)
{
HighLightSection config = (new GenerateHighLight()).Config;

XElement children = new XElement(ns + "OEChildren");

XElement table = new XElement(ns + "Table");
Expand Down Expand Up @@ -575,19 +577,26 @@ private XElement PrepareFormatedContent(string htmlContent, HighLightParameter p
//string nr = string.Format(@"<body style=""font-family:{0}"">", GenerateHighlightContent.GenerateHighLight.Config.OutputArguments["Font"].Value) +
// itemNr.Replace("&apos;", "'") + "</body>";
string nr = "";
if (string.IsNullOrEmpty(lineNrReplacementCh))
if (string.IsNullOrEmpty(config.LineNrReplaceCh))
{
nr = defaultStyle + itemNr.Replace("&apos;", "'") + "</pre>";
}
else
{
nr = defaultStyle + lineNrReplacementCh.PadLeft(5) + "</pre>";
nr = defaultStyle + config.LineNrReplaceCh.PadLeft(5) + "</pre>";
}

cell1.Add(new XElement(ns + "OEChildren",
new XElement(ns + "OE",
XElement oeElement = new XElement(ns + "OE",
new XElement(ns + "T",
new XCData(nr)))));
new XCData(nr)));
if (ContainsAsianCharacter(itemLine))
{
oeElement.Add(new XAttribute("spaceBefore", config.AsianBeforeSpace));
oeElement.Add(new XAttribute("spaceAfter", config.AsianAfterSpace));
}

cell1.Add(new XElement(ns + "OEChildren",
oeElement ));
}
else
{
Expand Down Expand Up @@ -617,5 +626,10 @@ private XElement PrepareFormatedContent(string htmlContent, HighLightParameter p
table));
return children;
}

private bool ContainsAsianCharacter(string itemLine)
{
return itemLine.Any(c => (uint)c >= 0x4E00 && (uint)c <= 0x2FA1F);
}
}
}
4 changes: 2 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.5.0.0, Culture=neutral, PublicKeyToken=77d9ec1ac4fb0cdc"/>
<section name="HighLightSection" type="GenerateHighlightContent.HighLightSection, GenerateHighlightContent, Version=2.6.0.0, Culture=neutral, PublicKeyToken=77d9ec1ac4fb0cdc"/>
</configSections>
<userSettings>
<NoteHighLightForm.Properties.Settings>
Expand All @@ -23,7 +23,7 @@
</NoteHighLightForm.Properties.Settings>
</userSettings>
<!--highlight CLI options Document:http://www.andre-simon.de/doku/highlight/en/highlight.html -->
<HighLightSection FolderName="highlight" ProcessName="highlight.exe" ThemeFolder="themes" LineNrReplaceCh="">
<HighLightSection FolderName="highlight" ProcessName="highlight.exe" ThemeFolder="themes" LineNrReplaceCh="" AsianBeforeSpace="4.2" AsianAfterSpace="2.0">
<GeneralArguments>
<add Name="InputFile" Key="-i" Value="{inputFileName}"/>
<add Name="Syntax" Key="-S" Value="{codeType}"/>
Expand Down

0 comments on commit 8d2ca8e

Please sign in to comment.