mirror of
				https://github.com/go-gitea/gitea.git
				synced 2025-10-29 10:57:44 +09:00 
			
		
		
		
	
							
								
								
									
										2
									
								
								vendor/github.com/yuin/goldmark/extension/ast/tasklist.go
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								vendor/github.com/yuin/goldmark/extension/ast/tasklist.go
									
									
									
										generated
									
									
										vendored
									
									
								
							| @@ -11,7 +11,7 @@ type TaskCheckBox struct { | ||||
| 	IsChecked bool | ||||
| } | ||||
|  | ||||
| // Dump impelemtns Node.Dump. | ||||
| // Dump implements Node.Dump. | ||||
| func (n *TaskCheckBox) Dump(source []byte, level int) { | ||||
| 	m := map[string]string{ | ||||
| 		"Checked": fmt.Sprintf("%v", n.IsChecked), | ||||
|   | ||||
							
								
								
									
										179
									
								
								vendor/github.com/yuin/goldmark/extension/linkify.go
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										179
									
								
								vendor/github.com/yuin/goldmark/extension/linkify.go
									
									
									
										generated
									
									
										vendored
									
									
								
							| @@ -2,27 +2,153 @@ package extension | ||||
|  | ||||
| import ( | ||||
| 	"bytes" | ||||
| 	"regexp" | ||||
|  | ||||
| 	"github.com/yuin/goldmark" | ||||
| 	"github.com/yuin/goldmark/ast" | ||||
| 	"github.com/yuin/goldmark/parser" | ||||
| 	"github.com/yuin/goldmark/text" | ||||
| 	"github.com/yuin/goldmark/util" | ||||
| 	"regexp" | ||||
| ) | ||||
|  | ||||
| var wwwURLRegxp = regexp.MustCompile(`^www\.[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}((?:/|[#?])[-a-zA-Z0-9@:%_\+.~#!?&//=\(\);,'">\^{}\[\]` + "`" + `]*)?`) | ||||
| var wwwURLRegxp = regexp.MustCompile(`^www\.[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]+(?:(?:/|[#?])[-a-zA-Z0-9@:%_\+.~#!?&//=\(\);,'">\^{}\[\]` + "`" + `]*)?`) | ||||
|  | ||||
| var urlRegexp = regexp.MustCompile(`^(?:http|https|ftp):\/\/(?:www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}((?:/|[#?])[-a-zA-Z0-9@:%_+.~#$!?&//=\(\);,'">\^{}\[\]` + "`" + `]*)?`) | ||||
| var urlRegexp = regexp.MustCompile(`^(?:http|https|ftp):\/\/(?:www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]+(?:(?:/|[#?])[-a-zA-Z0-9@:%_+.~#$!?&//=\(\);,'">\^{}\[\]` + "`" + `]*)?`) | ||||
|  | ||||
| type linkifyParser struct { | ||||
| // An LinkifyConfig struct is a data structure that holds configuration of the | ||||
| // Linkify extension. | ||||
| type LinkifyConfig struct { | ||||
| 	AllowedProtocols [][]byte | ||||
| 	URLRegexp        *regexp.Regexp | ||||
| 	WWWRegexp        *regexp.Regexp | ||||
| 	EmailRegexp      *regexp.Regexp | ||||
| } | ||||
|  | ||||
| var defaultLinkifyParser = &linkifyParser{} | ||||
| const optLinkifyAllowedProtocols parser.OptionName = "LinkifyAllowedProtocols" | ||||
| const optLinkifyURLRegexp parser.OptionName = "LinkifyURLRegexp" | ||||
| const optLinkifyWWWRegexp parser.OptionName = "LinkifyWWWRegexp" | ||||
| const optLinkifyEmailRegexp parser.OptionName = "LinkifyEmailRegexp" | ||||
|  | ||||
| // SetOption implements SetOptioner. | ||||
| func (c *LinkifyConfig) SetOption(name parser.OptionName, value interface{}) { | ||||
| 	switch name { | ||||
| 	case optLinkifyAllowedProtocols: | ||||
| 		c.AllowedProtocols = value.([][]byte) | ||||
| 	case optLinkifyURLRegexp: | ||||
| 		c.URLRegexp = value.(*regexp.Regexp) | ||||
| 	case optLinkifyWWWRegexp: | ||||
| 		c.WWWRegexp = value.(*regexp.Regexp) | ||||
| 	case optLinkifyEmailRegexp: | ||||
| 		c.EmailRegexp = value.(*regexp.Regexp) | ||||
| 	} | ||||
| } | ||||
|  | ||||
| // A LinkifyOption interface sets options for the LinkifyOption. | ||||
| type LinkifyOption interface { | ||||
| 	parser.Option | ||||
| 	SetLinkifyOption(*LinkifyConfig) | ||||
| } | ||||
|  | ||||
| type withLinkifyAllowedProtocols struct { | ||||
| 	value [][]byte | ||||
| } | ||||
|  | ||||
| func (o *withLinkifyAllowedProtocols) SetParserOption(c *parser.Config) { | ||||
| 	c.Options[optLinkifyAllowedProtocols] = o.value | ||||
| } | ||||
|  | ||||
| func (o *withLinkifyAllowedProtocols) SetLinkifyOption(p *LinkifyConfig) { | ||||
| 	p.AllowedProtocols = o.value | ||||
| } | ||||
|  | ||||
| // WithLinkifyAllowedProtocols is a functional option that specify allowed | ||||
| // protocols in autolinks. Each protocol must end with ':' like | ||||
| // 'http:' . | ||||
| func WithLinkifyAllowedProtocols(value [][]byte) LinkifyOption { | ||||
| 	return &withLinkifyAllowedProtocols{ | ||||
| 		value: value, | ||||
| 	} | ||||
| } | ||||
|  | ||||
| type withLinkifyURLRegexp struct { | ||||
| 	value *regexp.Regexp | ||||
| } | ||||
|  | ||||
| func (o *withLinkifyURLRegexp) SetParserOption(c *parser.Config) { | ||||
| 	c.Options[optLinkifyURLRegexp] = o.value | ||||
| } | ||||
|  | ||||
| func (o *withLinkifyURLRegexp) SetLinkifyOption(p *LinkifyConfig) { | ||||
| 	p.URLRegexp = o.value | ||||
| } | ||||
|  | ||||
| // WithLinkifyURLRegexp is a functional option that specify | ||||
| // a pattern of the URL including a protocol. | ||||
| func WithLinkifyURLRegexp(value *regexp.Regexp) LinkifyOption { | ||||
| 	return &withLinkifyURLRegexp{ | ||||
| 		value: value, | ||||
| 	} | ||||
| } | ||||
|  | ||||
| // WithLinkifyWWWRegexp is a functional option that specify | ||||
| // a pattern of the URL without a protocol. | ||||
| // This pattern must start with 'www.' . | ||||
| type withLinkifyWWWRegexp struct { | ||||
| 	value *regexp.Regexp | ||||
| } | ||||
|  | ||||
| func (o *withLinkifyWWWRegexp) SetParserOption(c *parser.Config) { | ||||
| 	c.Options[optLinkifyWWWRegexp] = o.value | ||||
| } | ||||
|  | ||||
| func (o *withLinkifyWWWRegexp) SetLinkifyOption(p *LinkifyConfig) { | ||||
| 	p.WWWRegexp = o.value | ||||
| } | ||||
|  | ||||
| func WithLinkifyWWWRegexp(value *regexp.Regexp) LinkifyOption { | ||||
| 	return &withLinkifyWWWRegexp{ | ||||
| 		value: value, | ||||
| 	} | ||||
| } | ||||
|  | ||||
| // WithLinkifyWWWRegexp is a functional otpion that specify | ||||
| // a pattern of the email address. | ||||
| type withLinkifyEmailRegexp struct { | ||||
| 	value *regexp.Regexp | ||||
| } | ||||
|  | ||||
| func (o *withLinkifyEmailRegexp) SetParserOption(c *parser.Config) { | ||||
| 	c.Options[optLinkifyEmailRegexp] = o.value | ||||
| } | ||||
|  | ||||
| func (o *withLinkifyEmailRegexp) SetLinkifyOption(p *LinkifyConfig) { | ||||
| 	p.EmailRegexp = o.value | ||||
| } | ||||
|  | ||||
| func WithLinkifyEmailRegexp(value *regexp.Regexp) LinkifyOption { | ||||
| 	return &withLinkifyEmailRegexp{ | ||||
| 		value: value, | ||||
| 	} | ||||
| } | ||||
|  | ||||
| type linkifyParser struct { | ||||
| 	LinkifyConfig | ||||
| } | ||||
|  | ||||
| // NewLinkifyParser return a new InlineParser can parse | ||||
| // text that seems like a URL. | ||||
| func NewLinkifyParser() parser.InlineParser { | ||||
| 	return defaultLinkifyParser | ||||
| func NewLinkifyParser(opts ...LinkifyOption) parser.InlineParser { | ||||
| 	p := &linkifyParser{ | ||||
| 		LinkifyConfig: LinkifyConfig{ | ||||
| 			AllowedProtocols: nil, | ||||
| 			URLRegexp:        urlRegexp, | ||||
| 			WWWRegexp:        wwwURLRegxp, | ||||
| 		}, | ||||
| 	} | ||||
| 	for _, o := range opts { | ||||
| 		o.SetLinkifyOption(&p.LinkifyConfig) | ||||
| 	} | ||||
| 	return p | ||||
| } | ||||
|  | ||||
| func (s *linkifyParser) Trigger() []byte { | ||||
| @@ -53,14 +179,26 @@ func (s *linkifyParser) Parse(parent ast.Node, block text.Reader, pc parser.Cont | ||||
| 	var m []int | ||||
| 	var protocol []byte | ||||
| 	var typ ast.AutoLinkType = ast.AutoLinkURL | ||||
| 	if bytes.HasPrefix(line, protoHTTP) || bytes.HasPrefix(line, protoHTTPS) || bytes.HasPrefix(line, protoFTP) { | ||||
| 		m = urlRegexp.FindSubmatchIndex(line) | ||||
| 	if s.LinkifyConfig.AllowedProtocols == nil { | ||||
| 		if bytes.HasPrefix(line, protoHTTP) || bytes.HasPrefix(line, protoHTTPS) || bytes.HasPrefix(line, protoFTP) { | ||||
| 			m = s.LinkifyConfig.URLRegexp.FindSubmatchIndex(line) | ||||
| 		} | ||||
| 	} else { | ||||
| 		for _, prefix := range s.LinkifyConfig.AllowedProtocols { | ||||
| 			if bytes.HasPrefix(line, prefix) { | ||||
| 				m = s.LinkifyConfig.URLRegexp.FindSubmatchIndex(line) | ||||
| 				break | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
| 	if m == nil && bytes.HasPrefix(line, domainWWW) { | ||||
| 		m = wwwURLRegxp.FindSubmatchIndex(line) | ||||
| 		m = s.LinkifyConfig.WWWRegexp.FindSubmatchIndex(line) | ||||
| 		protocol = []byte("http") | ||||
| 	} | ||||
| 	if m != nil { | ||||
| 	if m != nil && m[0] != 0 { | ||||
| 		m = nil | ||||
| 	} | ||||
| 	if m != nil && m[0] == 0 { | ||||
| 		lastChar := line[m[1]-1] | ||||
| 		if lastChar == '.' { | ||||
| 			m[1]-- | ||||
| @@ -96,7 +234,15 @@ func (s *linkifyParser) Parse(parent ast.Node, block text.Reader, pc parser.Cont | ||||
| 			return nil | ||||
| 		} | ||||
| 		typ = ast.AutoLinkEmail | ||||
| 		stop := util.FindEmailIndex(line) | ||||
| 		stop := -1 | ||||
| 		if s.LinkifyConfig.EmailRegexp == nil { | ||||
| 			stop = util.FindEmailIndex(line) | ||||
| 		} else { | ||||
| 			m := s.LinkifyConfig.EmailRegexp.FindSubmatchIndex(line) | ||||
| 			if m != nil && m[0] == 0 { | ||||
| 				stop = m[1] | ||||
| 			} | ||||
| 		} | ||||
| 		if stop < 0 { | ||||
| 			return nil | ||||
| 		} | ||||
| @@ -136,15 +282,22 @@ func (s *linkifyParser) CloseBlock(parent ast.Node, pc parser.Context) { | ||||
| } | ||||
|  | ||||
| type linkify struct { | ||||
| 	options []LinkifyOption | ||||
| } | ||||
|  | ||||
| // Linkify is an extension that allow you to parse text that seems like a URL. | ||||
| var Linkify = &linkify{} | ||||
|  | ||||
| func NewLinkify(opts ...LinkifyOption) goldmark.Extender { | ||||
| 	return &linkify{ | ||||
| 		options: opts, | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func (e *linkify) Extend(m goldmark.Markdown) { | ||||
| 	m.Parser().AddOptions( | ||||
| 		parser.WithInlineParsers( | ||||
| 			util.Prioritized(NewLinkifyParser(), 999), | ||||
| 			util.Prioritized(NewLinkifyParser(e.options...), 999), | ||||
| 		), | ||||
| 	) | ||||
| } | ||||
|   | ||||
							
								
								
									
										2
									
								
								vendor/github.com/yuin/goldmark/extension/table.go
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								vendor/github.com/yuin/goldmark/extension/table.go
									
									
									
										generated
									
									
										vendored
									
									
								
							| @@ -27,7 +27,7 @@ type tableParagraphTransformer struct { | ||||
| var defaultTableParagraphTransformer = &tableParagraphTransformer{} | ||||
|  | ||||
| // NewTableParagraphTransformer returns  a new ParagraphTransformer | ||||
| // that can transform pargraphs into tables. | ||||
| // that can transform paragraphs into tables. | ||||
| func NewTableParagraphTransformer() parser.ParagraphTransformer { | ||||
| 	return defaultTableParagraphTransformer | ||||
| } | ||||
|   | ||||
							
								
								
									
										29
									
								
								vendor/github.com/yuin/goldmark/extension/typographer.go
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										29
									
								
								vendor/github.com/yuin/goldmark/extension/typographer.go
									
									
									
										generated
									
									
										vendored
									
									
								
							| @@ -1,6 +1,8 @@ | ||||
| package extension | ||||
|  | ||||
| import ( | ||||
| 	"unicode" | ||||
|  | ||||
| 	"github.com/yuin/goldmark" | ||||
| 	gast "github.com/yuin/goldmark/ast" | ||||
| 	"github.com/yuin/goldmark/parser" | ||||
| @@ -31,6 +33,8 @@ const ( | ||||
| 	LeftAngleQuote | ||||
| 	// RightAngleQuote is >> | ||||
| 	RightAngleQuote | ||||
| 	// Apostrophe is ' | ||||
| 	Apostrophe | ||||
|  | ||||
| 	typographicPunctuationMax | ||||
| ) | ||||
| @@ -52,6 +56,7 @@ func newDefaultSubstitutions() [][]byte { | ||||
| 	replacements[Ellipsis] = []byte("…") | ||||
| 	replacements[LeftAngleQuote] = []byte("«") | ||||
| 	replacements[RightAngleQuote] = []byte("»") | ||||
| 	replacements[Apostrophe] = []byte("’") | ||||
|  | ||||
| 	return replacements | ||||
| } | ||||
| @@ -189,6 +194,26 @@ func (s *typographerParser) Parse(parent gast.Node, block text.Reader, pc parser | ||||
| 			return nil | ||||
| 		} | ||||
| 		if c == '\'' { | ||||
| 			if s.Substitutions[Apostrophe] != nil { | ||||
| 				// Handle decade abbrevations such as '90s | ||||
| 				if d.CanOpen && !d.CanClose && len(line) > 3 && util.IsNumeric(line[1]) && util.IsNumeric(line[2]) && line[3] == 's' { | ||||
| 					after := util.ToRune(line, 4) | ||||
| 					if len(line) == 3 || unicode.IsSpace(after) || unicode.IsPunct(after) { | ||||
| 						node := gast.NewString(s.Substitutions[Apostrophe]) | ||||
| 						node.SetCode(true) | ||||
| 						block.Advance(1) | ||||
| 						return node | ||||
| 					} | ||||
| 				} | ||||
| 				// Convert normal apostrophes. This is probably more flexible than necessary but | ||||
| 				// converts any apostrophe in between two alphanumerics. | ||||
| 				if len(line) > 1 && (unicode.IsDigit(before) || unicode.IsLetter(before)) && (util.IsAlphaNumeric(line[1])) { | ||||
| 					node := gast.NewString(s.Substitutions[Apostrophe]) | ||||
| 					node.SetCode(true) | ||||
| 					block.Advance(1) | ||||
| 					return node | ||||
| 				} | ||||
| 			} | ||||
| 			if s.Substitutions[LeftSingleQuote] != nil && d.CanOpen && !d.CanClose { | ||||
| 				node := gast.NewString(s.Substitutions[LeftSingleQuote]) | ||||
| 				node.SetCode(true) | ||||
| @@ -228,10 +253,10 @@ type typographer struct { | ||||
| 	options []TypographerOption | ||||
| } | ||||
|  | ||||
| // Typographer is an extension that repalace punctuations with typographic entities. | ||||
| // Typographer is an extension that replaces punctuations with typographic entities. | ||||
| var Typographer = &typographer{} | ||||
|  | ||||
| // NewTypographer returns a new Entender that repalace punctuations with typographic entities. | ||||
| // NewTypographer returns a new Extender that replaces punctuations with typographic entities. | ||||
| func NewTypographer(opts ...TypographerOption) goldmark.Extender { | ||||
| 	return &typographer{ | ||||
| 		options: opts, | ||||
|   | ||||
		Reference in New Issue
	
	Block a user