projects
/
pagedown
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (from parent 1:
340f857
)
remove a few RegExp.$1 usages. Chrome still doesn't like them (http://meta.stackoverf...
author
balpha
<devnull@localhost>
Fri, 5 Aug 2011 13:36:52 +0000
(15:36 +0200)
committer
balpha
<devnull@localhost>
Fri, 5 Aug 2011 13:36:52 +0000
(15:36 +0200)
Markdown.Editor.js
patch
|
blob
|
history
diff --git
a/Markdown.Editor.js
b/Markdown.Editor.js
index
ba2e1b7
..
5e839a9
100644
(file)
--- a/
Markdown.Editor.js
+++ b/
Markdown.Editor.js
@@
-148,18
+148,15
@@
//
\r
// If remove is true, the whitespace disappears.
\r
Chunks.prototype.trimWhitespace = function (remove) {
\r
//
\r
// If remove is true, the whitespace disappears.
\r
Chunks.prototype.trimWhitespace = function (remove) {
\r
-
\r
- this.selection = this.selection.replace(/^(\s*)/, "");
\r
-
\r
- if (!remove) {
\r
- this.before += re.$1;
\r
- }
\r
-
\r
- this.selection = this.selection.replace(/(\s*)$/, "");
\r
-
\r
- if (!remove) {
\r
- this.after = re.$1 + this.after;
\r
+ var beforeReplacer, afterReplacer, that = this;
\r
+ if (remove) {
\r
+ beforeReplacer = afterReplacer = "";
\r
+ } else {
\r
+ beforeReplacer = function (s) { that.before += s; return ""; }
\r
+ afterReplacer = function (s) { that.after = s + that.after; return ""; }
\r
}
\r
}
\r
+
\r
+ this.selection = this.selection.replace(/^(\s*)/, beforeReplacer).replace(/(\s*)$/, afterReplacer);
\r
};
\r
\r
\r
};
\r
\r
\r
@@
-1520,11
+1517,9
@@
chunk.selection = chunk.selection.replace(/\n{2,}/g, "\n");
\r
\r
// Look for stars before and after. Is the chunk already marked up?
\r
chunk.selection = chunk.selection.replace(/\n{2,}/g, "\n");
\r
\r
// Look for stars before and after. Is the chunk already marked up?
\r
- chunk.before.search(/(\**$)/);
\r
- var starsBefore = re.$1;
\r
-
\r
- chunk.after.search(/(^\**)/);
\r
- var starsAfter = re.$1;
\r
+ // note that these regex matches cannot fail
\r
+ var starsBefore = /(\**$)/.exec(chunk.before)[0];
\r
+ var starsAfter = /(^\**)/.exec(chunk.after)[0];
\r
\r
var prevStars = Math.min(starsBefore.length, starsAfter.length);
\r
\r
\r
var prevStars = Math.min(starsBefore.length, starsAfter.length);
\r
\r
@@
-1792,7
+1787,7
@@
if (chunk.before) {
\r
var lines = chunk.before.replace(/\n$/, "").split("\n");
\r
var inChain = false;
\r
if (chunk.before) {
\r
var lines = chunk.before.replace(/\n$/, "").split("\n");
\r
var inChain = false;
\r
- for (var i = 0; i < lines.length; i++
) {
\r
+ for (var i = 0; i < lines.length; i++) {
\r
var good = false;
\r
line = lines[i];
\r
inChain = inChain && line.length > 0; // c) any non-empty line continues the chain
\r
var good = false;
\r
line = lines[i];
\r
inChain = inChain && line.length > 0; // c) any non-empty line continues the chain
\r