将 Html 或 RTF 转换为 Markdown 或 Wiki 兼容语法? [英] Convert Html or RTF to Markdown or Wiki Compatible syntax?

查看:29
本文介绍了将 Html 或 RTF 转换为 Markdown 或 Wiki 兼容语法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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?

推荐答案

这是我用来包装 的代码潘多克.不幸的是,到目前为止,我还没有看到任何其他像样的方法.

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;
}

这篇关于将 Html 或 RTF 转换为 Markdown 或 Wiki 兼容语法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆