javascript 对决,markdown 无法正确解析
我有一个令人困惑的问题。
我有两个文件,都运行摊牌。然而,似乎只有一个文件能够正确解析。
事情是这样的。
文件 1 通过 PHP 和 AJAX 运行。
文件 2 通过 AJAX 请求获取。处理ajax请求的文件包含此代码。
这是 ajax
如您所见,将详细信息显示到屏幕上的 jQuery 代码完全相同来自变量和 JSON 字符串,而不是来自数据库的直接字符串。
现在,文件 #1 无法正确解析 markdown,而文件 2 则可以...
这是文件 #1 和 #2 的屏幕截图
文件 #1
文件 #2
知道可能是什么原因造成的吗?另外,有什么修复的想法吗?
I have a confusing problem.
I have two files, both that run showdown. However, it seems that only one file parses correctly.
Here's the deal.
File 1 is run through PHP and AJAX.
File 2 is grabbed via an AJAX request. The file that processes the ajax request contains this code.
Here is the ajax
As you can see, the jQuery code that puts the details onto the screen are exactly the same apart from the variables and the JSON string instead of a direct string from the database.
Now file #1 doesn't parse the markdown correctly, where file two does...
Here is a screenshot of files #1 and #2
File #1
File #2
Any idea on what could possibly be causing this? Also, any ideas on a fix?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
也许是因为在文件 2 中你有:
它忽略了第一个 preg_replace()。您想要:
您已在文件 1 中正确实现了该功能。这可能意味着文件 1 的行为是正确的,而文件 2 的行为实际上是不正确的,具体取决于您看待它的方式。
编辑
回答您的评论:
替换(在文件1中):
用
这是否达到了预期的效果?
Maybe it is because in file 2 you have:
Which ignores the first preg_replace(). You want:
Which you have correctly implemented in file 1. This could mean that file 1's behaviour is correct and file 2's behaviour is actually incorrect, depending on the way you look at it.
EDIT
To answer your comment:
Replace (in file 1):
With
Does that achieve the desired effect?
好吧,
看起来是文件中换行符的解析...但是我们已经将其从
更改为,因为这导致降价解析错误地双重转义的问题,
所以它现在读取
哪个工作正常并且有效地解析两个文件
Ok,
So it seems it was the parsing of the line breaks in the file... However we have changed it from
as this is causing the issue of the markdown parsing incorrectly to double escaped
so it now reads
which works correctly and parses both files efficiently