summaryrefslogtreecommitdiffstats
path: root/modules/markup
diff options
context:
space:
mode:
authorRinat <paladin2012gnu@gmail.com>2019-09-06 03:39:54 +0300
committertechknowlogick <techknowlogick@gitea.io>2019-09-05 20:39:54 -0400
commitb660a732ae283d863636ead9cc1a365ce1c0edc1 (patch)
treed4ed1987a44e5f1a0c1c23068f0aaa2c238e32c4 /modules/markup
parent79c8bc0e51db9ef1579b72d0510cac9aaded06db (diff)
downloadgitea-b660a732ae283d863636ead9cc1a365ce1c0edc1.tar.gz
gitea-b660a732ae283d863636ead9cc1a365ce1c0edc1.zip
feat: highlight issue references with : (#8101)
* feat: highlight issue references with : e.g. #1287: my commit msg e.g. ABC-1234: my commit msg * ref: update model regex to consistent with issueNumericPattern * test: check highlight issue with : in commits messages
Diffstat (limited to 'modules/markup')
-rw-r--r--modules/markup/html.go4
-rw-r--r--modules/markup/html_internal_test.go7
2 files changed, 9 insertions, 2 deletions
diff --git a/modules/markup/html.go b/modules/markup/html.go
index 1ffb7da24c..ff5b1a76e6 100644
--- a/modules/markup/html.go
+++ b/modules/markup/html.go
@@ -40,9 +40,9 @@ var (
mentionPattern = regexp.MustCompile(`(?:\s|^|\(|\[)(@[0-9a-zA-Z-_\.]+)(?:\s|$|\)|\])`)
// issueNumericPattern matches string that references to a numeric issue, e.g. #1287
- issueNumericPattern = regexp.MustCompile(`(?:\s|^|\(|\[)(#[0-9]+)(?:\s|$|\)|\]|\.(\s|$))`)
+ issueNumericPattern = regexp.MustCompile(`(?:\s|^|\(|\[)(#[0-9]+)(?:\s|$|\)|\]|:|\.(\s|$))`)
// issueAlphanumericPattern matches string that references to an alphanumeric issue, e.g. ABC-1234
- issueAlphanumericPattern = regexp.MustCompile(`(?:\s|^|\(|\[)([A-Z]{1,10}-[1-9][0-9]*)(?:\s|$|\)|\]|\.(\s|$))`)
+ issueAlphanumericPattern = regexp.MustCompile(`(?:\s|^|\(|\[)([A-Z]{1,10}-[1-9][0-9]*)(?:\s|$|\)|\]|:|\.(\s|$))`)
// crossReferenceIssueNumericPattern matches string that references a numeric issue in a different repository
// e.g. gogits/gogs#12345
crossReferenceIssueNumericPattern = regexp.MustCompile(`(?:\s|^|\(|\[)([0-9a-zA-Z-_\.]+/[0-9a-zA-Z-_\.]+#[0-9]+)(?:\s|$|\)|\]|\.(\s|$))`)
diff --git a/modules/markup/html_internal_test.go b/modules/markup/html_internal_test.go
index f0d894532b..bb47ba3b2c 100644
--- a/modules/markup/html_internal_test.go
+++ b/modules/markup/html_internal_test.go
@@ -118,6 +118,10 @@ func TestRender_IssueIndexPattern2(t *testing.T) {
test("wow (#54321 #1243)", "wow (%s %s)", 54321, 1243)
test("(#4)(#5)", "(%s)(%s)", 4, 5)
test("#1 (#4321) test", "%s (%s) test", 1, 4321)
+
+ // should render with :
+ test("#1234: test", "%s: test", 1234)
+ test("wow (#54321: test)", "wow (%s: test)", 54321)
}
func TestRender_IssueIndexPattern3(t *testing.T) {
@@ -237,6 +241,8 @@ func TestRegExp_issueNumericPattern(t *testing.T) {
"#0",
"#1234567890987654321",
" #12",
+ "#12:",
+ "ref: #12: msg",
}
falseTestCases := []string{
"# 1234",
@@ -354,6 +360,7 @@ func TestRegExp_issueAlphanumericPattern(t *testing.T) {
"ABC-123.",
"(ABC-123)",
"[ABC-123]",
+ "ABC-123:",
}
falseTestCases := []string{
"RC-08",