mirror of
				https://gitee.com/gitea/gitea
				synced 2025-11-04 08:30:25 +08:00 
			
		
		
		
	Update Goldmark v1.1.25 -> v1.1.32 (#12048)
This commit is contained in:
		
							
								
								
									
										83
									
								
								vendor/github.com/yuin/goldmark/extension/typographer.go
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										83
									
								
								vendor/github.com/yuin/goldmark/extension/typographer.go
									
									
									
										generated
									
									
										vendored
									
									
								
							@@ -10,6 +10,27 @@ import (
 | 
			
		||||
	"github.com/yuin/goldmark/util"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
var uncloseCounterKey = parser.NewContextKey()
 | 
			
		||||
 | 
			
		||||
type unclosedCounter struct {
 | 
			
		||||
	Single int
 | 
			
		||||
	Double int
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (u *unclosedCounter) Reset() {
 | 
			
		||||
	u.Single = 0
 | 
			
		||||
	u.Double = 0
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func getUnclosedCounter(pc parser.Context) *unclosedCounter {
 | 
			
		||||
	v := pc.Get(uncloseCounterKey)
 | 
			
		||||
	if v == nil {
 | 
			
		||||
		v = &unclosedCounter{}
 | 
			
		||||
		pc.Set(uncloseCounterKey, v)
 | 
			
		||||
	}
 | 
			
		||||
	return v.(*unclosedCounter)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// TypographicPunctuation is a key of the punctuations that can be replaced with
 | 
			
		||||
// typographic entities.
 | 
			
		||||
type TypographicPunctuation int
 | 
			
		||||
@@ -143,7 +164,6 @@ func (s *typographerParser) Trigger() []byte {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (s *typographerParser) Parse(parent gast.Node, block text.Reader, pc parser.Context) gast.Node {
 | 
			
		||||
	before := block.PrecendingCharacter()
 | 
			
		||||
	line, _ := block.PeekLine()
 | 
			
		||||
	c := line[0]
 | 
			
		||||
	if len(line) > 2 {
 | 
			
		||||
@@ -189,15 +209,20 @@ func (s *typographerParser) Parse(parent gast.Node, block text.Reader, pc parser
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	if c == '\'' || c == '"' {
 | 
			
		||||
		before := block.PrecendingCharacter()
 | 
			
		||||
		d := parser.ScanDelimiter(line, before, 1, defaultTypographerDelimiterProcessor)
 | 
			
		||||
		if d == nil {
 | 
			
		||||
			return nil
 | 
			
		||||
		}
 | 
			
		||||
		counter := getUnclosedCounter(pc)
 | 
			
		||||
		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)
 | 
			
		||||
					after := rune(' ')
 | 
			
		||||
					if len(line) > 4 {
 | 
			
		||||
						after = util.ToRune(line, 4)
 | 
			
		||||
					}
 | 
			
		||||
					if len(line) == 3 || unicode.IsSpace(after) || unicode.IsPunct(after) {
 | 
			
		||||
						node := gast.NewString(s.Substitutions[Apostrophe])
 | 
			
		||||
						node.SetCode(true)
 | 
			
		||||
@@ -207,7 +232,7 @@ func (s *typographerParser) Parse(parent gast.Node, block text.Reader, pc parser
 | 
			
		||||
				}
 | 
			
		||||
				// 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])) {
 | 
			
		||||
				if len(line) > 1 && (unicode.IsDigit(before) || unicode.IsLetter(before)) && (unicode.IsLetter(util.ToRune(line, 1))) {
 | 
			
		||||
					node := gast.NewString(s.Substitutions[Apostrophe])
 | 
			
		||||
					node.SetCode(true)
 | 
			
		||||
					block.Advance(1)
 | 
			
		||||
@@ -215,16 +240,34 @@ func (s *typographerParser) Parse(parent gast.Node, block text.Reader, pc parser
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
			if s.Substitutions[LeftSingleQuote] != nil && d.CanOpen && !d.CanClose {
 | 
			
		||||
				node := gast.NewString(s.Substitutions[LeftSingleQuote])
 | 
			
		||||
				nt := LeftSingleQuote
 | 
			
		||||
				// special cases: Alice's, I'm ,Don't, You'd
 | 
			
		||||
				if len(line) > 1 && (line[1] == 's' || line[1] == 'm' || line[1] == 't' || line[1] == 'd') && (len(line) < 3 || util.IsPunct(line[2]) || util.IsSpace(line[2])) {
 | 
			
		||||
					nt = RightSingleQuote
 | 
			
		||||
				}
 | 
			
		||||
				// special cases: I've, I'll, You're
 | 
			
		||||
				if len(line) > 2 && ((line[1] == 'v' && line[2] == 'e') || (line[1] == 'l' && line[2] == 'l') || (line[1] == 'r' && line[2] == 'e')) && (len(line) < 4 || util.IsPunct(line[3]) || util.IsSpace(line[3])) {
 | 
			
		||||
					nt = RightSingleQuote
 | 
			
		||||
				}
 | 
			
		||||
				if nt == LeftSingleQuote {
 | 
			
		||||
					counter.Single++
 | 
			
		||||
				}
 | 
			
		||||
 | 
			
		||||
				node := gast.NewString(s.Substitutions[nt])
 | 
			
		||||
				node.SetCode(true)
 | 
			
		||||
				block.Advance(1)
 | 
			
		||||
				return node
 | 
			
		||||
			}
 | 
			
		||||
			if s.Substitutions[RightSingleQuote] != nil && d.CanClose && !d.CanOpen {
 | 
			
		||||
				node := gast.NewString(s.Substitutions[RightSingleQuote])
 | 
			
		||||
				node.SetCode(true)
 | 
			
		||||
				block.Advance(1)
 | 
			
		||||
				return node
 | 
			
		||||
			if s.Substitutions[RightSingleQuote] != nil && counter.Single > 0 {
 | 
			
		||||
				isClose := d.CanClose && !d.CanOpen
 | 
			
		||||
				maybeClose := d.CanClose && d.CanOpen && len(line) > 1 && (line[1] == ',' || line[1] == '.' || line[1] == '!' || line[1] == '?') && (len(line) == 2 || (len(line) > 2 && util.IsPunct(line[2]) || util.IsSpace(line[2])))
 | 
			
		||||
				if isClose || maybeClose {
 | 
			
		||||
					node := gast.NewString(s.Substitutions[RightSingleQuote])
 | 
			
		||||
					node.SetCode(true)
 | 
			
		||||
					block.Advance(1)
 | 
			
		||||
					counter.Single--
 | 
			
		||||
					return node
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
		if c == '"' {
 | 
			
		||||
@@ -232,13 +275,23 @@ func (s *typographerParser) Parse(parent gast.Node, block text.Reader, pc parser
 | 
			
		||||
				node := gast.NewString(s.Substitutions[LeftDoubleQuote])
 | 
			
		||||
				node.SetCode(true)
 | 
			
		||||
				block.Advance(1)
 | 
			
		||||
				counter.Double++
 | 
			
		||||
				return node
 | 
			
		||||
			}
 | 
			
		||||
			if s.Substitutions[RightDoubleQuote] != nil && d.CanClose && !d.CanOpen {
 | 
			
		||||
				node := gast.NewString(s.Substitutions[RightDoubleQuote])
 | 
			
		||||
				node.SetCode(true)
 | 
			
		||||
				block.Advance(1)
 | 
			
		||||
				return node
 | 
			
		||||
			if s.Substitutions[RightDoubleQuote] != nil && counter.Double > 0 {
 | 
			
		||||
				isClose := d.CanClose && !d.CanOpen
 | 
			
		||||
				maybeClose := d.CanClose && d.CanOpen && len(line) > 1 && (line[1] == ',' || line[1] == '.' || line[1] == '!' || line[1] == '?') && (len(line) == 2 || (len(line) > 2 && util.IsPunct(line[2]) || util.IsSpace(line[2])))
 | 
			
		||||
				if isClose || maybeClose {
 | 
			
		||||
					// special case: "Monitor 21""
 | 
			
		||||
					if len(line) > 1 && line[1] == '"' && unicode.IsDigit(before) {
 | 
			
		||||
						return nil
 | 
			
		||||
					}
 | 
			
		||||
					node := gast.NewString(s.Substitutions[RightDoubleQuote])
 | 
			
		||||
					node.SetCode(true)
 | 
			
		||||
					block.Advance(1)
 | 
			
		||||
					counter.Double--
 | 
			
		||||
					return node
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
@@ -246,7 +299,7 @@ func (s *typographerParser) Parse(parent gast.Node, block text.Reader, pc parser
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (s *typographerParser) CloseBlock(parent gast.Node, pc parser.Context) {
 | 
			
		||||
	// nothing to do
 | 
			
		||||
	getUnclosedCounter(pc).Reset()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type typographer struct {
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										5
									
								
								vendor/github.com/yuin/goldmark/parser/atx_heading.go
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										5
									
								
								vendor/github.com/yuin/goldmark/parser/atx_heading.go
									
									
									
										generated
									
									
										vendored
									
									
								
							@@ -126,7 +126,8 @@ func (b *atxHeadingParser) Open(parent ast.Node, reader text.Reader, pc Context)
 | 
			
		||||
		if closureClose > 0 {
 | 
			
		||||
			reader.Advance(closureClose)
 | 
			
		||||
			attrs, ok := ParseAttributes(reader)
 | 
			
		||||
			parsed = ok
 | 
			
		||||
			rest, _ := reader.PeekLine()
 | 
			
		||||
			parsed = ok && util.IsBlank(rest)
 | 
			
		||||
			if parsed {
 | 
			
		||||
				for _, attr := range attrs {
 | 
			
		||||
					node.SetAttribute(attr.Name, attr.Value)
 | 
			
		||||
@@ -232,7 +233,7 @@ func parseLastLineAttributes(node ast.Node, reader text.Reader, pc Context) {
 | 
			
		||||
		}
 | 
			
		||||
		lr.Advance(1)
 | 
			
		||||
	}
 | 
			
		||||
	if ok && util.IsBlank(line[end.Stop:]) {
 | 
			
		||||
	if ok && util.IsBlank(line[end.Start:]) {
 | 
			
		||||
		for _, attr := range attrs {
 | 
			
		||||
			node.SetAttribute(attr.Name, attr.Value)
 | 
			
		||||
		}
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										2
									
								
								vendor/github.com/yuin/goldmark/parser/html_block.go
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								vendor/github.com/yuin/goldmark/parser/html_block.go
									
									
									
										generated
									
									
										vendored
									
									
								
							@@ -93,7 +93,7 @@ var htmlBlockType5Close = []byte{']', ']', '>'}
 | 
			
		||||
 | 
			
		||||
var htmlBlockType6Regexp = regexp.MustCompile(`^[ ]{0,3}</?([a-zA-Z0-9]+)(?:\s.*|>.*|/>.*|)\n?$`)
 | 
			
		||||
 | 
			
		||||
var htmlBlockType7Regexp = regexp.MustCompile(`^[ ]{0,3}<(/)?([a-zA-Z0-9]+)(` + attributePattern + `*)(:?>|/>)\s*\n?$`)
 | 
			
		||||
var htmlBlockType7Regexp = regexp.MustCompile(`^[ ]{0,3}<(/)?([a-zA-Z0-9\-]+)(` + attributePattern + `*)(:?>|/>)\s*\n?$`)
 | 
			
		||||
 | 
			
		||||
type htmlBlockParser struct {
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										2
									
								
								vendor/github.com/yuin/goldmark/parser/list.go
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								vendor/github.com/yuin/goldmark/parser/list.go
									
									
									
										generated
									
									
										vendored
									
									
								
							@@ -191,7 +191,7 @@ func (b *listParser) Continue(node ast.Node, reader text.Reader, pc Context) Sta
 | 
			
		||||
					isHeading := false
 | 
			
		||||
					last := pc.LastOpenedBlock().Node
 | 
			
		||||
					if ast.IsParagraph(last) {
 | 
			
		||||
						c, ok := matchesSetextHeadingBar(line)
 | 
			
		||||
						c, ok := matchesSetextHeadingBar(line[match[3]-1:])
 | 
			
		||||
						if ok && c == '-' {
 | 
			
		||||
							isHeading = true
 | 
			
		||||
						}
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										2
									
								
								vendor/github.com/yuin/goldmark/util/util.go
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								vendor/github.com/yuin/goldmark/util/util.go
									
									
									
										generated
									
									
										vendored
									
									
								
							@@ -268,7 +268,7 @@ func FindClosure(bs []byte, opener, closure byte, codeSpan, allowNesting bool) i
 | 
			
		||||
			if codeSpanCloser == codeSpanOpener {
 | 
			
		||||
				codeSpanOpener = 0
 | 
			
		||||
			}
 | 
			
		||||
		} else if c == '\\' && i < len(bs)-1 && IsPunct(bs[i+1]) {
 | 
			
		||||
		} else if codeSpanOpener == 0 && c == '\\' && i < len(bs)-1 && IsPunct(bs[i+1]) {
 | 
			
		||||
			i += 2
 | 
			
		||||
			continue
 | 
			
		||||
		} else if codeSpan && codeSpanOpener == 0 && c == '`' {
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										2
									
								
								vendor/github.com/yuin/goldmark/util/util_safe.go
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								vendor/github.com/yuin/goldmark/util/util_safe.go
									
									
									
										generated
									
									
										vendored
									
									
								
							@@ -1,4 +1,4 @@
 | 
			
		||||
// +build appengine,js
 | 
			
		||||
// +build appengine js
 | 
			
		||||
 | 
			
		||||
package util
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										9
									
								
								vendor/github.com/yuin/goldmark/util/util_unsafe.go
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										9
									
								
								vendor/github.com/yuin/goldmark/util/util_unsafe.go
									
									
									
										generated
									
									
										vendored
									
									
								
							@@ -13,8 +13,11 @@ func BytesToReadOnlyString(b []byte) string {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// StringToReadOnlyBytes returns bytes converted from given string.
 | 
			
		||||
func StringToReadOnlyBytes(s string) []byte {
 | 
			
		||||
func StringToReadOnlyBytes(s string) (bs []byte) {
 | 
			
		||||
	sh := (*reflect.StringHeader)(unsafe.Pointer(&s))
 | 
			
		||||
	bh := reflect.SliceHeader{Data: sh.Data, Len: sh.Len, Cap: sh.Len}
 | 
			
		||||
	return *(*[]byte)(unsafe.Pointer(&bh))
 | 
			
		||||
	bh := (*reflect.SliceHeader)(unsafe.Pointer(&bs))
 | 
			
		||||
	bh.Data = sh.Data
 | 
			
		||||
	bh.Cap = sh.Len
 | 
			
		||||
	bh.Len = sh.Len
 | 
			
		||||
	return
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user