Csharp/C#教程:将Html或RTF转换为Markdown或Wiki兼容语法?分享


将Html或RTF转换为Markdown或Wiki兼容语法?

是否有.net api可以做到这一点? 我看到Pandoc有一个独立的exe,我可以包装,但我不想,如果有东西已经存在。 有什么建议?

这是我用来包装pandoc的代码。 到目前为止,我还没有看到任何其他不错的方法。

public string Convert(string source) { string processName = @"C:Program FilesPandocbinpandoc.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; } 

我创建了一个库Html2Markdown 。 用法很简单。

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

其中html是您要转换的HTML的字符串表示forms。 我积极支持它并愉快地接受贡献。

上述就是C#学习教程:将Html或RTF转换为Markdown或Wiki兼容语法?分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)!

本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

ctvol管理联系方式QQ:251552304

本文章地址:https://www.ctvol.com/cdevelopment/1019042.html

(0)
上一篇 2022年1月4日
下一篇 2022年1月4日

精彩推荐