Better blockquote button in Markdown editor when non-traditional markdown linebreaks

are enabled.
This commit is contained in:
Robin Ward 2013-10-28 12:44:10 -04:00
parent 098673ecc0
commit 26a8156f08
2 changed files with 47 additions and 1 deletions

View File

@ -10,5 +10,29 @@ window.PagedownCustom = {
return Discourse.__container__.lookup('controller:composer').send('importQuote');
}
}
]
],
customActions: {
"doBlockquote": function(chunk, postProcessing, oldDoBlockquote) {
// When traditional linebreaks are set, use the default Pagedown implementation
if (Discourse.SiteSettings.traditional_markdown_linebreaks) {
return oldDoBlockquote.call(this, chunk, postProcessing);
}
// Our custom blockquote for non-traditional markdown linebreaks
var result = [];
chunk.selection.split(/\n/).forEach(function (line) {
var newLine = "";
if (line.indexOf("> ") === 0) {
newLine += line.substr(2);
} else {
if (/\S/.test(line)) { newLine += "> " + line; }
}
result.push(newLine)
})
chunk.selection = result.join("\n");
}
}
};

View File

@ -18,6 +18,17 @@
// ]
// };
//
// To extend actions:
//
// window.PagedownCustom = {
// customActions: {
// "doBlockquote": function(chunk, postProcessing, oldDoBlockquote) {
// console.log('custom blockquote called!');
// return oldDoBlockquote.call(this, chunk, postProcessing);
// }
// }
// };
(function () {
@ -1470,6 +1481,17 @@
}
function bindCommand(method) {
if (typeof PagedownCustom != "undefined" && PagedownCustom.customActions) {
var custom = PagedownCustom.customActions[method];
if (custom) {
return function() {
var args = Array.prototype.slice.call(arguments);
args.push(commandManager[method]);
return custom.apply(commandManager, args);
};
}
}
if (typeof method === "string")
method = commandManager[method];
return function () { method.apply(commandManager, arguments); }