FEATURE: Autolinking to category using hashtags.

This commit is contained in:
Guo Xiang Tan
2015-12-28 14:28:16 +08:00
parent b8471177dc
commit c1dbf5c1c4
20 changed files with 365 additions and 14 deletions

View File

@@ -289,6 +289,46 @@ test("Mentions", function() {
"it allows mentions within HTML tags");
});
test("Category hashtags", () => {
var alwaysTrue = { categoryHashtagLookup: (function() { return ["category", "http://test.discourse.org/category-hashtag"]; }) };
cookedOptions("Check out #category-hashtag", alwaysTrue,
"<p>Check out <a class=\"hashtag\" href=\"http://test.discourse.org/category-hashtag\">#category-hashtag</a></p>",
"it translates category hashtag into links");
cooked("Check out #category-hashtag",
"<p>Check out <span class=\"hashtag\">#category-hashtag</span></p>",
"it does not translate category hashtag into links if it is not a valid category hashtag");
cookedOptions("[#category-hashtag](http://www.test.com)", alwaysTrue,
"<p><a href=\"http://www.test.com\">#category-hashtag</a></p>",
"it does not translate category hashtag within links");
cooked("```\n# #category-hashtag\n```",
"<p><pre><code class=\"lang-auto\"># #category-hashtag</code></pre></p>",
"it does not translate category hashtags to links in code blocks");
cooked("># #category-hashtag\n",
"<blockquote><h1><span class=\"hashtag\">#category-hashtag</span></h1></blockquote>",
"it handles category hashtags in simple quotes");
cooked("# #category-hashtag",
"<h1><span class=\"hashtag\">#category-hashtag</span></h1>",
"it works within ATX-style headers");
cooked("don't `#category-hashtag`",
"<p>don't <code>#category-hashtag</code></p>",
"it does not mention in an inline code block");
cooked("test #hashtag1/#hashtag2",
"<p>test <span class=\"hashtag\">#hashtag1</span>/#hashtag2</p>",
"it does not convert category hashtag not bounded by spaces");
cooked("<small>#category-hashtag</small>",
"<p><small><span class=\"hashtag\">#category-hashtag</span></small></p>",
"it works between HTML tags");
});
test("Heading", function() {
cooked("**Bold**\n----------", "<h2><strong>Bold</strong></h2>", "It will bold the heading");

View File

@@ -158,3 +158,27 @@ test("defaultHomepage", function() {
Discourse.SiteSettings.top_menu = "latest|top|hot";
equal(utils.defaultHomepage(), "latest", "default homepage is the first item in the top_menu site setting");
});
test("caretRowCol", () => {
var textarea = document.createElement('textarea');
const content = document.createTextNode("01234\n56789\n012345");
textarea.appendChild(content);
textarea.setAttribute('id', 'test');
document.body.appendChild(textarea);
const assertResult = (setCaretPos, expectedRowNum, expectedColNum) => {
Discourse.Utilities.setCaretPosition(textarea, setCaretPos);
const result = Discourse.Utilities.caretRowCol(textarea);
equal(result.rowNum, expectedRowNum, "returns the right row of the caret");
equal(result.colNum, expectedColNum, "returns the right col of the caret");
};
assertResult(0, 1, 0);
assertResult(5, 1, 5);
assertResult(6, 2, 0);
assertResult(11, 2, 5);
assertResult(14, 3, 2);
document.body.removeChild(textarea);
});