mirror of
https://github.com/discourse/discourse.git
synced 2024-11-26 19:00:32 -06:00
Automatically convert some quotes to blockquotes
This commit is contained in:
parent
1bbd1a94bb
commit
a7a7387da1
@ -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:
|
||||
|
||||
<blockquote>My fake plants died because I did not pretend to water them.</blockquote>
|
||||
|
||||
**/
|
||||
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]];
|
||||
}
|
||||
}
|
||||
});
|
@ -29,6 +29,14 @@ test("basic cooking", function() {
|
||||
cooked("brussel sproutes are *awful*.", "<p>brussel sproutes are <em>awful</em>.</p>", "it doesn't swallow periods.");
|
||||
});
|
||||
|
||||
test("Auto quoting", function() {
|
||||
cooked('"My fake plants died because I did not pretend to water them."',
|
||||
"<p><blockquote>My fake plants died because I did not pretend to water them.</blockquote></p>",
|
||||
"it converts single line quotes to blockquotes");
|
||||
cooked('"hello\nworld"', "<p>\"hello<br/>world\"</p>", "It doesn't convert multi line quotes");
|
||||
cooked('"hello "evil" trout"', '<p>"hello "evil" trout"</p>', "it doesn't format quotes in the middle of a line");
|
||||
});
|
||||
|
||||
test("Traditional Line Breaks", function() {
|
||||
var input = "1\n2\n3";
|
||||
cooked(input, "<p>1<br/>2<br/>3</p>", "automatically handles trivial newlines");
|
||||
|
Loading…
Reference in New Issue
Block a user