【发布时间】:2015-11-12 03:14:47
【问题描述】:
有没有 .net api 可以做到这一点?我看到Pandoc 有一个我可以打包的独立 exe,但如果那里已经有东西我宁愿不要。有什么建议么?
【问题讨论】:
有没有 .net api 可以做到这一点?我看到Pandoc 有一个我可以打包的独立 exe,但如果那里已经有东西我宁愿不要。有什么建议么?
【问题讨论】:
这是我用来包装pandoc 的代码。不幸的是,到目前为止我还没有看到任何其他像样的方法。
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;
}
【讨论】:
string args = String.Format(@"-r html -t mediawiki"); 而不仅仅是string args = "-r html -t mediawiki";?我缺少 String.Format 的任何预期副作用吗?
我创建了一个库Html2Markdown。用法很简单。
var markdown = new Converter().Convert(html);
html 是您希望转换的 HTML 的字符串表示形式。我积极支持它并乐于接受贡献。
【讨论】: