@ -53,38 +53,38 @@ var (
// shortLinkPattern matches short but difficult to parse [[name|link|arg=test]] syntax
shortLinkPattern = regexp . MustCompile ( ` \[\[(.*?)\]\](\w*) ` )
// any SHA1 Pattern splits url containing SHA into parts
// any Hash Pattern splits url containing SHA into parts
anyHashPattern = regexp . MustCompile ( ` https?://(?:\S+/) { 4,5}([0-9a-f] { 40,64})(/[-+~_%.a-zA-Z0-9/]+)?(#[-+~_%.a-zA-Z0-9]+)? ` )
// comparePattern matches "http://domain/org/repo/compare/COMMIT1...COMMIT2#hash"
comparePattern = regexp . MustCompile ( ` https?://(?:\S+/) { 4,5}([0-9a-f] { 7,64})(\.\.\.?)([0-9a-f] { 7,64})?(#[-+~_%.a-zA-Z0-9]+)? ` )
validLinksPattern = regexp . MustCompile ( ` ^[a-z][\w-]+:// ` )
// fullURLPattern matches full URL like "mailto:...", "https://..." and "ssh+git://..."
fullURLPattern = regexp . MustCompile ( ` ^[a-z][-+\w]+: ` )
// While this email regex is definitely not perfect and I'm sure you can come up
// with edge cases, it is still accepted by the CommonMark specification, as
// well as the HTML5 spec:
// emailRegex is definitely not perfect with edge cases,
// it is still accepted by the CommonMark specification, as well as the HTML5 spec:
// http://spec.commonmark.org/0.28/#email-address
// https://html.spec.whatwg.org/multipage/input.html#e-mail-state-(type%3Demail)
emailRegex = regexp . MustCompile ( "(?:\\s|^|\\(|\\[)([a-zA-Z0-9.!#$%&'*+\\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\\.[a-zA-Z0-9]{2,}(?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+)(?:\\s|$|\\)|\\]|;|,|\\?|!|\\.(\\s|$))" )
// blackfriday extensions create IDs like fn:user-content-footnote
// blackfriday ExtRegex is for blackfriday extensions create IDs like fn:user-content-footnote
blackfridayExtRegex = regexp . MustCompile ( ` [^:]*:user-content- ` )
// E mojiShortCodeRegex find emoji by alias like :smile:
E mojiShortCodeRegex = regexp . MustCompile ( ` :[-+\w]+: ` )
// e mojiShortCodeRegex find emoji by alias like :smile:
e mojiShortCodeRegex = regexp . MustCompile ( ` :[-+\w]+: ` )
)
// CSS class for action keywords (e.g. "closes: #1")
const keywordClass = "issue-keyword"
// Is Link reports whether link fits valid format.
func Is Link ( link [ ] byte ) bool {
return validLinks Pattern. Match ( link )
// Is FullURLBytes reports whether link fits valid format.
func Is FullURLBytes ( link [ ] byte ) bool {
return fullURL Pattern. Match ( link )
}
func Is Link Str( link string ) bool {
return validLinks Pattern. MatchString ( link )
func Is FullUR LString ( link string ) bool {
return fullURL Pattern. MatchString ( link )
}
// regexp for full links to issues/pulls
@ -399,7 +399,7 @@ func visitNode(ctx *RenderContext, procs []processor, node *html.Node) {
if attr . Key != "src" {
continue
}
if len ( attr . Val ) > 0 && ! Is Link Str( attr . Val ) && ! strings . HasPrefix ( attr . Val , "data:image/" ) {
if len ( attr . Val ) > 0 && ! Is FullUR LString ( attr . Val ) && ! strings . HasPrefix ( attr . Val , "data:image/" ) {
attr . Val = util . URLJoin ( ctx . Links . ResolveMediaLink ( ctx . IsWiki ) , attr . Val )
}
attr . Val = camoHandleLink ( attr . Val )
@ -650,7 +650,7 @@ func shortLinkProcessor(ctx *RenderContext, node *html.Node) {
if equalPos := strings . IndexByte ( v , '=' ) ; equalPos == - 1 {
// There is no equal in this argument; this is a mandatory arg
if props [ "name" ] == "" {
if Is Link Str( v ) {
if Is FullUR LString ( v ) {
// If we clearly see it is a link, we save it so
// But first we need to ensure, that if both mandatory args provided
@ -725,7 +725,7 @@ func shortLinkProcessor(ctx *RenderContext, node *html.Node) {
DataAtom : atom . A ,
}
childNode . Parent = linkNode
absoluteLink := Is Link Str( link )
absoluteLink := Is FullUR LString ( link )
if ! absoluteLink {
if image {
link = strings . ReplaceAll ( link , " " , "+" )
@ -1059,7 +1059,7 @@ func emojiShortCodeProcessor(ctx *RenderContext, node *html.Node) {
start := 0
next := node . NextSibling
for node != nil && node != next && start < len ( node . Data ) {
m := E mojiShortCodeRegex. FindStringSubmatchIndex ( node . Data [ start : ] )
m := e mojiShortCodeRegex. FindStringSubmatchIndex ( node . Data [ start : ] )
if m == nil {
return
}