Skip to content

Commit d3dc1bf

Browse files
committed
Everything is pretty much done.
1 parent 7dd54bf commit d3dc1bf

1 file changed

Lines changed: 50 additions & 48 deletions

File tree

wmd-base.js

Lines changed: 50 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1836,20 +1836,22 @@ Attacklab.wmdBase = function(){
18361836
}
18371837
};
18381838

1839-
wmd.Chunks.prototype.skipLines = function(_126, _127, _128){
1839+
1840+
wmd.Chunks.prototype.skipLines = function(nLinesBefore, nLinesAfter, findExtraNewlines){
18401841

1841-
if(_126 === undefined){
1842-
_126 = 1;
1842+
if(nLinesBefore === undefined){
1843+
nLinesBefore = 1;
18431844
}
18441845

1845-
if(_127 === undefined){
1846-
_127 = 1;
1846+
if(nLinesAfter === undefined){
1847+
nLinesAfter = 1;
18471848
}
18481849

1849-
_126++;
1850-
_127++;
1850+
nLinesBefore++;
1851+
nLinesAfter++;
18511852

1852-
var _129, _12a;
1853+
var regexText;
1854+
var replacementText;
18531855

18541856
this.selection = this.selection.replace(/(^\n*)/, "");
18551857
this.startTag = this.startTag + re.$1;
@@ -1862,32 +1864,32 @@ Attacklab.wmdBase = function(){
18621864

18631865
if(this.before){
18641866

1865-
_129 = _12a = "";
1867+
regexText = replacementText = "";
18661868

1867-
while(_126--){
1868-
_129 += "\\n?";
1869-
_12a += "\n";
1869+
while(nLinesBefore--){
1870+
regexText += "\\n?";
1871+
replacementText += "\n";
18701872
}
18711873

1872-
if(_128){
1873-
_129 = "\\n*";
1874+
if(findExtraNewlines){
1875+
regexText = "\\n*";
18741876
}
1875-
this.before = this.before.replace(new re(_129 + "$", ""), _12a);
1877+
this.before = this.before.replace(new re(regexText + "$", ""), replacementText);
18761878
}
18771879

18781880
if(this.after){
18791881

1880-
_129 = _12a = "";
1882+
regexText = replacementText = "";
18811883

1882-
while(_127--){
1883-
_129 += "\\n?";
1884-
_12a += "\n";
1884+
while(nLinesAfter--){
1885+
regexText += "\\n?";
1886+
replacementText += "\n";
18851887
}
1886-
if(_128){
1887-
_129 = "\\n*";
1888+
if(findExtraNewlines){
1889+
regexText = "\\n*";
18881890
}
18891891

1890-
this.after = this.after.replace(new re(_129, ""), _12a);
1892+
this.after = this.after.replace(new re(regexText, ""), replacementText);
18911893
}
18921894
};
18931895

@@ -1974,6 +1976,7 @@ Attacklab.wmdBase = function(){
19741976
chunk.after = markup + chunk.after;
19751977
};
19761978

1979+
// DONE
19771980
command.stripLinkDefs = function(text, defsToAdd){
19781981

19791982
text = text.replace(/^[ ]{0,3}\[(\d+)\]:[ \t]*\n?[ \t]*<?(\S+?)>?[ \t]*\n?[ \t]*(?:(\n*)["(](.+?)[")][ \t]*)?(?:\n+|$)/gm,
@@ -1993,50 +1996,48 @@ Attacklab.wmdBase = function(){
19931996
return text;
19941997
};
19951998

1999+
// DONE
19962000
command.addLinkDef = function(chunk, linkDef){
19972001

1998-
var refNumber = 0;
1999-
var defsToAdd = {};
2002+
var refNumber = 0; // The current reference number
2003+
var defsToAdd = {}; //
20002004

2005+
// Start with a clean slate by removing all previous link definitions.
20012006
chunk.before = command.stripLinkDefs(chunk.before, defsToAdd);
20022007
chunk.selection = command.stripLinkDefs(chunk.selection, defsToAdd);
20032008
chunk.after = command.stripLinkDefs(chunk.after, defsToAdd);
20042009

2005-
var _147 = "";
2010+
var defs = "";
20062011
var regex = /(\[(?:\[[^\]]*\]|[^\[\]])*\][ ]?(?:\n[ ]*)?\[)(\d+)(\])/g;
20072012

2008-
var _149 =
2009-
function(def){
2010-
refNumber++;
2011-
def = def.replace(/^[ ]{0,3}\[(\d+)\]:/, " ["+ refNumber +"]:");
2012-
_147 += "\n" + def;
2013-
};
2014-
2015-
var _14b =
2016-
2017-
function(_14c, _14d, id, end){
2013+
var addDefNumber = function(def){
2014+
refNumber++;
2015+
def = def.replace(/^[ ]{0,3}\[(\d+)\]:/, " ["+ refNumber +"]:");
2016+
defs += "\n" + def;
2017+
};
20182018

2019-
if(defsToAdd[id]){
2019+
var getLink = function(wholeMatch, link, id, end){
20202020

2021-
_149(defsToAdd[id]);
2022-
return _14d + refNumber + end;
2021+
if(defsToAdd[id]){
2022+
addDefNumber(defsToAdd[id]);
2023+
return link + refNumber + end;
20232024

2024-
}
2025-
return _14c;
2026-
};
2025+
}
2026+
return wholeMatch;
2027+
};
20272028

2028-
chunk.before = chunk.before.replace(regex, _14b);
2029+
chunk.before = chunk.before.replace(regex, getLink);
20292030

20302031
if(linkDef){
2031-
_149(linkDef);
2032+
addDefNumber(linkDef);
20322033
}
20332034
else{
2034-
chunk.selection = chunk.selection.replace(regex, _14b);
2035+
chunk.selection = chunk.selection.replace(regex, getLink);
20352036
}
20362037

2037-
var _150 = refNumber;
2038+
var refOut = refNumber;
20382039

2039-
chunk.after = chunk.after.replace(regex, _14b);
2040+
chunk.after = chunk.after.replace(regex, getLink);
20402041

20412042
if(chunk.after){
20422043
chunk.after = chunk.after.replace(/\n*$/, "");
@@ -2045,8 +2046,9 @@ Attacklab.wmdBase = function(){
20452046
chunk.selection = chunk.selection.replace(/\n*$/, "");
20462047
}
20472048

2048-
chunk.after += "\n\n" + _147;
2049-
return _150;
2049+
chunk.after += "\n\n" + defs;
2050+
2051+
return refOut;
20502052
};
20512053

20522054
// Done

0 commit comments

Comments
 (0)