mirror of
				https://github.com/go-gitea/gitea.git
				synced 2025-10-31 21:28:11 +09:00 
			
		
		
		
	Issue/PR Context Popups (#9822)
* Add data-index attribute to issue anchors Signed-off-by: jolheiser <john.olheiser@gmail.com> * Init JS Signed-off-by: jolheiser <john.olheiser@gmail.com> * Add required data to anchor Signed-off-by: jolheiser <john.olheiser@gmail.com> * Finish popup Signed-off-by: jolheiser <john.olheiser@gmail.com> * Revert changes to html.go Signed-off-by: jolheiser <john.olheiser@gmail.com> * Better octicon contexts Signed-off-by: jolheiser <john.olheiser@gmail.com> * Split out popup function for re-use Signed-off-by: jolheiser <john.olheiser@gmail.com> * Style changes, test fixes, and cross-reference support Signed-off-by: jolheiser <john.olheiser@gmail.com> * Prefer em to px Signed-off-by: jolheiser <john.olheiser@gmail.com> * Move label margin to base CSS Signed-off-by: jolheiser <john.olheiser@gmail.com> * Move JS to separate file. Signed-off-by: jolheiser <john.olheiser@gmail.com> * Move JS to features and fix module Signed-off-by: jolheiser <john.olheiser@gmail.com> * Remove query-string and hash Co-Authored-By: silverwind <me@silverwind.io> Co-authored-by: Lauris BH <lauris@nix.lv> Co-authored-by: Antoine GIRARD <sapk@users.noreply.github.com> Co-authored-by: silverwind <me@silverwind.io> Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com> Co-authored-by: zeripath <art27@cantab.net>
This commit is contained in:
		
				
					committed by
					
						 techknowlogick
						techknowlogick
					
				
			
			
				
	
			
			
			
						parent
						
							c5014a7f2c
						
					
				
				
					commit
					7d7ab1eeae
				
			| @@ -636,11 +636,11 @@ func fullIssuePatternProcessor(ctx *postProcessCtx, node *html.Node) { | ||||
| 	if matchOrg == ctx.metas["user"] && matchRepo == ctx.metas["repo"] { | ||||
| 		// TODO if m[4]:m[5] is not nil, then link is to a comment, | ||||
| 		// and we should indicate that in the text somehow | ||||
| 		replaceContent(node, m[0], m[1], createLink(link, id, "issue")) | ||||
| 		replaceContent(node, m[0], m[1], createLink(link, id, "ref-issue")) | ||||
|  | ||||
| 	} else { | ||||
| 		orgRepoID := matchOrg + "/" + matchRepo + id | ||||
| 		replaceContent(node, m[0], m[1], createLink(link, orgRepoID, "issue")) | ||||
| 		replaceContent(node, m[0], m[1], createLink(link, orgRepoID, "ref-issue")) | ||||
| 	} | ||||
| } | ||||
|  | ||||
| @@ -676,7 +676,7 @@ func issueIndexPatternProcessor(ctx *postProcessCtx, node *html.Node) { | ||||
| 	reftext := node.Data[ref.RefLocation.Start:ref.RefLocation.End] | ||||
| 	if exttrack && !ref.IsPull { | ||||
| 		ctx.metas["index"] = ref.Issue | ||||
| 		link = createLink(com.Expand(ctx.metas["format"], ctx.metas), reftext, "issue") | ||||
| 		link = createLink(com.Expand(ctx.metas["format"], ctx.metas), reftext, "ref-issue") | ||||
| 	} else { | ||||
| 		// Path determines the type of link that will be rendered. It's unknown at this point whether | ||||
| 		// the linked item is actually a PR or an issue. Luckily it's of no real consequence because | ||||
| @@ -686,9 +686,9 @@ func issueIndexPatternProcessor(ctx *postProcessCtx, node *html.Node) { | ||||
| 			path = "pulls" | ||||
| 		} | ||||
| 		if ref.Owner == "" { | ||||
| 			link = createLink(util.URLJoin(setting.AppURL, ctx.metas["user"], ctx.metas["repo"], path, ref.Issue), reftext, "issue") | ||||
| 			link = createLink(util.URLJoin(setting.AppURL, ctx.metas["user"], ctx.metas["repo"], path, ref.Issue), reftext, "ref-issue") | ||||
| 		} else { | ||||
| 			link = createLink(util.URLJoin(setting.AppURL, ref.Owner, ref.Name, path, ref.Issue), reftext, "issue") | ||||
| 			link = createLink(util.URLJoin(setting.AppURL, ref.Owner, ref.Name, path, ref.Issue), reftext, "ref-issue") | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
|   | ||||
| @@ -106,13 +106,13 @@ func TestRender_IssueIndexPattern2(t *testing.T) { | ||||
|  | ||||
| 		links := make([]interface{}, len(indices)) | ||||
| 		for i, index := range indices { | ||||
| 			links[i] = numericIssueLink(util.URLJoin(setting.AppSubURL, path), "issue", index, marker) | ||||
| 			links[i] = numericIssueLink(util.URLJoin(setting.AppSubURL, path), "ref-issue", index, marker) | ||||
| 		} | ||||
| 		expectedNil := fmt.Sprintf(expectedFmt, links...) | ||||
| 		testRenderIssueIndexPattern(t, s, expectedNil, &postProcessCtx{metas: localMetas}) | ||||
|  | ||||
| 		for i, index := range indices { | ||||
| 			links[i] = numericIssueLink(prefix, "issue", index, marker) | ||||
| 			links[i] = numericIssueLink(prefix, "ref-issue", index, marker) | ||||
| 		} | ||||
| 		expectedNum := fmt.Sprintf(expectedFmt, links...) | ||||
| 		testRenderIssueIndexPattern(t, s, expectedNum, &postProcessCtx{metas: numericMetas}) | ||||
| @@ -178,7 +178,7 @@ func TestRender_IssueIndexPattern4(t *testing.T) { | ||||
| 	test := func(s, expectedFmt string, names ...string) { | ||||
| 		links := make([]interface{}, len(names)) | ||||
| 		for i, name := range names { | ||||
| 			links[i] = alphanumIssueLink("https://someurl.com/someUser/someRepo/", "issue", name) | ||||
| 			links[i] = alphanumIssueLink("https://someurl.com/someUser/someRepo/", "ref-issue", name) | ||||
| 		} | ||||
| 		expected := fmt.Sprintf(expectedFmt, links...) | ||||
| 		testRenderIssueIndexPattern(t, s, expected, &postProcessCtx{metas: alphanumericMetas}) | ||||
| @@ -217,7 +217,7 @@ func TestRender_AutoLink(t *testing.T) { | ||||
|  | ||||
| 	// render valid issue URLs | ||||
| 	test(util.URLJoin(setting.AppSubURL, "issues", "3333"), | ||||
| 		numericIssueLink(util.URLJoin(setting.AppSubURL, "issues"), "issue", 3333, "#")) | ||||
| 		numericIssueLink(util.URLJoin(setting.AppSubURL, "issues"), "ref-issue", 3333, "#")) | ||||
|  | ||||
| 	// render valid commit URLs | ||||
| 	tmp := util.URLJoin(AppSubURL, "commit", "d8a994ef243349f321568f9e36d5c3f444b99cae") | ||||
| @@ -248,11 +248,11 @@ func TestRender_FullIssueURLs(t *testing.T) { | ||||
| 	test("Here is a link https://git.osgeo.org/gogs/postgis/postgis/pulls/6", | ||||
| 		"Here is a link https://git.osgeo.org/gogs/postgis/postgis/pulls/6") | ||||
| 	test("Look here http://localhost:3000/person/repo/issues/4", | ||||
| 		`Look here <a href="http://localhost:3000/person/repo/issues/4" class="issue">person/repo#4</a>`) | ||||
| 		`Look here <a href="http://localhost:3000/person/repo/issues/4" class="ref-issue">person/repo#4</a>`) | ||||
| 	test("http://localhost:3000/person/repo/issues/4#issuecomment-1234", | ||||
| 		`<a href="http://localhost:3000/person/repo/issues/4#issuecomment-1234" class="issue">person/repo#4</a>`) | ||||
| 		`<a href="http://localhost:3000/person/repo/issues/4#issuecomment-1234" class="ref-issue">person/repo#4</a>`) | ||||
| 	test("http://localhost:3000/gogits/gogs/issues/4", | ||||
| 		`<a href="http://localhost:3000/gogits/gogs/issues/4" class="issue">#4</a>`) | ||||
| 		`<a href="http://localhost:3000/gogits/gogs/issues/4" class="ref-issue">#4</a>`) | ||||
| } | ||||
|  | ||||
| func TestRegExp_sha1CurrentPattern(t *testing.T) { | ||||
|   | ||||
| @@ -58,10 +58,10 @@ func TestRender_CrossReferences(t *testing.T) { | ||||
|  | ||||
| 	test( | ||||
| 		"gogits/gogs#12345", | ||||
| 		`<p><a href="`+util.URLJoin(AppURL, "gogits", "gogs", "issues", "12345")+`" rel="nofollow">gogits/gogs#12345</a></p>`) | ||||
| 		`<p><a href="`+util.URLJoin(AppURL, "gogits", "gogs", "issues", "12345")+`" class="ref-issue" rel="nofollow">gogits/gogs#12345</a></p>`) | ||||
| 	test( | ||||
| 		"go-gitea/gitea#12345", | ||||
| 		`<p><a href="`+util.URLJoin(AppURL, "go-gitea", "gitea", "issues", "12345")+`" rel="nofollow">go-gitea/gitea#12345</a></p>`) | ||||
| 		`<p><a href="`+util.URLJoin(AppURL, "go-gitea", "gitea", "issues", "12345")+`" class="ref-issue" rel="nofollow">go-gitea/gitea#12345</a></p>`) | ||||
| 	test( | ||||
| 		"/home/gitea/go-gitea/gitea#12345", | ||||
| 		`<p>/home/gitea/go-gitea/gitea#12345</p>`) | ||||
|   | ||||
| @@ -105,8 +105,8 @@ func testAnswers(baseURLContent, baseURLImages string) []string { | ||||
| <p>See commit <a href="http://localhost:3000/gogits/gogs/commit/65f1bf27bc" rel="nofollow"><code>65f1bf27bc</code></a></p> | ||||
| <p>Ideas and codes</p> | ||||
| <ul> | ||||
| <li>Bezier widget (by <a href="` + AppURL + `r-lyeh" rel="nofollow">@r-lyeh</a>) <a href="http://localhost:3000/ocornut/imgui/issues/786" rel="nofollow">ocornut/imgui#786</a></li> | ||||
| <li>Bezier widget (by <a href="` + AppURL + `r-lyeh" rel="nofollow">@r-lyeh</a>) <a href="http://localhost:3000/gogits/gogs/issues/786" rel="nofollow">#786</a></li> | ||||
| <li>Bezier widget (by <a href="` + AppURL + `r-lyeh" rel="nofollow">@r-lyeh</a>) <a href="http://localhost:3000/ocornut/imgui/issues/786" class="ref-issue" rel="nofollow">ocornut/imgui#786</a></li> | ||||
| <li>Bezier widget (by <a href="` + AppURL + `r-lyeh" rel="nofollow">@r-lyeh</a>) <a href="http://localhost:3000/gogits/gogs/issues/786" class="ref-issue" rel="nofollow">#786</a></li> | ||||
| <li>Node graph editors <a href="https://github.com/ocornut/imgui/issues/306" rel="nofollow">https://github.com/ocornut/imgui/issues/306</a></li> | ||||
| <li><a href="` + baseURLContent + `/memory_editor_example" rel="nofollow">Memory Editor</a></li> | ||||
| <li><a href="` + baseURLContent + `/plot_var_example" rel="nofollow">Plot var helper</a></li> | ||||
|   | ||||
| @@ -53,6 +53,9 @@ func ReplaceSanitizer() { | ||||
| 	// Allow <kbd> tags for keyboard shortcut styling | ||||
| 	sanitizer.policy.AllowElements("kbd") | ||||
|  | ||||
| 	// Allow classes for anchors | ||||
| 	sanitizer.policy.AllowAttrs("class").Matching(regexp.MustCompile(`ref-issue`)).OnElements("a") | ||||
|  | ||||
| 	// Custom keyword markup | ||||
| 	for _, rule := range setting.ExternalSanitizerRules { | ||||
| 		if rule.Regexp != nil { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user