您将如何自动检测 Textile 与 Markdown?
我正在考虑同时支持 Textile 和 Markdown 当前项目。 我不想强迫用户选择其中之一。 有没有办法自动检测用户正在使用哪个? 你会怎么做呢? 我想找到/开发 JavaScript 和 PHP 解决方案,这样我就可以提供实时预览并在服务器端处理用户输入。
I'm considering supporting both Textile and Markdown on a current project. I would prefer not forcing users to choose one or the other. Is there a way to auto-detect which the user is using? How would you go about this? I'd like to find / develop both a JavaScript and a PHP solution so I can provide live previews as well as process the user input on the server-side.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
考虑到用户可能只在发布中使用一种特定的语法元素,因此您必须检查所有内容。 正在寻找“h1”。 显然只有当用户完全使用该元素时才有效。
对于标题之类的东西来说非常简单,但是考虑到 Markdown 将
*this*
格式设置为this
并且 Textile 会将其转换为< ;strong>这个
代替。 因此,您的语法结构不明确,会在每种语言中产生不同的结果。我建议根据用户的选择进行选择。 尝试找出您的用户(或您)通常喜欢哪种语法,为那些想要其他选择的人提供“使用 x 而不是 y”复选框。
Consider that users might only use one specific syntax element in a posting, so you'd have to check for everything. Looking for "h1." obviously only works if the user uses exactly that element.
It's pretty easy with things like headers, but consider that markdown formats
*this*
as<em>this</em>
and Textile will convert that to<strong>this</strong>
instead. So you'd have ambiguous syntax constructs that would yield different results in each language.I'd suggest going with a user choice. Try to find out what syntax is generally preferred by your users (or you), offer an "use x instead of y" checkbox for those who want the other choice.
这真的不应该那么难。 Markdown 不支持以下语法;
...所以您只需扫描它即可检查它是否是纺织品。 非常简单的正则表达式可帮助您在 PHP 代码中开始(扫描以 hX. 或 p. 开头的行):
您可能能够编写自己的正则表达式来扫描 Markdown。
This really shouldn't be that hard. Markdown does not support the following syntax;
... so you simply scan for that to check if it is textile. Very simple regular expression to get you started (scans for lines beginning with hX. or p.) in PHP code:
You will probably be able to write your own regex to scan for Markdown.
自动检测,我不知道,两者都是基于“自然”打字。
也许您可以要求用户选择一种格式,使用一对单选按钮或其他东西。
Auto-detection, I don't know, both are based on "natural" typing.
Perhaps you can ask the user to choose a format, with a pair of radio-buttons or something.