diff --git a/fuzz/fuzz.go b/fuzz/fuzz.go index f56dec6..629f5cc 100644 --- a/fuzz/fuzz.go +++ b/fuzz/fuzz.go @@ -2,11 +2,13 @@ package fuzz import ( "bytes" + "github.com/yuin/goldmark" "github.com/yuin/goldmark/extension" "github.com/yuin/goldmark/renderer/html" ) +// Fuzz runs automated fuzzing against goldmark. func Fuzz(data []byte) int { markdown := goldmark.New( goldmark.WithRendererOptions( diff --git a/parser/html_block.go b/parser/html_block.go index 752ba08..c796354 100644 --- a/parser/html_block.go +++ b/parser/html_block.go @@ -2,11 +2,12 @@ package parser import ( "bytes" + "regexp" + "strings" + "github.com/yuin/goldmark/ast" "github.com/yuin/goldmark/text" "github.com/yuin/goldmark/util" - "regexp" - "strings" ) var allowedBlockTags = map[string]bool{ @@ -97,12 +98,12 @@ var htmlBlockType7Regexp = regexp.MustCompile(`^[ ]{0,3}<(/)?([a-zA-Z0-9]+)(` + type htmlBlockParser struct { } -var defaultHtmlBlockParser = &htmlBlockParser{} +var defaultHTMLBlockParser = &htmlBlockParser{} // NewHTMLBlockParser return a new BlockParser that can parse html // blocks. func NewHTMLBlockParser() BlockParser { - return defaultHtmlBlockParser + return defaultHTMLBlockParser } func (b *htmlBlockParser) Trigger() []byte { diff --git a/parser/thematic_break.go b/parser/thematic_break.go index 2f5c9fa..4d0d8da 100644 --- a/parser/thematic_break.go +++ b/parser/thematic_break.go @@ -11,7 +11,7 @@ type thematicBreakPraser struct { var defaultThematicBreakPraser = &thematicBreakPraser{} -// NewThematicBreakPraser returns a new BlockParser that +// NewThematicBreakParser returns a new BlockParser that // parses thematic breaks. func NewThematicBreakParser() BlockParser { return defaultThematicBreakPraser diff --git a/renderer/renderer.go b/renderer/renderer.go index 1681305..5c11ceb 100644 --- a/renderer/renderer.go +++ b/renderer/renderer.go @@ -1,14 +1,13 @@ -// Package renderer renders the given AST to certain formats. +// Package renderer renders the given AST to certain formats. package renderer import ( "bufio" "io" + "sync" "github.com/yuin/goldmark/ast" "github.com/yuin/goldmark/util" - - "sync" ) // A Config struct is a data structure that holds configuration of the Renderer. diff --git a/testutil/testutil.go b/testutil/testutil.go index 4a83a03..4b9cff6 100644 --- a/testutil/testutil.go +++ b/testutil/testutil.go @@ -21,6 +21,7 @@ type TestingT interface { FailNow() } +// MarkdownTestCase represents a test case. type MarkdownTestCase struct { No int Markdown string @@ -30,6 +31,7 @@ type MarkdownTestCase struct { const attributeSeparator = "//- - - - - - - - -//" const caseSeparator = "//= = = = = = = = = = = = = = = = = = = = = = = =//" +// DoTestCaseFile runs test cases in a given file. func DoTestCaseFile(m goldmark.Markdown, filename string, t TestingT) { fp, err := os.Open(filename) if err != nil { @@ -86,12 +88,14 @@ func DoTestCaseFile(m goldmark.Markdown, filename string, t TestingT) { DoTestCases(m, cases, t) } +// DoTestCases runs a set of test cases. func DoTestCases(m goldmark.Markdown, cases []MarkdownTestCase, t TestingT) { for _, testCase := range cases { DoTestCase(m, testCase, t) } } +// DoTestCase runs a test case. func DoTestCase(m goldmark.Markdown, testCase MarkdownTestCase, t TestingT) { var ok bool var out bytes.Buffer diff --git a/text/reader.go b/text/reader.go index 0e2c3f0..a8db23b 100644 --- a/text/reader.go +++ b/text/reader.go @@ -1,10 +1,11 @@ package text import ( - "github.com/yuin/goldmark/util" "io" "regexp" "unicode/utf8" + + "github.com/yuin/goldmark/util" ) const invalidValue = -1 @@ -138,7 +139,7 @@ func (r *reader) LineOffset() int { if r.source[i] == '\t' { v += util.TabWidth(v) } else { - v += 1 + v++ } } r.lineOffset = v - r.pos.Padding @@ -355,7 +356,7 @@ func (r *blockReader) LineOffset() int { if r.source[i] == '\t' { v += util.TabWidth(v) } else { - v += 1 + v++ } } r.lineOffset = v - r.pos.Padding diff --git a/util/util.go b/util/util.go index 57a2b84..74f991b 100644 --- a/util/util.go +++ b/util/util.go @@ -631,7 +631,7 @@ func URLEscape(v []byte, resolveReference bool) []byte { cob.Write(v[n:i]) stop := i + int(u8len) if stop > len(v) { - i += 1 + i++ n = i continue }