Skip to content

Commit

Permalink
address staticcheck issues
Browse files Browse the repository at this point in the history
  • Loading branch information
kjk committed May 27, 2022
1 parent b8a3b38 commit c89a3d3
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 104 deletions.
81 changes: 0 additions & 81 deletions html/renderer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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] == '#' {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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("../")}
Expand Down
20 changes: 0 additions & 20 deletions md/md_renderer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions parser/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions parser/inline.go
Original file line number Diff line number Diff line change
Expand Up @@ -1118,6 +1118,7 @@ func isMailtoAutoLink(data []byte) int {
case '@':
nb++

/* TODO: was this supposed to be return 0? */
case '-', '.', '_':
break

Expand Down
3 changes: 2 additions & 1 deletion parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"fmt"
"strconv"
"strings"
"unicode/utf8"

"github.com/gomarkdown/markdown/ast"
)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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).
Expand Down

0 comments on commit c89a3d3

Please sign in to comment.