" +
+ " " +
+ "";
+
// The default text that appears in the dialog input box when entering
// links.
var imageDefaultText = "http://";
@@ -53,8 +106,8 @@ Attacklab.wmdBase = function(){
var pastePollInterval = 100;
// The link and title for the help button
- var helpLink = "http://wmd-editor.com/";
- var helpHoverTitle = "WMD website";
+ var helpLink = "http://daringfireball.net/projects/markdown/syntax";
+ var helpHoverTitle = "MarkDown Syntax";
var helpTarget = "_blank";
// -------------------------------------------------------------------
@@ -206,7 +259,11 @@ Attacklab.wmdBase = function(){
var dialog; // The dialog box.
var background; // The background beind the dialog box.
var input; // The text box where you enter the hyperlink.
-
+ var type = 0;
+ // The dialog box type(0: Link, 1: Image)
+ if(arguments.length == 4){
+ type = arguments[3];
+ }
if (defaultInputText === undefined) {
defaultInputText = "";
@@ -321,6 +378,7 @@ Attacklab.wmdBase = function(){
// The input text box
input = doc.createElement("input");
+ input.id = "image-url";
input.type = "text";
input.value = defaultInputText;
style = input.style;
@@ -328,6 +386,12 @@ Attacklab.wmdBase = function(){
style.width = "80%";
style.marginLeft = style.marginRight = "auto";
form.appendChild(input);
+
+ // The upload file input
+ var upload = doc.createElement("div");
+ upload.innerHTML = uploadImageHTML;
+ upload.style.padding = "5px";
+ form.appendChild(upload);
// The ok button
var okButton = doc.createElement("input");
@@ -1065,6 +1129,21 @@ Attacklab.wmdBase = function(){
setupButton(redoButton, true);
buttonRow.appendChild(redoButton);
+ var helpButton = document.createElement("li");
+ helpButton.className = "wmd-button";
+ helpButton.id = "wmd-help-button";
+ helpButton.XShift = "-240px";
+ helpButton.isHelp = true;
+
+ var helpAnchor = document.createElement("a");
+ helpAnchor.href = helpLink;
+ helpAnchor.target = helpTarget
+ helpAnchor.title = helpHoverTitle;
+ helpButton.appendChild(helpAnchor);
+
+ setupButton(helpButton, true);
+ buttonRow.appendChild(helpButton);
+
setUndoRedoButtonStates();
}
@@ -1097,14 +1176,6 @@ Attacklab.wmdBase = function(){
var keyCode = key.charCode || key.keyCode;
var keyCodeStr = String.fromCharCode(keyCode).toLowerCase();
- // Bugfix for messed up DEL and .
- if (keyCode === 46) {
- keyCodeStr = "";
- }
- if (keyCode === 190) {
- keyCodeStr = ".";
- }
-
switch(keyCodeStr) {
case "b":
doClick(document.getElementById("wmd-bold-button"));
@@ -1274,7 +1345,7 @@ Attacklab.wmdBase = function(){
this.text = inputArea.value;
}
- };
+ }
// Sets the selected text in the input box after we've performed an
// operation.
@@ -1489,6 +1560,10 @@ Attacklab.wmdBase = function(){
var regexText;
var replacementText;
+
+ if (navigator.userAgent.match(/Chrome/)) {
+ "X".match(/()./)
+ }
this.selection = this.selection.replace(/(^\n*)/, "");
this.startTag = this.startTag + re.$1;
@@ -1566,7 +1641,7 @@ Attacklab.wmdBase = function(){
// insertText: If you just click the button without highlighting text, this gets inserted
command.doBorI = function(chunk, nStars, insertText){
- // Get rid of whitespace and fixup newlines.
+ // Get rid of whitespace and fix up newlines.
chunk.trimWhitespace();
chunk.selection = chunk.selection.replace(/\n{2,}/g, "\n");
@@ -1635,7 +1710,9 @@ Attacklab.wmdBase = function(){
chunk.after = command.stripLinkDefs(chunk.after, defsToAdd);
var defs = "";
- var regex = /(\[(?:\[[^\]]*\]|[^\[\]])*\][ ]?(?:\n[ ]*)?\[)(\d+)(\])/g;
+ var regex = /(\[)((?:\[[^\]]*\]|[^\[\]])*)(\][ ]?(?:\n[ ]*)?\[)(\d+)(\])/g;
+
+
var addDefNumber = function(def){
refNumber++;
@@ -1643,11 +1720,16 @@ Attacklab.wmdBase = function(){
defs += "\n" + def;
};
- var getLink = function(wholeMatch, link, id, end){
-
+ // note that
+ // a) the recursive call to getLink cannot go infinite, because by definition
+ // of regex, inner is always a proper substring of wholeMatch, and
+ // b) more than one level of nesting is neither supported by the regex
+ // nor making a lot of sense (the only use case for nesting is a linked image)
+ var getLink = function (wholeMatch, before, inner, afterInner, id, end) {
+ inner = inner.replace(regex, getLink);
if (defsToAdd[id]) {
addDefNumber(defsToAdd[id]);
- return link + refNumber + end;
+ return before + inner + afterInner + refNumber + end;
}
return wholeMatch;
@@ -2030,19 +2112,74 @@ Attacklab.wmdBase = function(){
chunk.selection = chunk.selection.replace(/^(\s|>)+$/ ,"");
chunk.selection = chunk.selection || defaultText;
+ // The original code uses a regular expression to find out how much of the
+ // text *directly before* the selection already was a blockquote:
+ /*
if(chunk.before){
chunk.before = chunk.before.replace(/\n?$/,"\n");
}
+ chunk.before = chunk.before.replace(/(((\n|^)(\n[ \t]*)*>(.+\n)*.*)+(\n[ \t]*)*$)/,
+ function (totalMatch) {
+ chunk.startTag = totalMatch;
+ return "";
+ });
+ */
+ // This comes down to:
+ // Go backwards as many lines a possible, such that each line
+ // a) starts with ">", or
+ // b) is almost empty, except for whitespace, or
+ // c) is preceeded by an unbroken chain of non-empty lines
+ // leading up to a line that starts with ">" and at least one more character
+ // and in addition
+ // d) at least one line fulfills a)
+ //
+ // Since this is essentially a backwards-moving regex, it's susceptible to
+ // catstrophic backtracking and can cause the browser to hang;
+ // see e.g. http://meta.stackoverflow.com/questions/9807.
+ //
+ // Hence we replaced this by a simple state machine that just goes through the
+ // lines and checks for a), b), and c).
+
+ var match = "";
+ var leftOver = "";
+ if (chunk.before) {
+ var lines = chunk.before.replace(/\n$/, "").split("\n");
+ var inChain = false;
+ for (var i in lines) {
+ var good = false;
+ line = lines[i];
+ inChain = inChain && line.length > 0; // c) any non-empty line continues the chain
+ if (/^>/.test(line)) { // a)
+ good = true;
+ if (!inChain && line.length > 1) // c) any line that starts with ">" and has at least one more character starts the chain
+ inChain = true;
+ } else if (/^[ \t]*$/.test(line)) { // b)
+ good = true;
+ } else {
+ good = inChain; // c) the line is not empty and does not start with ">", so it matches if and only if we're in the chain
+ }
+ if (good) {
+ match += line + "\n";
+ } else {
+ leftOver += match + line;
+ match = "\n";
+ }
+ }
+ if (!/(^|\n)>/.test(match)) { // d)
+ leftOver += match;
+ match = "";
+ }
+ }
+
+ chunk.startTag = match;
+ chunk.before = leftOver;
+
+ // end of change
+
if(chunk.after){
chunk.after = chunk.after.replace(/^\n?/,"\n");
}
- chunk.before = chunk.before.replace(/(((\n|^)(\n[ \t]*)*>(.+\n)*.*)+(\n[ \t]*)*$)/,
- function(totalMatch){
- chunk.startTag = totalMatch;
- return "";
- });
-
chunk.after = chunk.after.replace(/^(((\n|^)(\n[ \t]*)*>(.+\n)*.*)+(\n[ \t]*)*)/,
function(totalMatch){
chunk.endTag = totalMatch;
@@ -2331,7 +2468,7 @@ Attacklab.wmdBase = function(){
Attacklab.wmd_env = {};
Attacklab.account_options = {};
-Attacklab.wmd_defaults = {version:1, output:"Markdown", lineLength:40, delayLoad:false};
+Attacklab.wmd_defaults = {version:1, output:"HTML", lineLength:40, delayLoad:false};
if(!Attacklab.wmd)
{