4

I am developing my down blog engine based on file system storage, very much interested to use Markdown for keeping file and storage compressed. I am able to figure out the way when user submit the content using Markdown editor (that's I am using now while writing the code!!) but also would like to enhance the feature by allowing Window Live Writer and Metablog API thus it is very important for me to transform vice versa (HTML -> Markup).

I am not able to find any example or specific code snippet that can help me. Advise would be much appreciated.

Reference: http://code.google.com/p/markdownsharp/

I am using above repository.

Cheer! Nilay.

Nilay Parikh
  • 328
  • 3
  • 14

1 Answers1

2

You can use Pandoc with a wrapper as shown in the answer to this question:

Convert Html or RTF to Markdown or Wiki Compatible syntax?

Edit:

Here's a slightly modified (to dispose of process resources) version of the function that @Rob wrote:

private string Convert(string source) {
    string processName = @"C:\Program Files (x86)\Pandoc\bin\pandoc.exe";
    string args = "-r html -t markdown";

    ProcessStartInfo psi = new ProcessStartInfo(processName, args) {
        RedirectStandardOutput = true,
        RedirectStandardInput = true,
        CreateNoWindow = true,
        UseShellExecute = false
    };

    var outputString = "";

    using (var p = new Process()) {
        p.StartInfo = psi;
        p.Start();

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

        using (var sr = new StreamReader(p.StandardOutput.BaseStream)) {
            outputString = sr.ReadToEnd();
        }
    }

    return outputString;
}

I'm not sure how practical this is but it works.

Community
  • 1
  • 1
gram
  • 2,772
  • 20
  • 24
  • Thanks, but I'm more over looking for web or possibly server side script, pinvoke is very dangerous. I've almost found a solution that's using XSLT though it has some limitations but I'm happy to accept them. Once I am confident over my code, I'll publish it here. – Nilay Parikh Jun 27 '11 at 16:55