Skip to content

Commit 8d2ca8e

Browse files
committed
Merge branch 'fix-asian-character-spacing'
2 parents b12b4b5 + b0af636 commit 8d2ca8e

File tree

4 files changed

+33
-13
lines changed

4 files changed

+33
-13
lines changed

GenerateHighlightContent/HighLightSection.cs

+6
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ public override bool IsReadOnly()
2525
[ConfigurationProperty("LineNrReplaceCh", DefaultValue = "", IsRequired =false)]
2626
public string LineNrReplaceCh { get { return base["LineNrReplaceCh"].ToString(); } }
2727

28+
[ConfigurationProperty("AsianBeforeSpace", DefaultValue = "", IsRequired = false)]
29+
public string AsianBeforeSpace { get { return base["AsianBeforeSpace"].ToString(); } }
30+
31+
[ConfigurationProperty("AsianAfterSpace", DefaultValue = "", IsRequired = false)]
32+
public string AsianAfterSpace { get { return base["AsianAfterSpace"].ToString(); } }
33+
2834
[ConfigurationProperty("GeneralArguments", IsRequired = true, IsDefaultCollection = true)]
2935
public GeneralArgumentsCollection GeneralArguments
3036
{

GenerateHighlightContent/Properties/AssemblyInfo.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,5 @@
3232
// 您可以指定所有的值,也可以依照以下的方式,使用 '*' 將組建和修訂編號
3333
// 指定為預設值:
3434
// [assembly: AssemblyVersion("1.0.*")]
35-
[assembly: AssemblyVersion("2.5.0.0")]
36-
[assembly: AssemblyFileVersion("2.5.0.0")]
35+
[assembly: AssemblyVersion("2.6.0.0")]
36+
[assembly: AssemblyFileVersion("2.6.0.0")]

NoteHighlightAddin/AddIn.cs

+23-9
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ private void InsertHighLightCodeToCurrentSide(string fileName, HighLightParamete
264264
position = GetMousePointPosition(existingPageId);
265265
}
266266

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

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

423423
bool update = false;
424424
if (outline == null)
@@ -496,8 +496,10 @@ private XElement CreateOutline(string[] position, XElement children)
496496
return outline;
497497
}
498498

499-
private XElement PrepareFormatedContent(string htmlContent, HighLightParameter parameters, string lineNrReplacementCh, bool isInline)
499+
private XElement PrepareFormatedContent(string htmlContent, HighLightParameter parameters, bool isInline)
500500
{
501+
HighLightSection config = (new GenerateHighLight()).Config;
502+
501503
XElement children = new XElement(ns + "OEChildren");
502504

503505
XElement table = new XElement(ns + "Table");
@@ -575,19 +577,26 @@ private XElement PrepareFormatedContent(string htmlContent, HighLightParameter p
575577
//string nr = string.Format(@"<body style=""font-family:{0}"">", GenerateHighlightContent.GenerateHighLight.Config.OutputArguments["Font"].Value) +
576578
// itemNr.Replace("&apos;", "'") + "</body>";
577579
string nr = "";
578-
if (string.IsNullOrEmpty(lineNrReplacementCh))
580+
if (string.IsNullOrEmpty(config.LineNrReplaceCh))
579581
{
580582
nr = defaultStyle + itemNr.Replace("&apos;", "'") + "</pre>";
581583
}
582584
else
583585
{
584-
nr = defaultStyle + lineNrReplacementCh.PadLeft(5) + "</pre>";
586+
nr = defaultStyle + config.LineNrReplaceCh.PadLeft(5) + "</pre>";
585587
}
586588

587-
cell1.Add(new XElement(ns + "OEChildren",
588-
new XElement(ns + "OE",
589+
XElement oeElement = new XElement(ns + "OE",
589590
new XElement(ns + "T",
590-
new XCData(nr)))));
591+
new XCData(nr)));
592+
if (ContainsAsianCharacter(itemLine))
593+
{
594+
oeElement.Add(new XAttribute("spaceBefore", config.AsianBeforeSpace));
595+
oeElement.Add(new XAttribute("spaceAfter", config.AsianAfterSpace));
596+
}
597+
598+
cell1.Add(new XElement(ns + "OEChildren",
599+
oeElement ));
591600
}
592601
else
593602
{
@@ -617,5 +626,10 @@ private XElement PrepareFormatedContent(string htmlContent, HighLightParameter p
617626
table));
618627
return children;
619628
}
629+
630+
private bool ContainsAsianCharacter(string itemLine)
631+
{
632+
return itemLine.Any(c => (uint)c >= 0x4E00 && (uint)c <= 0x2FA1F);
633+
}
620634
}
621635
}

NoteHighlightAddin/App.config

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
55
<section name="NoteHighLightForm.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false"/>
66
</sectionGroup>
7-
<section name="HighLightSection" type="GenerateHighlightContent.HighLightSection, GenerateHighlightContent, Version=2.5.0.0, Culture=neutral, PublicKeyToken=77d9ec1ac4fb0cdc"/>
7+
<section name="HighLightSection" type="GenerateHighlightContent.HighLightSection, GenerateHighlightContent, Version=2.6.0.0, Culture=neutral, PublicKeyToken=77d9ec1ac4fb0cdc"/>
88
</configSections>
99
<userSettings>
1010
<NoteHighLightForm.Properties.Settings>
@@ -23,7 +23,7 @@
2323
</NoteHighLightForm.Properties.Settings>
2424
</userSettings>
2525
<!--highlight CLI options Document:http://www.andre-simon.de/doku/highlight/en/highlight.html -->
26-
<HighLightSection FolderName="highlight" ProcessName="highlight.exe" ThemeFolder="themes" LineNrReplaceCh="">
26+
<HighLightSection FolderName="highlight" ProcessName="highlight.exe" ThemeFolder="themes" LineNrReplaceCh="" AsianBeforeSpace="4.2" AsianAfterSpace="2.0">
2727
<GeneralArguments>
2828
<add Name="InputFile" Key="-i" Value="{inputFileName}"/>
2929
<add Name="Syntax" Key="-S" Value="{codeType}"/>

0 commit comments

Comments
 (0)