Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert Html or RTF to Markdown or Wiki Compatible syntax? [closed]

Is there a .net api that can do this? I saw Pandoc has a standalone exe that I could wrap but I'd rather not if there is something already out there. Any suggestions?

like image 287
Rob Avatar asked May 25 '11 05:05

Rob


People also ask

Can Pandoc convert HTML to markdown?

Pandoc can convert between numerous markup and word processing formats, including, but not limited to, various flavors of Markdown, HTML, LaTeX and Word docx.

How do I convert HTML to Wikipedia?

Click on the "Convert HTML to wiki markup" button (if it doesn't work, use the "Fetch from URL" option or another HTML converter). Copy/paste the resulting text into the edit box of the wiki page you have created. Preview the page and check that everything looks correct.

What is HTML to markdown?

HTML to Markdown Converter helps to convert HTML (HyperText Markup Language) to Markdown markup language and helps to save and share the Markdown code. Markdown is getting popular to create blog using Hugo framework, also to create Readme file in github.


2 Answers

Here's the code I used to wrap pandoc. I haven't seen any other decent methods so far unfortunately.

public string Convert(string source)
{
    string processName = @"C:\Program Files\Pandoc\bin\pandoc.exe";
    string args = String.Format(@"-r html -t mediawiki");

    ProcessStartInfo psi = new ProcessStartInfo(processName, args);

    psi.RedirectStandardOutput = true;
    psi.RedirectStandardInput = true;

    Process p = new Process();
    p.StartInfo = psi;
    psi.UseShellExecute = false;
    p.Start();

    string outputString = "";
    byte[] inputBuffer = Encoding.UTF8.GetBytes(source);
    p.StandardInput.BaseStream.Write(inputBuffer, 0, inputBuffer.Length);
    p.StandardInput.Close();

    p.WaitForExit(2000);
    using (System.IO.StreamReader sr = new System.IO.StreamReader(
                                           p.StandardOutput.BaseStream))
    {

        outputString = sr.ReadToEnd();
    }

    return outputString;
}
like image 111
Rob Avatar answered Sep 28 '22 13:09

Rob


I have created a library Html2Markdown. Usage is very simple.

var markdown = new Converter().Convert(html);

Where html is the string representation of the HTML you wish to convert. I actively support it and happily accept contributions.

like image 32
baynezy Avatar answered Sep 28 '22 11:09

baynezy