Cocoa 应用程序最简单的 Markdown 实现是什么?
我正在用 Objective-C 编写一个 Cocoa 应用程序,并且我希望能够合并 Markdown。用户以 Markdown 语法输入文本,单击“导出”按钮,程序将输出 XHTML 文件。
不过,似乎有很多选择。我可以使用 C/C++ 实现 之一,我可以将 Perl 脚本作为我的 Cocoa 应用程序的资源运行,我假设可以使用 Python 实现和 PyObjC 桥或 Perl实现和 CamelBones 或 PerlObjC 桥接器。最简单、最容易的解决方案是什么?我没有做任何复杂的事情,比如需要线程的实时渲染预览。
I'm writing a Cocoa application in Objective-C, and I would like to be able to incorporate Markdown. The user will enter text in Markdown syntax, click an "export" button, and the program will output a file of XHTML.
It seems like there are a lot of options, though. I could use one of the C/C++ implementations, I could run the Perl script as a resource to my Cocoa app, I assume could use the Python implementation and the PyObjC bridge or the Perl implementation and the CamelBones or PerlObjC bridges. What would be the simplest and easiest solution? I'm not doing anything complicated like a real-time rendered preview that would require threading.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
我查看了各种选项,最后发现了libsoldout,一个非常小的C非常容易集成的实现。你只需要在你的 Xcode 项目中包含 array.[ch]、buffer.[ch]、markdown.[ch] 和 renderers.[ch],然后你就可以将 NSString 从 markdown 转换为 HTML,如下所示:
I had a look at the various options, and in the end found libsoldout, a very small C implementation that's quite easy to integrate. You just need to include array.[ch], buffer.[ch], markdown.[ch], and renderers.[ch] in your Xcode project, then you can convert an NSString from markdown to HTML like so:
我刚刚在 iPad 应用程序中使用了 Sundown 实现,其中包括 SmartyPants 支持,并取得了巨大成功。花费了大约 15 分钟来构建一个测试应用程序。
假设您有一个 UITextView *textView (您设置了Delegate:self)和一个 UIWebView *webView 用于显示结果:
I just used the Sundown implementation which includes SmartyPants support, in an iPad app with great success. Took about 15 minutes to build a test app.
Assume you have a UITextView *textView (which you setDelegate:self) and also a UIWebView *webView in which to display the results:
您可能想查看我编写的开源应用程序 Macdown (或者也可以使用rentzsch的Markdownlive),这两个应用程序将此功能合并为唯一目的。
You may want to check out the open-source app Macdown which I wrote (or alternatively rentzsch's Markdownlive), which incorporate this functionality as the sole purpose of the two apps.
我发现使用这些基于 C 的库处理大量 Markdown 时存在问题。
这里有一个非常简单的 Obj-C 库对我有用:
https://github.com/mdiep/MMMarkdown
使用 MMMarkdown 的步骤:
构建 OS X 或 iOS 目标
复制
include/MMMarkdown.h
以及lib/libMMMarkdown-Mac.a
或lib/libMMMarkdown-iOS.a
到您的项目然后代码是:
I found problems with processing large amounts of markdown with these C-based libraries.
There's a very simple Obj-C library that worked for me here:
https://github.com/mdiep/MMMarkdown
Steps to use MMMarkdown:
Build the OS X or iOS target
Copy
include/MMMarkdown.h
and eitherlib/libMMMarkdown-Mac.a
orlib/libMMMarkdown-iOS.a
into your projectThen the code is:
我使用过peg-markdown,它比原来的perl快得多,并且可以处理一些语法扩展(如果启用)。
I've used peg-markdown, it's much faster than the original perl and can handle a few syntax extensions if you enable them.