标记文本解析器,如Objective-C中的stackoverflow格式器 [英] markup text parser like stackoverflow's formatter in Objective-C

查看:83
本文介绍了标记文本解析器,如Objective-C中的stackoverflow格式器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用Objective C创建标记编辑器.我需要以下功能:

I'm in the process of creating a markup editor in Objective C. I require the following functionality:

  • 识别块的分界,例如**block**
  • 删除开始和结束标签",例如下一个文本为**bold**"变为下一个文本为粗体"
  • 确定标记的文本在新上下文中的开始和结束位置:下一个文本为粗体"
  • Recognise the demarcation of a block eg **block**
  • Delete the start and end "tags" eg "The next text is **bold**" becomes "The next text is bold"
  • Determine the start and end positions of the marked-up text in the new context: "The next text is bold"

由于我将来可能会扩展语法(此刻将非常有限),因此自上而下进行解析非常重要,这样文本的开始和结束位置始终与结果文本相对应.因此,正则表达式可能不是最佳解决方案.

As I may expand the syntax in the future (it will be very limited at the moment), it is important that parsing be top-down such that the start and end positions of the text always correspond with the resulting text. For this reason regex may not be the best solution.

做到这一点的最佳方法是什么?

What is the best way to do this?

推荐答案

MarkDown Sharp,StackExchange网站上使用的markdown处理器为开源.可以在文件中 您可以查看他们的操作方式或将其移植到Objective-c.

MarkDown Sharp, the markdown processor used on the StackExchange websites, is open source. Take a look at the file, perhaps you can see how they do it or port it to objective-c.

也许更好,请看以下问题:

Perhaps better yet, take a look at this question: "What is the simplest implementation of Markdown for a Cocoa application?"

它链接到名为 MarkdownLive 的开源应用程序,该应用程序使用Markdown的C实现,称为Discount,并为此提供了一个Objective-C包装器.

It links to an open source application called MarkdownLive which uses a C implementation of Markdown called discount, and also provides an objective-c wrapper for it.

这篇关于标记文本解析器,如Objective-C中的stackoverflow格式器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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