Bump up CommonMark Spec to 0.31.2

This commit is contained in:
yuin 2024-02-02 21:13:09 +09:00
parent 90c46e0829
commit b8d6d3a9b7
5 changed files with 1610 additions and 1619 deletions

View file

@ -8,7 +8,7 @@ goldmark
> A Markdown parser written in Go. Easy to extend, standards-compliant, well-structured. > A Markdown parser written in Go. Easy to extend, standards-compliant, well-structured.
goldmark is compliant with CommonMark 0.30. goldmark is compliant with CommonMark 0.31.2.
Motivation Motivation
---------------------- ----------------------

File diff suppressed because it is too large Load diff

View file

@ -61,8 +61,8 @@ var allowedBlockTags = map[string]bool{
"option": true, "option": true,
"p": true, "p": true,
"param": true, "param": true,
"search": true,
"section": true, "section": true,
"source": true,
"summary": true, "summary": true,
"table": true, "table": true,
"tbody": true, "tbody": true,

View file

@ -58,47 +58,38 @@ var closeProcessingInstruction = []byte("?>")
var openCDATA = []byte("<![CDATA[") var openCDATA = []byte("<![CDATA[")
var closeCDATA = []byte("]]>") var closeCDATA = []byte("]]>")
var closeDecl = []byte(">") var closeDecl = []byte(">")
var emptyComment = []byte("<!---->") var emptyComment1 = []byte("<!-->")
var invalidComment1 = []byte("<!-->") var emptyComment2 = []byte("<!--->")
var invalidComment2 = []byte("<!--->")
var openComment = []byte("<!--") var openComment = []byte("<!--")
var closeComment = []byte("-->") var closeComment = []byte("-->")
var doubleHyphen = []byte("--")
func (s *rawHTMLParser) parseComment(block text.Reader, pc Context) ast.Node { func (s *rawHTMLParser) parseComment(block text.Reader, pc Context) ast.Node {
savedLine, savedSegment := block.Position() savedLine, savedSegment := block.Position()
node := ast.NewRawHTML() node := ast.NewRawHTML()
line, segment := block.PeekLine() line, segment := block.PeekLine()
if bytes.HasPrefix(line, emptyComment) { if bytes.HasPrefix(line, emptyComment1) {
node.Segments.Append(segment.WithStop(segment.Start + len(emptyComment))) node.Segments.Append(segment.WithStop(segment.Start + len(emptyComment1)))
block.Advance(len(emptyComment)) block.Advance(len(emptyComment1))
return node return node
} }
if bytes.HasPrefix(line, invalidComment1) || bytes.HasPrefix(line, invalidComment2) { if bytes.HasPrefix(line, emptyComment2) {
return nil node.Segments.Append(segment.WithStop(segment.Start + len(emptyComment2)))
block.Advance(len(emptyComment2))
return node
} }
offset := len(openComment) offset := len(openComment)
line = line[offset:] line = line[offset:]
for { for {
hindex := bytes.Index(line, doubleHyphen) index := bytes.Index(line, closeComment)
if hindex > -1 { if index > -1 {
hindex += offset node.Segments.Append(segment.WithStop(segment.Start + offset + index + len(closeComment)))
} block.Advance(offset + index + len(closeComment))
index := bytes.Index(line, closeComment) + offset return node
if index > -1 && hindex == index {
if index == 0 || len(line) < 2 || line[index-offset-1] != '-' {
node.Segments.Append(segment.WithStop(segment.Start + index + len(closeComment)))
block.Advance(index + len(closeComment))
return node
}
}
if hindex > 0 {
break
} }
offset = 0
node.Segments.Append(segment) node.Segments.Append(segment)
block.AdvanceLine() block.AdvanceLine()
line, segment = block.PeekLine() line, segment = block.PeekLine()
offset = 0
if line == nil { if line == nil {
break break
} }

View file

@ -808,7 +808,7 @@ func IsPunct(c byte) bool {
// IsPunctRune returns true if the given rune is a punctuation, otherwise false. // IsPunctRune returns true if the given rune is a punctuation, otherwise false.
func IsPunctRune(r rune) bool { func IsPunctRune(r rune) bool {
return int32(r) <= 256 && IsPunct(byte(r)) || unicode.IsPunct(r) return unicode.IsSymbol(r) || unicode.IsPunct(r)
} }
// IsSpace returns true if the given character is a space, otherwise false. // IsSpace returns true if the given character is a space, otherwise false.