Commits

Ville Saalo committed d922b48

#31 / #58: Creole / Markdown.

Linkify changeset ids.

  • Participants
  • Parent commits 089b4a5
  • Branches default

Comments (0)

Files changed (2)

src/com/saibotd/bitbeaker/MarkupHelper.java

 import android.text.Html;
 import android.text.Spanned;
 import android.text.TextUtils;
+import android.util.Log;
 import android.util.Patterns;
 
 import com.petebevin.markdown.MarkdownProcessor;
 	}
 	
 	private static String getBitbucketLinksLinkified(String input, String owner, String slug) {
+		Log.d("MH", "1: "+input);
 		input = input.replaceAll("#(\\d+)", "<a href=\"https://bitbucket.org/"+owner+"/"+slug+"/issue/$1\">#$1</a>");
+		Log.d("MH", "2: "+input);
 		input = input.replaceAll("(?<!\\w)@([\\w\\d_]{1,30})", "<a href=\"https://bitbucket.org/$1\">@$1</a>"); // username up to 30 chars: letters, numbers, underscores
-		//input = input.replaceAll("([a-fA-F0-9]{7,40})", "<a href=\"https://bitbucket.org/"+owner+"/"+slug+"/changeset/$1\">$1</a>");// changeset 7-40 hex chars
+		Log.d("MH", "3: "+input);
+		input = input.replaceAll("([a-fA-F0-9]{7,40})(?!([a-fA-F0-9\"]|</a>))", "<a href=\"https://bitbucket.org/"+owner+"/"+slug+"/changeset/$1\">$1</a>");// changeset 7-40 hex chars
+		Log.d("MH", "4: "+input);
 		return input;
 	}
 	

src/com/saibotd/bitbeaker/tests/MarkupHelperTest.java

 	}
 	
 	public void test_decorate_changeset_links() {
+		assertEquals("Basic changeset link test case fails!", 
+				"<a href=\"https://bitbucket.org/user/repo/changeset/0123456789abcdef\">0123456789abcdef</a>", 
+				MarkupHelper.decorateCreole("0123456789abcdef", "user", "repo"));
+		
+		assertEquals("Another basic changeset link test case fails!", 
+				"<a href=\"https://bitbucket.org/user/repo/changeset/8334708\">8334708</a>", 
+				MarkupHelper.decorateCreole("8334708", "user", "repo"));
+		
 		assertEquals("Basic changeset link at the end of the string test case fails!", 
 				"It was done in <a href=\"https://bitbucket.org/user/repo/changeset/abcd12345\">abcd12345</a>", 
 				MarkupHelper.decorateCreole("It was done in abcd12345", "user", "repo"));
 				MarkupHelper.decorateCreole("I dit it in 1234cafe.", "user", "repo"));
 		
 		assertEquals("Basic changeset link in parenthesis fails!", 
-				"The changes (<a href=\"https://bitbucket.org/user/repo/changeset/D3ADB33F\">DEADB33F</a>) are superb!", 
+				"The changes (<a href=\"https://bitbucket.org/user/repo/changeset/DEADB33F\">DEADB33F</a>) are superb!", 
 				MarkupHelper.decorateCreole("The changes (DEADB33F) are superb!", "user", "repo"));
 	}
 	
+	public void test_decorate_several_changeset_links() {
+		assertEquals("Test with two plain changeset ids fails!",
+				"<a href=\"https://bitbucket.org/saibotd/bitbeaker/changeset/083ab57537\">083ab57537</a>\n" +
+				"<a href=\"https://bitbucket.org/saibotd/bitbeaker/changeset/102be9c\">102be9c</a>",
+				MarkupHelper.decorateCreole("083ab57537\n" +
+		                                    "102be9c", "saibotd", "bitbeaker"));
+		
+		assertEquals("Test with two already HTML changeset ids fails!",
+				"<a href=\"https://bitbucket.org/saibotd/bitbeaker/changeset/083ab57537\">https://bitbucket.org/saibotd/bitbeaker/changeset/083ab57537</a>\n" +
+				"<a href=\"https://bitbucket.org/saibotd/bitbeaker/changeset/102be9c\">https://bitbucket.org/saibotd/bitbeaker/changeset/102be9c</a>",
+				MarkupHelper.decorateCreole("https://bitbucket.org/saibotd/bitbeaker/changeset/083ab57537\n" +
+		                                    "https://bitbucket.org/saibotd/bitbeaker/changeset/102be9c", "saibotd", "bitbeaker"));
+		
+		assertEquals("Test with two different kind of changeset ids fails!",
+				"Testing:\n\n* <a href=\"https://bitbucket.org/saibotd/bitbeaker/changeset/083ab57537\">https://bitbucket.org/saibotd/bitbeaker/changeset/083ab57537</a>" +
+				          "\n* <a href=\"https://bitbucket.org/saibotd/bitbeaker/changeset/102be9c\">102be9c</a>",
+				MarkupHelper.decorateCreole("Testing:\n\n* https://bitbucket.org/saibotd/bitbeaker/changeset/083ab57537" +
+		                                    "\n* 102be9c", "saibotd", "bitbeaker"));
+	}
+	
 	public void test_decorate_changeset_links_not_being_too_aggressive() {
 		assertEquals("The decoration method messed up a link that was already in HTML format!", 
 				"Changeset <a href=\"https://bitbucket.org/user/repo/changeset/abc123def456\">abc123def456</a> rocks!",