diff options
Diffstat (limited to 'vendor/github.com/yuin/goldmark/parser')
9 files changed, 41 insertions, 31 deletions
diff --git a/vendor/github.com/yuin/goldmark/parser/attribute.go b/vendor/github.com/yuin/goldmark/parser/attribute.go index f86c83610..42985f4f7 100644 --- a/vendor/github.com/yuin/goldmark/parser/attribute.go +++ b/vendor/github.com/yuin/goldmark/parser/attribute.go @@ -12,7 +12,7 @@ import ( var attrNameID = []byte("id") var attrNameClass = []byte("class") -// An Attribute is an attribute of the markdown elements +// An Attribute is an attribute of the markdown elements. type Attribute struct { Name []byte Value interface{} @@ -93,7 +93,8 @@ func parseAttribute(reader text.Reader) (Attribute, bool) { // CommonMark is basically defined for XHTML(even though it is legacy). // So we restrict id characters. for ; i < len(line) && !util.IsSpace(line[i]) && - (!util.IsPunct(line[i]) || line[i] == '_' || line[i] == '-' || line[i] == ':' || line[i] == '.'); i++ { + (!util.IsPunct(line[i]) || line[i] == '_' || + line[i] == '-' || line[i] == ':' || line[i] == '.'); i++ { } name := attrNameClass if c == '#' { @@ -145,7 +146,7 @@ func parseAttributeValue(reader text.Reader) (interface{}, bool) { reader.SkipSpaces() c := reader.Peek() var value interface{} - ok := false + var ok bool switch c { case text.EOF: return Attribute{}, false @@ -244,7 +245,7 @@ func scanAttributeDecimal(reader text.Reader, w io.ByteWriter) { for { c := reader.Peek() if util.IsNumeric(c) { - w.WriteByte(c) + _ = w.WriteByte(c) } else { return } @@ -286,7 +287,7 @@ func parseAttributeNumber(reader text.Reader) (float64, bool) { } scanAttributeDecimal(reader, &buf) } - f, err := strconv.ParseFloat(buf.String(), 10) + f, err := strconv.ParseFloat(buf.String(), 64) if err != nil { return 0, false } diff --git a/vendor/github.com/yuin/goldmark/parser/atx_heading.go b/vendor/github.com/yuin/goldmark/parser/atx_heading.go index 13a198b52..dae5e84af 100644 --- a/vendor/github.com/yuin/goldmark/parser/atx_heading.go +++ b/vendor/github.com/yuin/goldmark/parser/atx_heading.go @@ -13,7 +13,7 @@ type HeadingConfig struct { } // SetOption implements SetOptioner. -func (b *HeadingConfig) SetOption(name OptionName, value interface{}) { +func (b *HeadingConfig) SetOption(name OptionName, _ interface{}) { switch name { case optAutoHeadingID: b.AutoHeadingID = true @@ -135,7 +135,9 @@ func (b *atxHeadingParser) Open(parent ast.Node, reader text.Reader, pc Context) for _, attr := range attrs { node.SetAttribute(attr.Name, attr.Value) } - node.Lines().Append(text.NewSegment(segment.Start+start+1-segment.Padding, segment.Start+closureOpen-segment.Padding)) + node.Lines().Append(text.NewSegment( + segment.Start+start+1-segment.Padding, + segment.Start+closureOpen-segment.Padding)) } } } diff --git a/vendor/github.com/yuin/goldmark/parser/delimiter.go b/vendor/github.com/yuin/goldmark/parser/delimiter.go index eb843af44..d097e3fb3 100644 --- a/vendor/github.com/yuin/goldmark/parser/delimiter.go +++ b/vendor/github.com/yuin/goldmark/parser/delimiter.go @@ -66,12 +66,12 @@ func (d *Delimiter) Dump(source []byte, level int) { var kindDelimiter = ast.NewNodeKind("Delimiter") -// Kind implements Node.Kind +// Kind implements Node.Kind. func (d *Delimiter) Kind() ast.NodeKind { return kindDelimiter } -// Text implements Node.Text +// Text implements Node.Text. func (d *Delimiter) Text(source []byte) []byte { return d.Segment.Value(source) } @@ -126,7 +126,7 @@ func ScanDelimiter(line []byte, before rune, min int, processor DelimiterProcess after = util.ToRune(line, j) } - canOpen, canClose := false, false + var canOpen, canClose bool beforeIsPunctuation := util.IsPunctRune(before) beforeIsWhitespace := util.IsSpaceRune(before) afterIsPunctuation := util.IsPunctRune(after) diff --git a/vendor/github.com/yuin/goldmark/parser/html_block.go b/vendor/github.com/yuin/goldmark/parser/html_block.go index 6881e25a9..bf0258b5d 100644 --- a/vendor/github.com/yuin/goldmark/parser/html_block.go +++ b/vendor/github.com/yuin/goldmark/parser/html_block.go @@ -76,7 +76,7 @@ var allowedBlockTags = map[string]bool{ "ul": true, } -var htmlBlockType1OpenRegexp = regexp.MustCompile(`(?i)^[ ]{0,3}<(script|pre|style|textarea)(?:\s.*|>.*|/>.*|)(?:\r\n|\n)?$`) +var htmlBlockType1OpenRegexp = regexp.MustCompile(`(?i)^[ ]{0,3}<(script|pre|style|textarea)(?:\s.*|>.*|/>.*|)(?:\r\n|\n)?$`) //nolint:golint,lll var htmlBlockType1CloseRegexp = regexp.MustCompile(`(?i)^.*</(?:script|pre|style|textarea)>.*`) var htmlBlockType2OpenRegexp = regexp.MustCompile(`^[ ]{0,3}<!\-\-`) @@ -91,9 +91,9 @@ var htmlBlockType4Close = []byte{'>'} var htmlBlockType5OpenRegexp = regexp.MustCompile(`^[ ]{0,3}<\!\[CDATA\[`) var htmlBlockType5Close = []byte{']', ']', '>'} -var htmlBlockType6Regexp = regexp.MustCompile(`^[ ]{0,3}<(?:/[ ]*)?([a-zA-Z]+[a-zA-Z0-9\-]*)(?:[ ].*|>.*|/>.*|)(?:\r\n|\n)?$`) +var htmlBlockType6Regexp = regexp.MustCompile(`^[ ]{0,3}<(?:/[ ]*)?([a-zA-Z]+[a-zA-Z0-9\-]*)(?:[ ].*|>.*|/>.*|)(?:\r\n|\n)?$`) //nolint:golint,lll -var htmlBlockType7Regexp = regexp.MustCompile(`^[ ]{0,3}<(/[ ]*)?([a-zA-Z]+[a-zA-Z0-9\-]*)(` + attributePattern + `*)[ ]*(?:>|/>)[ ]*(?:\r\n|\n)?$`) +var htmlBlockType7Regexp = regexp.MustCompile(`^[ ]{0,3}<(/[ ]*)?([a-zA-Z]+[a-zA-Z0-9\-]*)(` + attributePattern + `*)[ ]*(?:>|/>)[ ]*(?:\r\n|\n)?$`) //nolint:golint,lll type htmlBlockParser struct { } @@ -135,7 +135,8 @@ func (b *htmlBlockParser) Open(parent ast.Node, reader text.Reader, pc Context) _, ok := allowedBlockTags[tagName] if ok { node = ast.NewHTMLBlock(ast.HTMLBlockType6) - } else if tagName != "script" && tagName != "style" && tagName != "pre" && !ast.IsParagraph(last) && !(isCloseTag && hasAttr) { // type 7 can not interrupt paragraph + } else if tagName != "script" && tagName != "style" && + tagName != "pre" && !ast.IsParagraph(last) && !(isCloseTag && hasAttr) { // type 7 can not interrupt paragraph node = ast.NewHTMLBlock(ast.HTMLBlockType7) } } diff --git a/vendor/github.com/yuin/goldmark/parser/link.go b/vendor/github.com/yuin/goldmark/parser/link.go index 99583ac2a..57840bdfb 100644 --- a/vendor/github.com/yuin/goldmark/parser/link.go +++ b/vendor/github.com/yuin/goldmark/parser/link.go @@ -250,7 +250,8 @@ var linkFindClosureOptions text.FindClosureOptions = text.FindClosureOptions{ Advance: true, } -func (s *linkParser) parseReferenceLink(parent ast.Node, last *linkLabelState, block text.Reader, pc Context) (*ast.Link, bool) { +func (s *linkParser) parseReferenceLink(parent ast.Node, last *linkLabelState, + block text.Reader, pc Context) (*ast.Link, bool) { _, orgpos := block.Position() block.Advance(1) // skip '[' segments, found := block.FindClosure('[', ']', linkFindClosureOptions) diff --git a/vendor/github.com/yuin/goldmark/parser/list.go b/vendor/github.com/yuin/goldmark/parser/list.go index e5cad1173..3e0eea6d7 100644 --- a/vendor/github.com/yuin/goldmark/parser/list.go +++ b/vendor/github.com/yuin/goldmark/parser/list.go @@ -22,7 +22,7 @@ var listItemFlagValue interface{} = true // Same as // `^(([ ]*)([\-\*\+]))(\s+.*)?\n?$`.FindSubmatchIndex or -// `^(([ ]*)(\d{1,9}[\.\)]))(\s+.*)?\n?$`.FindSubmatchIndex +// `^(([ ]*)(\d{1,9}[\.\)]))(\s+.*)?\n?$`.FindSubmatchIndex. func parseListItem(line []byte) ([6]int, listItemType) { i := 0 l := len(line) @@ -89,7 +89,7 @@ func matchesListItem(source []byte, strict bool) ([6]int, listItemType) { } func calcListOffset(source []byte, match [6]int) int { - offset := 0 + var offset int if match[4] < 0 || util.IsBlank(source[match[4]:]) { // list item starts with a blank line offset = 1 } else { @@ -250,14 +250,14 @@ func (b *listParser) Close(node ast.Node, reader text.Reader, pc Context) { for c := node.FirstChild(); c != nil && list.IsTight; c = c.NextSibling() { if c.FirstChild() != nil && c.FirstChild() != c.LastChild() { for c1 := c.FirstChild().NextSibling(); c1 != nil; c1 = c1.NextSibling() { - if bl, ok := c1.(ast.Node); ok && bl.HasBlankPreviousLines() { + if c1.HasBlankPreviousLines() { list.IsTight = false break } } } if c != node.FirstChild() { - if bl, ok := c.(ast.Node); ok && bl.HasBlankPreviousLines() { + if c.HasBlankPreviousLines() { list.IsTight = false } } diff --git a/vendor/github.com/yuin/goldmark/parser/parser.go b/vendor/github.com/yuin/goldmark/parser/parser.go index a82369266..5cc2175f9 100644 --- a/vendor/github.com/yuin/goldmark/parser/parser.go +++ b/vendor/github.com/yuin/goldmark/parser/parser.go @@ -403,7 +403,8 @@ func (p *parseContext) IsInLinkLabel() bool { type State int const ( - none State = 1 << iota + // None is a default value of the [State]. + None State = 1 << iota // Continue indicates parser can continue parsing. Continue @@ -1049,7 +1050,7 @@ func isBlankLine(lineNum, level int, stats []lineStat) bool { func (p *parser) parseBlocks(parent ast.Node, reader text.Reader, pc Context) { pc.SetOpenedBlocks([]Block{}) blankLines := make([]lineStat, 0, 128) - isBlank := false + var isBlank bool for { // process blocks separated by blank lines _, lines, ok := reader.SkipBlankLines() if !ok { @@ -1152,18 +1153,23 @@ func (p *parser) parseBlock(block text.BlockReader, parent ast.Node, pc Context) break } lineLength := len(line) - var lineBreakFlags uint8 = 0 + var lineBreakFlags uint8 hasNewLine := line[lineLength-1] == '\n' - if ((lineLength >= 3 && line[lineLength-2] == '\\' && line[lineLength-3] != '\\') || (lineLength == 2 && line[lineLength-2] == '\\')) && hasNewLine { // ends with \\n + if ((lineLength >= 3 && line[lineLength-2] == '\\' && + line[lineLength-3] != '\\') || (lineLength == 2 && line[lineLength-2] == '\\')) && hasNewLine { // ends with \\n lineLength -= 2 lineBreakFlags |= lineBreakHard | lineBreakVisible - } else if ((lineLength >= 4 && line[lineLength-3] == '\\' && line[lineLength-2] == '\r' && line[lineLength-4] != '\\') || (lineLength == 3 && line[lineLength-3] == '\\' && line[lineLength-2] == '\r')) && hasNewLine { // ends with \\r\n + } else if ((lineLength >= 4 && line[lineLength-3] == '\\' && line[lineLength-2] == '\r' && + line[lineLength-4] != '\\') || (lineLength == 3 && line[lineLength-3] == '\\' && line[lineLength-2] == '\r')) && + hasNewLine { // ends with \\r\n lineLength -= 3 lineBreakFlags |= lineBreakHard | lineBreakVisible - } else if lineLength >= 3 && line[lineLength-3] == ' ' && line[lineLength-2] == ' ' && hasNewLine { // ends with [space][space]\n + } else if lineLength >= 3 && line[lineLength-3] == ' ' && line[lineLength-2] == ' ' && + hasNewLine { // ends with [space][space]\n lineLength -= 3 lineBreakFlags |= lineBreakHard - } else if lineLength >= 4 && line[lineLength-4] == ' ' && line[lineLength-3] == ' ' && line[lineLength-2] == '\r' && hasNewLine { // ends with [space][space]\r\n + } else if lineLength >= 4 && line[lineLength-4] == ' ' && line[lineLength-3] == ' ' && + line[lineLength-2] == '\r' && hasNewLine { // ends with [space][space]\r\n lineLength -= 4 lineBreakFlags |= lineBreakHard } else if hasNewLine { diff --git a/vendor/github.com/yuin/goldmark/parser/raw_html.go b/vendor/github.com/yuin/goldmark/parser/raw_html.go index cae88a66e..2b3dbc23d 100644 --- a/vendor/github.com/yuin/goldmark/parser/raw_html.go +++ b/vendor/github.com/yuin/goldmark/parser/raw_html.go @@ -15,7 +15,7 @@ type rawHTMLParser struct { var defaultRawHTMLParser = &rawHTMLParser{} // NewRawHTMLParser return a new InlineParser that can parse -// inline htmls +// inline htmls. func NewRawHTMLParser() InlineParser { return defaultRawHTMLParser } @@ -49,7 +49,7 @@ func (s *rawHTMLParser) Parse(parent ast.Node, block text.Reader, pc Context) as var tagnamePattern = `([A-Za-z][A-Za-z0-9-]*)` var spaceOrOneNewline = `(?:[ \t]|(?:\r\n|\n){0,1})` -var attributePattern = `(?:[\r\n \t]+[a-zA-Z_:][a-zA-Z0-9:._-]*(?:[\r\n \t]*=[\r\n \t]*(?:[^\"'=<>` + "`" + `\x00-\x20]+|'[^']*'|"[^"]*"))?)` +var attributePattern = `(?:[\r\n \t]+[a-zA-Z_:][a-zA-Z0-9:._-]*(?:[\r\n \t]*=[\r\n \t]*(?:[^\"'=<>` + "`" + `\x00-\x20]+|'[^']*'|"[^"]*"))?)` //nolint:golint,lll var openTagRegexp = regexp.MustCompile("^<" + tagnamePattern + attributePattern + `*` + spaceOrOneNewline + `*/?>`) var closeTagRegexp = regexp.MustCompile("^</" + tagnamePattern + spaceOrOneNewline + `*>`) @@ -153,9 +153,8 @@ func (s *rawHTMLParser) parseMultiLineRegexp(reg *regexp.Regexp, block text.Read if l == eline { block.Advance(end - start) break - } else { - block.AdvanceLine() } + block.AdvanceLine() } return node } diff --git a/vendor/github.com/yuin/goldmark/parser/setext_headings.go b/vendor/github.com/yuin/goldmark/parser/setext_headings.go index 686efe179..915bcc124 100644 --- a/vendor/github.com/yuin/goldmark/parser/setext_headings.go +++ b/vendor/github.com/yuin/goldmark/parser/setext_headings.go @@ -91,7 +91,7 @@ func (b *setextHeadingParser) Close(node ast.Node, reader text.Reader, pc Contex para.Lines().Append(segment) heading.Parent().InsertAfter(heading.Parent(), heading, para) } else { - next.(ast.Node).Lines().Unshift(segment) + next.Lines().Unshift(segment) } heading.Parent().RemoveChild(heading.Parent(), heading) } else { |