summaryrefslogtreecommitdiffstats
path: root/modules/markup/html.go
diff options
context:
space:
mode:
authorguillep2k <18600385+guillep2k@users.noreply.github.com>2019-10-14 22:31:09 -0300
committerzeripath <art27@cantab.net>2019-10-15 02:31:09 +0100
commitcea8ea5ae64bbb287ed7011c6fc2e51ccdfb9cb3 (patch)
tree00c5b6906745fcefed54442ce43e38477218f685 /modules/markup/html.go
parent8ad26976114c4fed6269a40e52632d065167bd20 (diff)
downloadgitea-cea8ea5ae64bbb287ed7011c6fc2e51ccdfb9cb3.tar.gz
gitea-cea8ea5ae64bbb287ed7011c6fc2e51ccdfb9cb3.zip
Support inline rendering of CUSTOM_URL_SCHEMES (#8496)
* Support inline rendering of CUSTOM_URL_SCHEMES * Fix lint * Add tests * Fix lint
Diffstat (limited to 'modules/markup/html.go')
-rw-r--r--modules/markup/html.go26
1 files changed, 26 insertions, 0 deletions
diff --git a/modules/markup/html.go b/modules/markup/html.go
index fc823b1f30..1ff7a41cbb 100644
--- a/modules/markup/html.go
+++ b/modules/markup/html.go
@@ -92,6 +92,32 @@ func getIssueFullPattern() *regexp.Regexp {
return issueFullPattern
}
+// CustomLinkURLSchemes allows for additional schemes to be detected when parsing links within text
+func CustomLinkURLSchemes(schemes []string) {
+ schemes = append(schemes, "http", "https")
+ withAuth := make([]string, 0, len(schemes))
+ validScheme := regexp.MustCompile(`^[a-z]+$`)
+ for _, s := range schemes {
+ if !validScheme.MatchString(s) {
+ continue
+ }
+ without := false
+ for _, sna := range xurls.SchemesNoAuthority {
+ if s == sna {
+ without = true
+ break
+ }
+ }
+ if without {
+ s += ":"
+ } else {
+ s += "://"
+ }
+ withAuth = append(withAuth, s)
+ }
+ linkRegex, _ = xurls.StrictMatchingScheme(strings.Join(withAuth, "|"))
+}
+
// IsSameDomain checks if given url string has the same hostname as current Gitea instance
func IsSameDomain(s string) bool {
if strings.HasPrefix(s, "/") {