using CefSharp;
using CefSharp.WinForms;
using System.Linq.Expressions;
namespace MintHTML
{
public partial class Form1 : Form
{
string appdata = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
string markfile;
string htmlfile = "
Welcome to MintHTML
Open a markdown file and press \"Render preview\" to see the output here.
";
string csssuffix = @"
div{
font-family: monospace;
background-color: #F3F3F3;
border: solid;
border-width: 1px
}
";
string css;
// Custom functions
private void convert()
{
htmlfile = "";
using (StringReader reader = new StringReader(markfile))
{
string line;
while ((line = reader.ReadLine()) != null)
{
try
{
// Header 1
if (line[1..2] == "# ")
{
line = "" + line[1..] + "
";
}
// Header 2
else if (line[1..3] == "## ")
{
line = "" + line[1..] + "
";
}
// Header 3
else if (line[1..4] == "### ")
{
line = "" + line[1..] + "
";
}
// Header 4
else if (line[1..5] == "#### ")
{
line = "" + line[1..] + "
";
}
// Header 5
else if (line[1..6] == "##### ")
{
line = "" + line[1..] + "
";
}
// Header 6
else if (line[1..7] == "###### ")
{
line = "" + line[1..] + "
";
}
// Bullet point
else if (line[1..2] == "* ")
{
line = "- " + line[1..] + "
";
}
else if (line[1..2] == "- ")
{
line = "- " + line[1..] + "
";
} } catch{}
// Code block
if (line.Contains("`"))
{
line = "" + line[1..^1] + "
";
}
// Everything else (Possibly paragraph or HTML code)
else
{
line = line + "
";
}
htmlfile += line;
}
}
}
// Custom functions end
public Form1()
{
if (File.Exists(appdata + "/SweeZero/MintHTML/RootCache/lockfile"))
{
if (MessageBox.Show("There is another instance of MintHTML running. If there isn't, press Yes to try opening anyways.", "Cef Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
{
try
{
File.Delete(appdata + "/SweeZero/MintHTML/RootCache/lockfile");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Cef Error (fatal)", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
var settings = new CefSettings()
{
RootCachePath = appdata + "/SweeZero/MintHTML/RootCache",
};
InitializeComponent();
Cef.Initialize(settings);
css = @"