From c89a3d3cd9b5aca0ce0499d3868d94b1cf56f87b Mon Sep 17 00:00:00 2001 From: Krzysztof Kowalczyk Date: Fri, 27 May 2022 20:55:12 +0000 Subject: [PATCH] address staticcheck issues --- html/renderer.go | 81 ----------------------------------------------- md/md_renderer.go | 20 ------------ parser/block.go | 4 +-- parser/inline.go | 1 + parser/parser.go | 3 +- 5 files changed, 5 insertions(+), 104 deletions(-) diff --git a/html/renderer.go b/html/renderer.go index 6886857..0d5ac07 100644 --- a/html/renderer.go +++ b/html/renderer.go @@ -211,70 +211,6 @@ func NewRenderer(opts RendererOptions) *Renderer { } } -func isHTMLTag(tag []byte, tagname string) bool { - found, _ := findHTMLTagPos(tag, tagname) - return found -} - -// Look for a character, but ignore it when it's in any kind of quotes, it -// might be JavaScript -func skipUntilCharIgnoreQuotes(html []byte, start int, char byte) int { - inSingleQuote := false - inDoubleQuote := false - inGraveQuote := false - i := start - for i < len(html) { - switch { - case html[i] == char && !inSingleQuote && !inDoubleQuote && !inGraveQuote: - return i - case html[i] == '\'': - inSingleQuote = !inSingleQuote - case html[i] == '"': - inDoubleQuote = !inDoubleQuote - case html[i] == '`': - inGraveQuote = !inGraveQuote - } - i++ - } - return start -} - -func findHTMLTagPos(tag []byte, tagname string) (bool, int) { - i := 0 - if i < len(tag) && tag[0] != '<' { - return false, -1 - } - i++ - i = skipSpace(tag, i) - - if i < len(tag) && tag[i] == '/' { - i++ - } - - i = skipSpace(tag, i) - j := 0 - for ; i < len(tag); i, j = i+1, j+1 { - if j >= len(tagname) { - break - } - - if strings.ToLower(string(tag[i]))[0] != tagname[j] { - return false, -1 - } - } - - if i == len(tag) { - return false, -1 - } - - rightAngle := skipUntilCharIgnoreQuotes(tag, i, '>') - if rightAngle >= i { - return true, rightAngle - } - - return false, -1 -} - func isRelativeLink(link []byte) (yes bool) { // a tag begin with '#' if link[0] == '#' { @@ -351,14 +287,6 @@ func needSkipLink(flags Flags, dest []byte) bool { return flags&Safelink != 0 && !isSafeLink(dest) && !isMailto(dest) } -func isSmartypantable(node ast.Node) bool { - switch node.GetParent().(type) { - case *ast.Link, *ast.CodeBlock, *ast.Code: - return false - } - return true -} - func appendLanguageAttr(attrs []string, info []byte) []string { if len(info) == 0 { return attrs @@ -1297,15 +1225,6 @@ func isListItemTerm(node ast.Node) bool { return ok && data.ListFlags&ast.ListTypeTerm != 0 } -// TODO: move to internal package -func skipSpace(data []byte, i int) int { - n := len(data) - for i < n && isSpace(data[i]) { - i++ - } - return i -} - // TODO: move to internal package var validUris = [][]byte{[]byte("http://"), []byte("https://"), []byte("ftp://"), []byte("mailto://")} var validPaths = [][]byte{[]byte("/"), []byte("./"), []byte("../")} diff --git a/md/md_renderer.go b/md/md_renderer.go index 720bcdc..83c12ba 100644 --- a/md/md_renderer.go +++ b/md/md_renderer.go @@ -42,12 +42,6 @@ func (r *Renderer) outs(w io.Writer, s string) { io.WriteString(w, s) } -func (r *Renderer) cr(w io.Writer) { - if r.lastOutputLen > 0 { - r.outs(w, "\n") - } -} - func (r *Renderer) doubleSpace(w io.Writer) { // TODO: need to remember number of written bytes //if out.Len() > 0 { @@ -196,14 +190,6 @@ func (r *Renderer) surround(w io.Writer, symbol string) { r.outs(w, symbol) } -func (r *Renderer) enclose(w io.Writer, entering bool, fst, snd string) { - if entering { - r.outs(w, fst) - } else { - r.outs(w, snd) - } -} - func (r *Renderer) htmlSpan(w io.Writer, node *ast.HTMLSpan) { r.out(w, node.Literal) } @@ -381,12 +367,6 @@ func (r *Renderer) RenderNode(w io.Writer, node ast.Node, entering bool) ast.Wal return ast.GoToNext } -func ifThen(entering bool, w io.Writer, node *ast.Text, f func(w io.Writer, text *ast.Text)) { - if entering { - f(w, node) - } -} - // RenderHeader renders header func (r *Renderer) RenderHeader(w io.Writer, ast ast.Node) { // do nothing diff --git a/parser/block.go b/parser/block.go index dee173f..eeebec7 100644 --- a/parser/block.go +++ b/parser/block.go @@ -24,8 +24,8 @@ const ( ) var ( - reBackslashOrAmp = regexp.MustCompile("[\\&]") - reEntityOrEscapedChar = regexp.MustCompile("(?i)\\\\" + escapable + "|" + charEntity) + reBackslashOrAmp = regexp.MustCompile(`[\&]`) + reEntityOrEscapedChar = regexp.MustCompile(`(?i)\\` + escapable + "|" + charEntity) // blockTags is a set of tags that are recognized as HTML block tags. // Any of these can be included in markdown text without special escaping. diff --git a/parser/inline.go b/parser/inline.go index 1f23935..447ea06 100644 --- a/parser/inline.go +++ b/parser/inline.go @@ -1118,6 +1118,7 @@ func isMailtoAutoLink(data []byte) int { case '@': nb++ + /* TODO: was this supposed to be return 0? */ case '-', '.', '_': break diff --git a/parser/parser.go b/parser/parser.go index 7712a29..eb63a91 100644 --- a/parser/parser.go +++ b/parser/parser.go @@ -8,7 +8,6 @@ import ( "fmt" "strconv" "strings" - "unicode/utf8" "github.com/gomarkdown/markdown/ast" ) @@ -720,6 +719,7 @@ func isAlnum(c byte) bool { // TODO: this is not used // Replace tab characters with spaces, aligning to the next TAB_SIZE column. // always ends output with a newline +/* func expandTabs(out *bytes.Buffer, line []byte, tabSize int) { // first, check for common cases: no tabs, or only tabs at beginning of line i, prefix := 0, 0 @@ -775,6 +775,7 @@ func expandTabs(out *bytes.Buffer, line []byte, tabSize int) { i++ } } +*/ // Find if a line counts as indented or not. // Returns number of characters the indent is (0 = not indented).