So, I am using StackOverflow's own MarkdownSharp on my blog and I love it. I now want to implement a code button exactly like the one here on SO. I can't seem to find the javascript that fires when that button is clicked as it's all minified and not intrusive script. Anyone know the piece of code that it runs when it's clicked or ctrl+k is pressed?
Here is a screen shot just in case you don't know which button I'm referring to: http://www.codetunnel.com/codebutton.jpg
Thanks in advance!
UPDATE
I copied the source of SO's wmd.js file and unminified it. I then did some searching in notepad for certain key text. The variables in this file are impossible to understand, let alone read, but I did find this:
c.doCode = function (v, u) {
var w = /\S[ ]*$/.test(v.before);
var s = /^[ ]*\S/.test(v.after);
if ((!s && !w) || /\n/.test(v.selection)) {
v.before = v.before.replace(/[ ]{4}$/, function (x) {
v.selection = x + v.selection;
return ""
});
var t = 1;
var r = 1;
if (/\n(\t|[ ]{4,}).*\n$/.test(v.before)) {
t = 0
}
if (/^\n(\t|[ ]{4,})/.test(v.after)) {
r = 0
}
v.skipLines(t, r);
if (!v.selection) {
v.startTag = " ";
v.selection = "enter code here"
} else {
if (/^[ ]{0,3}\S/m.test(v.selection)) {
v.selection = v.selection.replace(/^/gm, " ")
} else {
v.selection = v.selection.replace(/^[ ]{4}/gm, "")
}
}
} else {
v.trimWhitespace();
v.findTags(/`/, /`/);
if (!v.startTag && !v.endTag) {
v.startTag = v.endTag = "`";
if (!v.selection) {
v.selection = "enter code here"
}
} else {
if (v.endTag && !v.startTag) {
v.before += v.endTag;
v.endTag = ""
} else {
v.startTag = v.endTag = ""
}
}
}
};
I found it when I realized that clicking the button without text highlighted inserted the text "enter code here" into the editor. I then searched for that text and found that snippet. Anyone able to make heads or tails?
I don't even want the full editor so much as I just want the code button. I could care less about the rest.