这种情况不经常发生:为什么此JavaScript代码仅在Chrome中破裂?
-
29-09-2019 - |
题
我已经决定爱上了堆栈溢出中的Markdown编辑器。这是来自 showdown.js
来自约翰·弗雷泽(John Fraser)。我想在我的一个项目上使用此解析器,但是在分析了消息来源之后,我发现这对我的口味有点混乱。
因此,我着手修改JavaScript代码以满足我的需求,即:
- 摆脱所有全球变量,
- 将变量声明结合到单个
var
每个范围, - 将串联变为阵列加入,
- 其他各种调整旨在使缩小源较小。
除了一个小问题外,我的一切都很好,除了一个小问题: command.doList
功能在Chrome中很不错。我已经测试了所有内容,以便在Internet Explorer,Firefox和Safari中正常工作。我已经将问题隔离到以下几行:
// Get the item prefix - e.g. " 1. " for a numbered list, " - " for a bulleted
// list.
getItemPrefix = function () {
var prefix;
if (isNumberedList) {
// the `s` variable is just a string space.
prefix = [s, num, '. '].join('');
num++;
} else {
prefix = [s, bullet, s].join('');
}
return prefix;
};
// Fixes the prefixes of the other list items.
getPrefixedItem = function (itemText) {
// The numbering flag is unset when called by autoindent.
if (isNumberedList === undefined) {
isNumberedList = /^\s*\d/.test(itemText);
}
// Renumber/bullet the list element.
// THE FOLLOWING LINES COMMENTED OUT TO FIX A BUG.
//itemText = itemText.replace(/^[ ]{0,3}([\*\+\-]|\d+[.])\s/gm,
// function () { return getItemPrefix(); });
return itemText;
};
这两条评论的线在末端停止Chrome附近表现出色,但编号列表不再自动插入。一旦我取消关注线条,除Chrome外,所有主要浏览器都会开始正常工作。 (Chrome变得疯狂,并用额外的编号和子弹自动完成列表,当尝试使用无序列表时也会发生。)
问题显然不存在 这里 在堆栈溢出上,我希望这只是我的愚蠢监督。 (要么那个或堆栈溢出已更新并修复了错误。)
解决方案
你可以看一下 使固定 对于另一个WMD叉(第32行)。
其他提示
您不需要在方括号中反击 *+ - 应该吗?那可能就是Chrome遇到问题。
不隶属于 StackOverflow