降价 -> detab 正则表达式中的摊牌错误?
我正在查看 Gruber 的原始 Markdown 实现此处 和 Showdown 实现此处。
我正在比较每个中的 _Detab
函数。我给出以下每个字符串。
"Where\tis pancakes house?"
Perl 版本的测试和输出位于此处。长度为 26
个字符。
测试和输出的 JavaScript 版本位于此处。长度为 27
个字符。
123456789012345678901234567
Perl: Where is pancakes house?
JS: Where is pancakes house?
我犯了一个错误吗?这是一个错误,还是有其他目的?
I'm looking at Gruber's original Markdown implementation here and the Showdown implementation here.
I'm comparing the _Detab
function in each. I'm giving each the following string
"Where\tis pancakes house?"
The Perl version of the test and output is here. This is 26
characters long.
The JavaScript version of the test and output is here. This is 27
characters long.
123456789012345678901234567
Perl: Where is pancakes house?
JS: Where is pancakes house?
Have I made a mistake? Is it a bug, or is there some other purpose?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Showdown 的 detabber 中有几个错误。这就是为什么对于 Stack Overflow 的版本,我重写了它< /a>:
它正确地 detabs,如果我正确地回忆起我的测量结果,这与旧 IE 版本中的原始版本一样快(可能慢一点),并且在较新的浏览器中快得多。
请参阅 http://code.google.com/p/pagedown/wiki/PageDown 完整版本的 Showdown。
There are several bugs in Showdown's detabber. That's why for Stack Overflow's version, I have rewritten it:
It detabs correctly, and if I recall my measurements correctly, this is about as fast (maybe a little slower) as the original in older IE versions, and much faster in newer browsers.
See http://code.google.com/p/pagedown/wiki/PageDown for our full version of Showdown.
它看起来像是 Showdown 实现中的一个错误。 Markdown 使用 4 个空格制表符,因此在制表符转换为空格后,以制表符结尾的字符串长度应始终是 4 个字符的倍数。 Perl 版本将
"Where\t"
设为 8 个字符,但 JavaScript 版本将其设为 9 个字符。我怀疑该错误可能不会发生在行首的制表符上,这就是它们通常在 Markdown 中使用的方式,这可以解释为什么它没有被注意到。
It looks like a bug in the Showdown implementation. Markdown uses 4-space tabs, so a string ending in a tab should always be a multiple of 4 characters long after tabs are converted to spaces. The Perl version makes
"Where\t"
8 characters, but the JavaScript one makes it 9 characters.I suspect the bug may not occur with tabs at the beginning of a line, which is how they're normally used in Markdown, which would explain why it hasn't been noticed.