创建简单的 Markdown 类
我目前正在开发一个集成了评论系统的系统,该系统在 Codeigniter 上运行,所以我希望创建一个 Markdown 库,但功能非常少。
我希望拥有的功能是
- 自动链接
- 粗体
*bold*
- 斜体
_italic_
实际上就是这样,发布数据将在进入标记之前通过Codeigniter的XSS类运行 所以我的问题
是最好的方法是什么,我应该使用一个库并禁用某些功能,我应该从头开始构建它,如果是这样,我应该如何构建班级以及我应该考虑哪些事情。
Im currently working on a system that has a comment system integrated, the system is running on Codeigniter so im looking to create a markdown library but with really minimal features.
The features im looking to have is
- Autolinking
- Bold
*bold*
- Italic
_italic_
And that's practically it, The post data will be run through Codeigniter's XSS Class before it goes to the mark down class
So my question is what's the best way to do this, should i be using a library out there and disabling certain features, should I build this from scratch, if so, how should i build the class and what things should I take into account.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我最近遇到了类似的情况,我想支持某种标记(BB、Markdown 等)。事实证明,大约 100 年来,BBCode 没有做任何事情,而且为它编写一个正则表达式解析器非常容易(至少对于格式良好的标记来说),所以我编写了一个非常简单的函数来做到这一点。
我的版本还包括图像、代码和颜色支持以及嵌套标签(
[b][i]粗体和斜体[/i][/b]
)。I was in a similar situation recently, where I wanted to support some kind of markup (BB, Markdown, etc). It turns out nothing has been done with BBCode for about 100 years, and it's dead easy to write a regex parser for it (for well-formed markup at least) so i wrote a really bare bones function to do just that.
My version also includes images, codes, and color support as well as nested tags (
[b][i]bold and italic[/i][/b]
).您可以从 PHP Markdown 类 开始吗?
或 CI 的那个。
如果我可以建议,您也可以尝试 MarkItUp 作为前端..
You can begin with PHP Markdown class ?
or the one for CI.
And If I may suggest, you can also try MarkItUp as front end..
对我来说,集成 Markdown 的最简单方法就是简单地
...以防万一有人 - 像我一样 - 再次偶然发现这个旧线程:)
For me the easiest way to integrate Markdown is by simply
...just in case someone - like me - stumbles upon this old thread again :)