diff --git a/app/assets/javascripts/discourse/dialects/autoquote_dialect.js b/app/assets/javascripts/discourse/dialects/autoquote_dialect.js new file mode 100644 index 00000000000..e34bd3c2330 --- /dev/null +++ b/app/assets/javascripts/discourse/dialects/autoquote_dialect.js @@ -0,0 +1,23 @@ +/** + If a line contains a single quote, convert it to a blockquote. For example: + + "My fake plants died because I did not pretend to water them." + + Would be: + +
My fake plants died because I did not pretend to water them.+ +**/ +Discourse.Dialect.registerInline('"', function(str, match, prev) { + + // Make sure we're on a line boundary + var last = prev[prev.length - 1]; + if (typeof last === "string") { return; } + + if (str.length > 2 && str.charAt(0) === '"' && str.charAt(str.length-1) === '"') { + var inner = str.substr(1, str.length-2); + if (inner.indexOf('"') === -1 && inner.indexOf("\n") === -1) { + return [str.length, ['blockquote', inner]]; + } + } +}); \ No newline at end of file diff --git a/test/javascripts/lib/markdown_test.js b/test/javascripts/lib/markdown_test.js index a5af3ac1745..56348270a8a 100644 --- a/test/javascripts/lib/markdown_test.js +++ b/test/javascripts/lib/markdown_test.js @@ -29,6 +29,14 @@ test("basic cooking", function() { cooked("brussel sproutes are *awful*.", "
brussel sproutes are awful.
", "it doesn't swallow periods."); }); +test("Auto quoting", function() { + cooked('"My fake plants died because I did not pretend to water them."', + "My fake plants died because I did not pretend to water them.", + "it converts single line quotes to blockquotes"); + cooked('"hello\nworld"', "
\"hello
world\"
"hello "evil" trout"
', "it doesn't format quotes in the middle of a line"); +}); + test("Traditional Line Breaks", function() { var input = "1\n2\n3"; cooked(input, "1
2
3