I think Pandoc should do the work. There are also some online converters out there. Or just use the js library Turndown, you can find examples online for it.
Thank Morpheus Pandoc was the solution!
I wanted to share a useful C# script for automating HTML to Markdown conversion using Pandoc within ZennoPoster. This script might come in handy for those who need to process HTML content and convert it to Markdown format automatically.
The script assumes that you have Pandoc installed on your system and accessible via the command line. Here’s the generalized code snippet:
// Replace 'YourInputVariable' with your actual input variable name containing HTML content
string htmlContent = project.Variables["YourInputVariable"].Value;
// Replace 'YourOutputVariable' with your actual output variable name where Markdown will be stored
string markdownOutputVariable = "YourOutputVariable";
// Path to Pandoc executable; adjust it according to your system
string pandocPath = @"C:\Program Files\Pandoc\pandoc.exe";
// Temporary file paths for storing intermediate and output files
string tempHtmlPath = project.Directory + @"\tempHtml.html";
string tempMarkdownPath = project.Directory + @"\tempMarkdown.md";
try
{
System.IO.File.WriteAllText(tempHtmlPath, htmlContent);
var processInfo = new System.Diagnostics.ProcessStartInfo(pandocPath, $"-f html -t markdown {tempHtmlPath} -o {tempMarkdownPath}")
{
CreateNoWindow = true,
UseShellExecute = false,
RedirectStandardOutput = true,
RedirectStandardError = true
};
using (var process = System.Diagnostics.Process.Start(processInfo))
{
process.WaitForExit();
}
string markdownContent = System.IO.File.ReadAllText(tempMarkdownPath);
project.Variables[markdownOutputVariable].Value = markdownContent;
}
catch (Exception ex)
{
project.SendInfoToLog("Error during Pandoc execution: " + ex.Message);
}
finally
{
System.IO.File.Delete(tempHtmlPath);
System.IO.File.Delete(tempMarkdownPath);
}
Make sure to replace the placeholder variable names with the actual ones you use in your ZennoPoster project. This script creates temporary files for the HTML input and Markdown output, which are deleted after the conversion process is completed.
This code was refined with the help of ChatGPT,to ensure it's clear and functional because i am not a dev,)
So for sure there is a way to simplify it but for the moment its work for me
I hope this helps anyone looking to streamline their content processing workflow in ZennoPoster. If you have any questions or improvements, feel free to chime in!