From 2cb5f1ebddcab4472292f302d327ba941b88edda Mon Sep 17 00:00:00 2001 From: Swee Date: Mon, 2 Sep 2024 15:43:20 -0700 Subject: [PATCH] Use Markdig --- Form1.cs | 68 ++----------------------------------------------- MintHTML.csproj | 11 +++++++- 2 files changed, 12 insertions(+), 67 deletions(-) diff --git a/Form1.cs b/Form1.cs index 90ed1b9..9f3fb10 100644 --- a/Form1.cs +++ b/Form1.cs @@ -1,5 +1,6 @@ using CefSharp; using CefSharp.WinForms; +using Markdig; using System.Linq.Expressions; namespace MintHTML @@ -175,72 +176,7 @@ border-width: 1px // 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; - } - } + htmlfile = Markdown.ToHtml(markfile); } // Custom functions end diff --git a/MintHTML.csproj b/MintHTML.csproj index 476e950..14fee09 100644 --- a/MintHTML.csproj +++ b/MintHTML.csproj @@ -18,7 +18,16 @@ - + + + + + + + + + + \ No newline at end of file