文本到HTML字符串解析la Reddit注释

时间:2012-04-05 18:37:23

标签: regex parsing reddit

过去几个小时我一直在浏览Reddit的源代码(https://github.com/reddit/reddit/wiki),我找不到我想要的东西:做平面文本到HTML转换他们的评论。

如果你不熟悉,它会在网站上有一个表格,告诉你如何格式化你的评论,并将你的纯文本转换成html链接,粗体,斜体等。

链接: http://www.reddit.com/r/technology/comments/rupkj/5000_artists_line_up_for_a_pirate_bay_promotion/c48sy1v (点击“回复”,然后点击“格式化帮助”,查看格式选项表。)

示例输入:

This should be: **bold** and **I'm also bold**

This should be: *italic* and *I'm italic too*

This should be: ~~strikethrough text~~

This should be: [A Link To Google.com](http://www.google.com)

This should be A list:
*This is a list
*Of differnet
*Things that I like

任何想法如何用正则表达式优雅地完成这个?

1 个答案:

答案 0 :(得分:1)

如评论中所述,您可能正在寻找Markdown