Created
          October 11, 2019 00:39 
        
      - 
      
- 
        Save joe-oli/5dd6f7a53453d85acddc8a3bcc4e1384 to your computer and use it in GitHub Desktop. 
    html to markdown
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | /* install pandoc first; | |
| https://pandoc.org/installing.html | |
| https://github.com/jgm/pandoc/releases/tag/2.7.3 | |
| */ | |
| 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; | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment