Skip to content

Commit

Permalink
Dark Mode enabled for clipboard mode
Browse files Browse the repository at this point in the history
  • Loading branch information
elvirbrk committed Feb 9, 2021
1 parent 9b47c3f commit 80a80bc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion NoteHighlightAddin/AddIn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ private void ShowForm()
}
}

MainForm form = new MainForm(tag, outFileName, selectedText, this.QuickStyle);
MainForm form = new MainForm(tag, outFileName, selectedText, this.QuickStyle, this.DarkMode);

System.Windows.Forms.Application.Run(form);
//}
Expand Down
15 changes: 14 additions & 1 deletion NoteHighlightAddin/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public partial class MainForm : Form
private string _fileName;

private HighLightParameter _parameters;
private bool _darkMode;

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

private bool _quickStyle;

public bool DarkMode { get { return _darkMode; } }

[System.Runtime.InteropServices.DllImport("user32.dll")]
private static extern bool SetForegroundWindow(IntPtr hWnd);

#endregion

#region -- Constructor --

public MainForm(string codeType, string fileName, string selectedText, bool quickStyle)
public MainForm(string codeType, string fileName, string selectedText, bool quickStyle, bool darkMode)
{
_codeType = codeType;
_fileName = fileName;
InitializeComponent();
LoadThemes();
txtCode.Text = selectedText;
_quickStyle = quickStyle;
_darkMode = darkMode;

if (_quickStyle)
{
Expand Down Expand Up @@ -192,6 +196,15 @@ private void InsertToClipboard(string outputFileName)
string byteOrderMarkUtf8 = Encoding.UTF8.GetString(Encoding.UTF8.GetPreamble());
line = line.Replace(byteOrderMarkUtf8, "");

if (line.StartsWith("<pre") && this.DarkMode)
{

//Remove background-color element so that text would render with correct contrast in dark mode
int bcIndex = line.IndexOf("background-color");
line = line.Remove(bcIndex, line.IndexOf(';', bcIndex) - bcIndex + 1);
}


if (!line.StartsWith("</pre>"))
{
line = line.Replace("\t", "&nbsp;&nbsp;&nbsp;&nbsp;").Replace("&apos;", "'") + "<br />";
Expand Down

0 comments on commit 80a80bc

Please sign in to comment.