Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrite reference processing code in preparation for opening/closing from comment references #8261

Merged
merged 50 commits into from
Oct 13, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
9dbabcd
Merge go-gitea/master into master
guillep2k Sep 14, 2019
889c619
Merge branch 'master' of github.com:go-gitea/gitea
guillep2k Sep 14, 2019
d7c46c8
Merge branch 'master' of github.com:go-gitea/gitea
guillep2k Sep 15, 2019
8eaacbf
Merge remote-tracking branch 'refs/remotes/origin/master'
guillep2k Sep 19, 2019
de5aa64
Merge branch 'master' of github.com:go-gitea/gitea
guillep2k Sep 19, 2019
80c6f2b
Merge branch 'master' of github.com:go-gitea/gitea
guillep2k Sep 20, 2019
7d7bd6c
Add a markdown stripper for mentions and xrefs
guillep2k Sep 20, 2019
c20afe1
Improve comments
guillep2k Sep 20, 2019
69ef1c3
Small code simplification
guillep2k Sep 21, 2019
ae66b14
Move reference code to modules/references
guillep2k Sep 21, 2019
999bc87
Fix typo
guillep2k Sep 21, 2019
06f092e
Make MarkdownStripper return [][]byte
guillep2k Sep 21, 2019
16c6ab4
Implement preliminary keywords parsing
guillep2k Sep 22, 2019
dadadfa
Add FIXME comment
guillep2k Sep 22, 2019
ac40f7f
Merge branch 'master' of github.com:go-gitea/gitea
guillep2k Sep 22, 2019
a118be2
Fix comment
guillep2k Sep 22, 2019
9206849
Merge branch 'master' of github.com:go-gitea/gitea into strip-markdown
guillep2k Sep 22, 2019
debb01a
make fmt
guillep2k Sep 22, 2019
163ec65
Fix permissions check
guillep2k Sep 22, 2019
4796f43
Fix text assumptions
guillep2k Sep 22, 2019
4c75723
Fix imports
guillep2k Sep 22, 2019
79a7275
Fix lint, fmt
guillep2k Sep 22, 2019
98ea87e
Fix unused import
guillep2k Sep 22, 2019
361ba2e
Add missing export comment
guillep2k Sep 22, 2019
ac57ac5
Bypass revive on implemented interface
guillep2k Sep 23, 2019
f6ac46b
Merge branch 'master' of github.com:go-gitea/gitea
guillep2k Sep 23, 2019
caa53b7
Move mdstripper into its own package
guillep2k Sep 24, 2019
b936015
Support alphanumeric patterns
guillep2k Sep 24, 2019
c4c467c
Refactor FindAllMentions
guillep2k Sep 24, 2019
fdb45e6
Move mentions test to references
guillep2k Sep 24, 2019
70684f5
Parse mentions from reference package
guillep2k Sep 24, 2019
b9d709b
Refactor code to implement renderizable references
guillep2k Sep 25, 2019
b763968
Fix typo
guillep2k Sep 25, 2019
06b0f51
Move patterns and tests to the references package
guillep2k Sep 25, 2019
a00c798
Fix nil reference
guillep2k Sep 25, 2019
b563158
Merge branch 'master' of github.com:go-gitea/gitea
guillep2k Sep 25, 2019
5acbf34
Merge 'master' into strip-markdown
guillep2k Sep 25, 2019
8668772
Preliminary rendering attempt of closing keywords
guillep2k Sep 26, 2019
fc7e278
Normalize names, comments, general tidy-up
guillep2k Sep 26, 2019
3f9cd80
Add CSS style for action keywords
guillep2k Sep 27, 2019
cd31aad
Merge branch 'master' of github.com:go-gitea/gitea into strip-markdown
guillep2k Sep 27, 2019
44d1758
Merge branch 'master' into strip-markdown
guillep2k Sep 29, 2019
02b6eb2
Fix permission for admin and owner
guillep2k Sep 30, 2019
549ef80
Merge branch 'strip-markdown' of github.com:guillep2k/gitea into stri…
guillep2k Sep 30, 2019
4acf06f
Merge branch 'master' of github.com:go-gitea/gitea into strip-markdown
guillep2k Oct 9, 2019
1faece0
Fix golangci-lint
guillep2k Oct 9, 2019
b0735c3
Fix golangci-lint
guillep2k Oct 9, 2019
d18ade7
merge from master, resolve conflicts
guillep2k Oct 10, 2019
4927471
Merge branch 'master' into strip-markdown
lafriks Oct 11, 2019
4780e47
Merge branch 'master' into strip-markdown
zeripath Oct 13, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Improve comments
  • Loading branch information
guillep2k committed Sep 20, 2019
commit c20afe104471d6f89ba02f3f11469f259eabd887
5 changes: 3 additions & 2 deletions modules/markup/markdown_stripper.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ func (r *MarkdownStripper) GetLinks() []string {
}

// FindAllMentions matches mention patterns in given content
// and returns a list of found user names without @ prefix.
// and returns a list of found unvalidated user names without @ prefix.
func FindAllMentions(content string) []string {
content, _ = StripMarkdown([]byte(content))
mentions := mentionPattern.FindAllStringSubmatch(content, -1)
Expand All @@ -257,7 +257,7 @@ type RawIssueReference struct {
}

// FindAllIssueReferences matches issue reference patterns in given content
// and returns a list of found references *with* #.
// and returns a list of unvalidated references.
func FindAllIssueReferences(content string) []*RawIssueReference {

content, links := StripMarkdown([]byte(content))
Expand All @@ -284,6 +284,7 @@ func FindAllIssueReferences(content string) []*RawIssueReference {

for _, link := range links {
if u, err := url.Parse(link); err == nil {
// Note: we're not attempting to match the URL scheme (http/https)
host := strings.ToLower(u.Host)
if host != "" && host != giteahost {
continue
Expand Down
16 changes: 10 additions & 6 deletions modules/markup/markdown_stripper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,29 +72,33 @@ A HIDDEN ` + "`" + `GHOST` + "`" + ` IN THIS LINE.

func TestFindAllIssueReferences(t *testing.T) {
text := `
#123 no
#124 yes
This [one](#919) no.
#123 no, this is a title.
#124 yes, this is a reference.
This [one](#919) no, this is a URL fragment.
This [two](/user2/repo1/issues/921) yes.
This [three](/user2/repo1/pulls/922) yes.
This [four](http://gitea.com:3000/user3/repo4/issues/203) yes.
This [five](http://github.com/user3/repo4/issues/204) no.

` + "```" + `
This is a code block.
#723 no
#723 no, it's a code block.
` + "```" + `

This ` + "`" + `#724` + "`" + ` no.
This ` + "`" + `#724` + "`" + ` no, it's inline code.
This user3/repo4#200 yes.
This http://gitea.com:3000/user4/repo5/201 no.
This http://gitea.com:3000/user4/repo5/201 no, bad URL.
This http://gitea.com:3000/user4/repo5/pulls/202 yes.
This http://GiTeA.COM:3000/user4/repo6/pulls/205 yes.

`
// Note, FindAllIssueReferences() processes inline
// references first, then link references.
expected := []*RawIssueReference{
// Inline references
{124, "", ""},
{200, "user3", "repo4"},
// Link references
{921, "user2", "repo1"},
{922, "user2", "repo1"},
{203, "user3", "repo4"},
Expand Down