This commit is contained in:
Swee 2024-05-12 16:05:39 -07:00
parent 5cb82ecd5d
commit cc7798cd84
2 changed files with 213 additions and 130 deletions

205
Form1.Designer.cs generated
View file

@ -28,15 +28,10 @@
/// </summary> /// </summary>
private void InitializeComponent() private void InitializeComponent()
{ {
panel1 = new Panel();
groupBox3 = new GroupBox();
button2 = new Button();
textBox2 = new TextBox();
groupBox2 = new GroupBox();
button1 = new Button();
textBox1 = new TextBox();
menuStrip1 = new MenuStrip(); menuStrip1 = new MenuStrip();
fileToolStripMenuItem = new ToolStripMenuItem(); fileToolStripMenuItem = new ToolStripMenuItem();
openDevToolsToolStripMenuItem = new ToolStripMenuItem();
exitToolStripMenuItem = new ToolStripMenuItem();
helpToolStripMenuItem = new ToolStripMenuItem(); helpToolStripMenuItem = new ToolStripMenuItem();
aboutToolStripMenuItem = new ToolStripMenuItem(); aboutToolStripMenuItem = new ToolStripMenuItem();
renderToolStripMenuItem = new ToolStripMenuItem(); renderToolStripMenuItem = new ToolStripMenuItem();
@ -47,93 +42,18 @@
Opener = new OpenFileDialog(); Opener = new OpenFileDialog();
Saver = new SaveFileDialog(); Saver = new SaveFileDialog();
groupBox4 = new GroupBox(); groupBox4 = new GroupBox();
progressBar1 = new ProgressBar();
chromiumWebBrowser1 = new CefSharp.WinForms.ChromiumWebBrowser(); chromiumWebBrowser1 = new CefSharp.WinForms.ChromiumWebBrowser();
button4 = new Button(); button4 = new Button();
progressBar1 = new ProgressBar();
button3 = new Button(); button3 = new Button();
panel1.SuspendLayout(); groupBox3 = new GroupBox();
groupBox3.SuspendLayout(); button2 = new Button();
groupBox2.SuspendLayout(); textBox2 = new TextBox();
menuStrip1.SuspendLayout(); menuStrip1.SuspendLayout();
groupBox4.SuspendLayout(); groupBox4.SuspendLayout();
groupBox3.SuspendLayout();
SuspendLayout(); SuspendLayout();
// //
// panel1
//
panel1.Controls.Add(groupBox3);
panel1.Controls.Add(groupBox2);
panel1.Dock = DockStyle.Top;
panel1.Location = new Point(0, 24);
panel1.Name = "panel1";
panel1.Size = new Size(800, 67);
panel1.TabIndex = 1;
//
// groupBox3
//
groupBox3.Controls.Add(button2);
groupBox3.Controls.Add(textBox2);
groupBox3.Dock = DockStyle.Fill;
groupBox3.Location = new Point(401, 0);
groupBox3.Name = "groupBox3";
groupBox3.Size = new Size(399, 67);
groupBox3.TabIndex = 2;
groupBox3.TabStop = false;
groupBox3.Text = "Input file";
//
// button2
//
button2.Dock = DockStyle.Fill;
button2.FlatStyle = FlatStyle.System;
button2.Location = new Point(3, 42);
button2.Name = "button2";
button2.Size = new Size(393, 22);
button2.TabIndex = 3;
button2.Text = "Select file";
button2.UseVisualStyleBackColor = true;
button2.Click += button2_Click;
//
// textBox2
//
textBox2.Dock = DockStyle.Top;
textBox2.Location = new Point(3, 19);
textBox2.Name = "textBox2";
textBox2.PlaceholderText = "Type path or select file below. ";
textBox2.Size = new Size(393, 23);
textBox2.TabIndex = 2;
//
// groupBox2
//
groupBox2.Controls.Add(button1);
groupBox2.Controls.Add(textBox1);
groupBox2.Dock = DockStyle.Left;
groupBox2.Location = new Point(0, 0);
groupBox2.Name = "groupBox2";
groupBox2.Size = new Size(401, 67);
groupBox2.TabIndex = 1;
groupBox2.TabStop = false;
groupBox2.Text = "Output file";
//
// button1
//
button1.Dock = DockStyle.Fill;
button1.FlatStyle = FlatStyle.System;
button1.Location = new Point(3, 42);
button1.Name = "button1";
button1.Size = new Size(395, 22);
button1.TabIndex = 1;
button1.Text = "Select path";
button1.UseVisualStyleBackColor = true;
button1.Click += button1_Click;
//
// textBox1
//
textBox1.Dock = DockStyle.Top;
textBox1.Location = new Point(3, 19);
textBox1.Name = "textBox1";
textBox1.PlaceholderText = "Type path or select path below. ";
textBox1.Size = new Size(395, 23);
textBox1.TabIndex = 0;
//
// menuStrip1 // menuStrip1
// //
menuStrip1.Items.AddRange(new ToolStripItem[] { fileToolStripMenuItem, helpToolStripMenuItem, renderToolStripMenuItem }); menuStrip1.Items.AddRange(new ToolStripItem[] { fileToolStripMenuItem, helpToolStripMenuItem, renderToolStripMenuItem });
@ -146,10 +66,24 @@
// //
// fileToolStripMenuItem // fileToolStripMenuItem
// //
fileToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { openDevToolsToolStripMenuItem, exitToolStripMenuItem });
fileToolStripMenuItem.Name = "fileToolStripMenuItem"; fileToolStripMenuItem.Name = "fileToolStripMenuItem";
fileToolStripMenuItem.Size = new Size(37, 20); fileToolStripMenuItem.Size = new Size(37, 20);
fileToolStripMenuItem.Text = "File"; fileToolStripMenuItem.Text = "File";
// //
// openDevToolsToolStripMenuItem
//
openDevToolsToolStripMenuItem.Name = "openDevToolsToolStripMenuItem";
openDevToolsToolStripMenuItem.Size = new Size(154, 22);
openDevToolsToolStripMenuItem.Text = "Open DevTools";
openDevToolsToolStripMenuItem.Click += openDevToolsToolStripMenuItem_Click_1;
//
// exitToolStripMenuItem
//
exitToolStripMenuItem.Name = "exitToolStripMenuItem";
exitToolStripMenuItem.Size = new Size(154, 22);
exitToolStripMenuItem.Text = "Exit";
//
// helpToolStripMenuItem // helpToolStripMenuItem
// //
helpToolStripMenuItem.Alignment = ToolStripItemAlignment.Right; helpToolStripMenuItem.Alignment = ToolStripItemAlignment.Right;
@ -176,28 +110,31 @@
// //
fontFamilyToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { serifToolStripMenuItem, sansSerifToolStripMenuItem, forceMonospaceToolStripMenuItem }); fontFamilyToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { serifToolStripMenuItem, sansSerifToolStripMenuItem, forceMonospaceToolStripMenuItem });
fontFamilyToolStripMenuItem.Name = "fontFamilyToolStripMenuItem"; fontFamilyToolStripMenuItem.Name = "fontFamilyToolStripMenuItem";
fontFamilyToolStripMenuItem.Size = new Size(136, 22); fontFamilyToolStripMenuItem.Size = new Size(180, 22);
fontFamilyToolStripMenuItem.Text = "Font Family"; fontFamilyToolStripMenuItem.Text = "Font Family";
// //
// serifToolStripMenuItem // serifToolStripMenuItem
// //
serifToolStripMenuItem.Name = "serifToolStripMenuItem"; serifToolStripMenuItem.Name = "serifToolStripMenuItem";
serifToolStripMenuItem.Size = new Size(176, 22); serifToolStripMenuItem.Size = new Size(180, 22);
serifToolStripMenuItem.Text = "Serif"; serifToolStripMenuItem.Text = "Serif";
serifToolStripMenuItem.Click += serifToolStripMenuItem_Click;
// //
// sansSerifToolStripMenuItem // sansSerifToolStripMenuItem
// //
sansSerifToolStripMenuItem.Checked = true; sansSerifToolStripMenuItem.Checked = true;
sansSerifToolStripMenuItem.CheckState = CheckState.Checked; sansSerifToolStripMenuItem.CheckState = CheckState.Checked;
sansSerifToolStripMenuItem.Name = "sansSerifToolStripMenuItem"; sansSerifToolStripMenuItem.Name = "sansSerifToolStripMenuItem";
sansSerifToolStripMenuItem.Size = new Size(176, 22); sansSerifToolStripMenuItem.Size = new Size(180, 22);
sansSerifToolStripMenuItem.Text = "(Default) Sans serif"; sansSerifToolStripMenuItem.Text = "(Default) Sans serif";
sansSerifToolStripMenuItem.Click += sansSerifToolStripMenuItem_Click;
// //
// forceMonospaceToolStripMenuItem // forceMonospaceToolStripMenuItem
// //
forceMonospaceToolStripMenuItem.Name = "forceMonospaceToolStripMenuItem"; forceMonospaceToolStripMenuItem.Name = "forceMonospaceToolStripMenuItem";
forceMonospaceToolStripMenuItem.Size = new Size(176, 22); forceMonospaceToolStripMenuItem.Size = new Size(180, 22);
forceMonospaceToolStripMenuItem.Text = "(Force) Monospace"; forceMonospaceToolStripMenuItem.Text = "(Force) Monospace";
forceMonospaceToolStripMenuItem.Click += forceMonospaceToolStripMenuItem_Click;
// //
// Opener // Opener
// //
@ -219,10 +156,20 @@
groupBox4.Dock = DockStyle.Fill; groupBox4.Dock = DockStyle.Fill;
groupBox4.Location = new Point(0, 91); groupBox4.Location = new Point(0, 91);
groupBox4.Name = "groupBox4"; groupBox4.Name = "groupBox4";
groupBox4.Size = new Size(800, 401); groupBox4.Size = new Size(800, 378);
groupBox4.TabIndex = 3; groupBox4.TabIndex = 3;
groupBox4.TabStop = false; groupBox4.TabStop = false;
groupBox4.Text = "Preview"; groupBox4.Text = "Preview";
groupBox4.Enter += groupBox4_Enter;
//
// progressBar1
//
progressBar1.Dock = DockStyle.Top;
progressBar1.Location = new Point(3, 42);
progressBar1.Name = "progressBar1";
progressBar1.Size = new Size(794, 5);
progressBar1.Style = ProgressBarStyle.Marquee;
progressBar1.TabIndex = 2;
// //
// chromiumWebBrowser1 // chromiumWebBrowser1
// //
@ -230,13 +177,14 @@
chromiumWebBrowser1.Dock = DockStyle.Fill; chromiumWebBrowser1.Dock = DockStyle.Fill;
chromiumWebBrowser1.Location = new Point(3, 42); chromiumWebBrowser1.Location = new Point(3, 42);
chromiumWebBrowser1.Name = "chromiumWebBrowser1"; chromiumWebBrowser1.Name = "chromiumWebBrowser1";
chromiumWebBrowser1.Size = new Size(794, 356); chromiumWebBrowser1.Size = new Size(794, 333);
chromiumWebBrowser1.TabIndex = 0; chromiumWebBrowser1.TabIndex = 0;
chromiumWebBrowser1.LoadingStateChanged += chromiumWebBrowser1_LoadingStateChanged; chromiumWebBrowser1.LoadingStateChanged += chromiumWebBrowser1_LoadingStateChanged;
// //
// button4 // button4
// //
button4.Dock = DockStyle.Top; button4.Dock = DockStyle.Top;
button4.Enabled = false;
button4.FlatStyle = FlatStyle.System; button4.FlatStyle = FlatStyle.System;
button4.Location = new Point(3, 19); button4.Location = new Point(3, 19);
button4.Name = "button4"; button4.Name = "button4";
@ -244,21 +192,14 @@
button4.TabIndex = 1; button4.TabIndex = 1;
button4.Text = "Render preview"; button4.Text = "Render preview";
button4.UseVisualStyleBackColor = true; button4.UseVisualStyleBackColor = true;
// button4.Click += button4_Click;
// progressBar1
//
progressBar1.Dock = DockStyle.Top;
progressBar1.Location = new Point(3, 42);
progressBar1.Name = "progressBar1";
progressBar1.Size = new Size(794, 2);
progressBar1.Style = ProgressBarStyle.Marquee;
progressBar1.TabIndex = 2;
// //
// button3 // button3
// //
button3.BackColor = Color.Transparent; button3.BackColor = Color.Transparent;
button3.Dock = DockStyle.Bottom; button3.Dock = DockStyle.Bottom;
button3.FlatStyle = FlatStyle.Flat; button3.Enabled = false;
button3.FlatStyle = FlatStyle.System;
button3.Location = new Point(0, 469); button3.Location = new Point(0, 469);
button3.Name = "button3"; button3.Name = "button3";
button3.Size = new Size(800, 23); button3.Size = new Size(800, 23);
@ -267,44 +208,69 @@
button3.UseVisualStyleBackColor = false; button3.UseVisualStyleBackColor = false;
button3.Click += button3_Click; button3.Click += button3_Click;
// //
// groupBox3
//
groupBox3.Controls.Add(button2);
groupBox3.Controls.Add(textBox2);
groupBox3.Dock = DockStyle.Top;
groupBox3.Location = new Point(0, 24);
groupBox3.Name = "groupBox3";
groupBox3.Size = new Size(800, 67);
groupBox3.TabIndex = 2;
groupBox3.TabStop = false;
groupBox3.Text = "Input file";
//
// button2
//
button2.Dock = DockStyle.Fill;
button2.FlatStyle = FlatStyle.System;
button2.Location = new Point(3, 42);
button2.Name = "button2";
button2.Size = new Size(794, 22);
button2.TabIndex = 3;
button2.Text = "Select file";
button2.UseVisualStyleBackColor = true;
button2.Click += button2_Click;
//
// textBox2
//
textBox2.Dock = DockStyle.Top;
textBox2.Location = new Point(3, 19);
textBox2.Name = "textBox2";
textBox2.PlaceholderText = "Type path or select file below. ";
textBox2.Size = new Size(794, 23);
textBox2.TabIndex = 2;
textBox2.TextChanged += textBox2_TextChanged;
//
// Form1 // Form1
// //
AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font; AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(800, 492); ClientSize = new Size(800, 492);
Controls.Add(button3);
Controls.Add(groupBox4); Controls.Add(groupBox4);
Controls.Add(panel1); Controls.Add(groupBox3);
Controls.Add(button3);
Controls.Add(menuStrip1); Controls.Add(menuStrip1);
MainMenuStrip = menuStrip1; MainMenuStrip = menuStrip1;
MinimumSize = new Size(633, 531); MinimumSize = new Size(633, 531);
Name = "Form1"; Name = "Form1";
Text = "MintHTML"; Text = "MintHTML";
FormClosed += Form1_FormClosed;
Load += Form1_Load; Load += Form1_Load;
panel1.ResumeLayout(false);
groupBox3.ResumeLayout(false);
groupBox3.PerformLayout();
groupBox2.ResumeLayout(false);
groupBox2.PerformLayout();
menuStrip1.ResumeLayout(false); menuStrip1.ResumeLayout(false);
menuStrip1.PerformLayout(); menuStrip1.PerformLayout();
groupBox4.ResumeLayout(false); groupBox4.ResumeLayout(false);
groupBox3.ResumeLayout(false);
groupBox3.PerformLayout();
ResumeLayout(false); ResumeLayout(false);
PerformLayout(); PerformLayout();
} }
#endregion #endregion
private Panel panel1;
private MenuStrip menuStrip1; private MenuStrip menuStrip1;
private ToolStripMenuItem fileToolStripMenuItem; private ToolStripMenuItem fileToolStripMenuItem;
private ToolStripMenuItem helpToolStripMenuItem; private ToolStripMenuItem helpToolStripMenuItem;
private ToolStripMenuItem aboutToolStripMenuItem; private ToolStripMenuItem aboutToolStripMenuItem;
private GroupBox groupBox2;
private TextBox textBox1;
private Button button1;
private GroupBox groupBox3;
private Button button2;
private TextBox textBox2;
private OpenFileDialog Opener; private OpenFileDialog Opener;
private SaveFileDialog Saver; private SaveFileDialog Saver;
private GroupBox groupBox4; private GroupBox groupBox4;
@ -317,5 +283,10 @@
private ToolStripMenuItem sansSerifToolStripMenuItem; private ToolStripMenuItem sansSerifToolStripMenuItem;
private ToolStripMenuItem forceMonospaceToolStripMenuItem; private ToolStripMenuItem forceMonospaceToolStripMenuItem;
private ProgressBar progressBar1; private ProgressBar progressBar1;
private ToolStripMenuItem openDevToolsToolStripMenuItem;
private ToolStripMenuItem exitToolStripMenuItem;
private GroupBox groupBox3;
private Button button2;
private TextBox textBox2;
} }
} }

134
Form1.cs
View file

@ -5,6 +5,44 @@ namespace MintHTML
{ {
public partial class Form1 : Form public partial class Form1 : Form
{ {
string markfile;
string htmlfile = "<h1>Welcome to MintHTML</h1><p>Open a markdown file and press \"Render preview\" to see the output here.</p>";
string csssuffix = @"
div{
font-family: monospace;
background-color: #F3F3F3;
border: solid;
border-width: 1px
}
</style>";
string css;
// Custom functions
private void convert()
{
htmlfile = "";
using (StringReader reader = new StringReader(markfile))
{
string line;
while ((line = reader.ReadLine()) != null)
{
if (line.Contains("# "))
{
line = "<h1>" + line[1..] + "</h1>";
}
else if (line.Contains("`"))
{
line = "<div>" + line[1..^1] + "</div>";
}
else
{
line = line + "<br>";
}
htmlfile += line;
}
}
}
// Custom functions end
public Form1() public Form1()
{ {
InitializeComponent(); InitializeComponent();
@ -19,28 +57,102 @@ namespace MintHTML
{ {
Opener.ShowDialog(); Opener.ShowDialog();
textBox2.Text = Opener.FileName; textBox2.Text = Opener.FileName;
} if (textBox2.Text.Length > 0)
private void button1_Click(object sender, EventArgs e)
{ {
Saver.ShowDialog(); markfile = File.ReadAllText(textBox2.Text);
textBox1.Text = Saver.FileName; convert();
chromiumWebBrowser1.LoadHtml(css + htmlfile);
} }
private void chromiumWebBrowser1_LoadingStateChanged(object sender, CefSharp.LoadingStateChangedEventArgs e)
{
} }
private void Form1_Load(object sender, EventArgs e) private void Form1_Load(object sender, EventArgs e)
{ {
chromiumWebBrowser1.LoadHtml("<style>html{font-family: sans-serif}</style><h1>MintHTML</h1><p>Open a markdown file and press \"Render preview\" to see the output here.</p>"); css = @"<style>
html{
font-family: sans-serif
}" + csssuffix;
chromiumWebBrowser1.LoadHtml(css + htmlfile);
} }
private void button3_Click(object sender, EventArgs e) private void button3_Click(object sender, EventArgs e)
{ {
} }
private void Form1_FormClosed(object sender, FormClosedEventArgs e)
{
Cef.Shutdown();
}
private void chromiumWebBrowser1_LoadingStateChanged(object sender, LoadingStateChangedEventArgs e)
{
this.Invoke(new Action(() => progressBar1.Visible = chromiumWebBrowser1.IsLoading));
}
private void openDevToolsToolStripMenuItem_Click_1(object sender, EventArgs e)
{
chromiumWebBrowser1.ShowDevTools();
}
private void button4_Click(object sender, EventArgs e)
{
try
{
markfile = File.ReadAllText(textBox2.Text);
convert();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
chromiumWebBrowser1.LoadHtml(css + htmlfile);
}
private void textBox2_TextChanged(object sender, EventArgs e)
{
button3.Enabled = textBox2.Text.Length > 0;
button4.Enabled = textBox2.Text.Length > 0;
}
private void serifToolStripMenuItem_Click(object sender, EventArgs e)
{
css = @"<style>
html{
font-family: serif
}" + csssuffix;
sansSerifToolStripMenuItem.Checked = false;
forceMonospaceToolStripMenuItem.Checked = false;
serifToolStripMenuItem.Checked = true;
chromiumWebBrowser1.LoadHtml(css + htmlfile);
}
private void groupBox4_Enter(object sender, EventArgs e)
{
}
private void sansSerifToolStripMenuItem_Click(object sender, EventArgs e)
{
css = @"<style>
html{
font-family: sans-serif
}" + csssuffix;
sansSerifToolStripMenuItem.Checked = true;
forceMonospaceToolStripMenuItem.Checked = false;
serifToolStripMenuItem.Checked = false;
chromiumWebBrowser1.LoadHtml(css + htmlfile);
}
private void forceMonospaceToolStripMenuItem_Click(object sender, EventArgs e)
{
css = @"<style>
html{
font-family: monospace
}" + csssuffix;
sansSerifToolStripMenuItem.Checked = false;
forceMonospaceToolStripMenuItem.Checked = true;
serifToolStripMenuItem.Checked = false;
chromiumWebBrowser1.LoadHtml(css + htmlfile);
}
} }
} }