Skip to content

Commit 4c44d51

Browse files
committed
Merge branch 'v3.7_dark_mode' into master
2 parents 8388f2a + 80a80bc commit 4c44d51

File tree

354 files changed

+14400
-7711
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

354 files changed

+14400
-7711
lines changed

NoteHighlightAddin/AddIn.cs

+25-1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ protected Application OneNoteApplication
4848

4949
private bool QuickStyle { get; set; }
5050

51+
private bool DarkMode { get; set; }
52+
5153
public AddIn()
5254
{
5355
}
@@ -151,6 +153,20 @@ public void cbQuickStyle_OnAction(IRibbonControl control, bool isPressed)
151153
NoteHighlightForm.Properties.Settings.Default.Save();
152154
}
153155

156+
157+
public bool cbDarkMode_GetPressed(IRibbonControl control)
158+
{
159+
this.DarkMode = NoteHighlightForm.Properties.Settings.Default.DarkMode;
160+
return this.DarkMode;
161+
}
162+
163+
public void cbDarkMOde_OnAction(IRibbonControl control, bool isPressed)
164+
{
165+
this.DarkMode = isPressed;
166+
NoteHighlightForm.Properties.Settings.Default.DarkMode = this.DarkMode;
167+
NoteHighlightForm.Properties.Settings.Default.Save();
168+
}
169+
154170
//public async Task AddInButtonClicked(IRibbonControl control)
155171
public void AddInButtonClicked(IRibbonControl control)
156172
{
@@ -204,7 +220,7 @@ private void ShowForm()
204220
}
205221
}
206222

207-
MainForm form = new MainForm(tag, outFileName, selectedText, this.QuickStyle);
223+
MainForm form = new MainForm(tag, outFileName, selectedText, this.QuickStyle, this.DarkMode);
208224

209225
System.Windows.Forms.Application.Run(form);
210226
//}
@@ -608,6 +624,14 @@ private XElement PrepareFormatedContent(string htmlContent, HighLightParameter p
608624
defaultStyle = item.Substring(0, item.IndexOf(">") + 1);
609625
//Sets language to Latin to disable spell check
610626
defaultStyle = defaultStyle.Insert(defaultStyle.Length - 1, " lang=la");
627+
628+
if (this.DarkMode)
629+
{
630+
//Remove background-color element so that text would render with correct contrast in dark mode
631+
int bcIndex = defaultStyle.IndexOf("background-color");
632+
defaultStyle = defaultStyle.Remove(bcIndex, defaultStyle.IndexOf(';', bcIndex) - bcIndex +1);
633+
}
634+
611635
item = item.Substring(item.IndexOf(">") + 1);
612636
}
613637

NoteHighlightAddin/App.config

+3
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
</setting>
2323
<setting name="QuickStyle" serializeAs="String">
2424
<value>False</value>
25+
</setting>
26+
<setting name="DarkMode" serializeAs="String">
27+
<value>True</value>
2528
</setting>
2629
<setting name="Font" serializeAs="String">
2730
<value>Courier New</value>

NoteHighlightAddin/HtmlFragment.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public static void CopyToClipboard(string htmlFragment, string title, Uri source
2626

2727
string header =
2828
@"Format:HTML Format
29-
Version:1.0
29+
Version:0.9
3030
StartHTML:<<<<<<<1
3131
EndHTML:<<<<<<<2
3232
StartFragment:<<<<<<<3
@@ -54,10 +54,10 @@ public static void CopyToClipboard(string htmlFragment, string title, Uri source
5454
int fragmentStart = sb.Length;
5555

5656
sb.Append(htmlFragment);
57-
int fragmentEnd = sb.Length;
57+
int fragmentEnd = Encoding.UTF8.GetBytes(sb.ToString()).Length;
5858

5959
sb.Append(post);
60-
int endHTML = sb.Length;
60+
int endHTML = Encoding.UTF8.GetBytes(sb.ToString()).Length;
6161

6262
// Backpatch offsets
6363
sb.Replace("<<<<<<<1", To8DigitString(startHTML));

NoteHighlightAddin/MainForm.cs

+14-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public partial class MainForm : Form
2929
private string _fileName;
3030

3131
private HighLightParameter _parameters;
32+
private bool _darkMode;
3233

3334
//要HighLight的Code
3435
private string CodeContent { get { return this.txtCode.Text; } }
@@ -48,21 +49,24 @@ public partial class MainForm : Form
4849

4950
private bool _quickStyle;
5051

52+
public bool DarkMode { get { return _darkMode; } }
53+
5154
[System.Runtime.InteropServices.DllImport("user32.dll")]
5255
private static extern bool SetForegroundWindow(IntPtr hWnd);
5356

5457
#endregion
5558

5659
#region -- Constructor --
5760

58-
public MainForm(string codeType, string fileName, string selectedText, bool quickStyle)
61+
public MainForm(string codeType, string fileName, string selectedText, bool quickStyle, bool darkMode)
5962
{
6063
_codeType = codeType;
6164
_fileName = fileName;
6265
InitializeComponent();
6366
LoadThemes();
6467
txtCode.Text = selectedText;
6568
_quickStyle = quickStyle;
69+
_darkMode = darkMode;
6670

6771
if (_quickStyle)
6872
{
@@ -192,6 +196,15 @@ private void InsertToClipboard(string outputFileName)
192196
string byteOrderMarkUtf8 = Encoding.UTF8.GetString(Encoding.UTF8.GetPreamble());
193197
line = line.Replace(byteOrderMarkUtf8, "");
194198

199+
if (line.StartsWith("<pre") && this.DarkMode)
200+
{
201+
202+
//Remove background-color element so that text would render with correct contrast in dark mode
203+
int bcIndex = line.IndexOf("background-color");
204+
line = line.Remove(bcIndex, line.IndexOf(';', bcIndex) - bcIndex + 1);
205+
}
206+
207+
195208
if (!line.StartsWith("</pre>"))
196209
{
197210
line = line.Replace("\t", "&nbsp;&nbsp;&nbsp;&nbsp;").Replace("&apos;", "'") + "<br />";

0 commit comments

Comments
 (0)