Simplify code

This commit is contained in:
Manuel Rüger 2023-06-19 15:35:09 +02:00
parent fa6bebc584
commit adf4a91f02
9 changed files with 22 additions and 22 deletions

View file

@ -91,7 +91,7 @@ func (n *Text) SetSoftLineBreak(v bool) {
if v {
n.flags |= textSoftLineBreak
} else {
n.flags = n.flags &^ textSoftLineBreak
n.flags &^= textSoftLineBreak
}
}
@ -106,7 +106,7 @@ func (n *Text) SetRaw(v bool) {
if v {
n.flags |= textRaw
} else {
n.flags = n.flags &^ textRaw
n.flags &^= textRaw
}
}
@ -121,7 +121,7 @@ func (n *Text) SetHardLineBreak(v bool) {
if v {
n.flags |= textHardLineBreak
} else {
n.flags = n.flags &^ textHardLineBreak
n.flags &^= textHardLineBreak
}
}
@ -237,7 +237,7 @@ func (n *String) SetRaw(v bool) {
if v {
n.flags |= textRaw
} else {
n.flags = n.flags &^ textRaw
n.flags &^= textRaw
}
}
@ -252,7 +252,7 @@ func (n *String) SetCode(v bool) {
if v {
n.flags |= textCode
} else {
n.flags = n.flags &^ textCode
n.flags &^= textCode
}
}

View file

@ -229,7 +229,7 @@ func (a *footnoteASTTransformer) Transform(node *gast.Document, reader text.Read
}
}
for footnote := list.FirstChild(); footnote != nil; {
var container gast.Node = footnote
var container = footnote
next := footnote.NextSibling()
if fc := container.LastChild(); fc != nil && gast.IsParagraph(fc) {
container = fc
@ -649,8 +649,8 @@ func applyFootnoteTemplate(b []byte, index, refCount int) []byte {
}
is := []byte(strconv.Itoa(index))
rs := []byte(strconv.Itoa(refCount))
ret := bytes.Replace(b, []byte("^^"), is, -1)
return bytes.Replace(ret, []byte("%%"), rs, -1)
ret := bytes.ReplaceAll(b, []byte("^^"), is)
return bytes.ReplaceAll(ret, []byte("%%"), rs)
}
type footnote struct {

View file

@ -182,7 +182,7 @@ func (s *linkifyParser) Parse(parent ast.Node, block text.Reader, pc parser.Cont
var m []int
var protocol []byte
var typ ast.AutoLinkType = ast.AutoLinkURL
var typ = ast.AutoLinkURL
if s.LinkifyConfig.AllowedProtocols == nil {
if bytes.HasPrefix(line, protoHTTP) || bytes.HasPrefix(line, protoHTTPS) || bytes.HasPrefix(line, protoFTP) {
m = s.LinkifyConfig.URLRegexp.FindSubmatchIndex(line)

View file

@ -175,7 +175,7 @@ func (b *tableParagraphTransformer) Transform(node *gast.Paragraph, reader text.
node.Parent().RemoveChild(node.Parent(), node)
} else {
last := node.Lines().At(i - 2)
last.Stop = last.Stop - 1 // trim last newline(\n)
last.Stop-- // trim last newline(\n)
node.Lines().Set(i-2, last)
}
}

View file

@ -24,7 +24,7 @@ func (s *autoLinkParser) Trigger() []byte {
func (s *autoLinkParser) Parse(parent ast.Node, block text.Reader, pc Context) ast.Node {
line, segment := block.PeekLine()
stop := util.FindEmailIndex(line[1:])
typ := ast.AutoLinkType(ast.AutoLinkEmail)
typ := ast.AutoLinkEmail
if stop < 0 {
stop = util.FindURLIndex(line[1:])
typ = ast.AutoLinkURL

View file

@ -147,7 +147,7 @@ func (b *listParser) Open(parent ast.Node, reader text.Reader, pc Context) (ast.
if typ == orderedList && start != 1 {
return nil, NoChildren
}
//an empty list item cannot interrupt a paragraph:
// an empty list item cannot interrupt a paragraph:
if match[4] < 0 || util.IsBlank(line[match[4]:match[5]]) {
return nil, NoChildren
}

View file

@ -159,7 +159,7 @@ func (r *renderer) Render(w io.Writer, source []byte, n ast.Node) error {
writer = bufio.NewWriter(w)
}
err := ast.Walk(n, func(n ast.Node, entering bool) (ast.WalkStatus, error) {
s := ast.WalkStatus(ast.WalkContinue)
s := ast.WalkContinue
var err error
f := r.nodeRendererFuncs[n.Kind()]
if f != nil {

View file

@ -156,7 +156,7 @@ func DoTestCaseFile(m goldmark.Markdown, filename string, t TestingT, no ...int)
}
c.Expected = strings.Join(buf, "\n")
if len(c.Expected) != 0 {
c.Expected = c.Expected + "\n"
c.Expected += "\n"
}
shouldAdd := len(no) == 0
if !shouldAdd {

View file

@ -126,13 +126,13 @@ func IsBlank(bs []byte) bool {
// VisualizeSpaces visualize invisible space characters.
func VisualizeSpaces(bs []byte) []byte {
bs = bytes.Replace(bs, []byte(" "), []byte("[SPACE]"), -1)
bs = bytes.Replace(bs, []byte("\t"), []byte("[TAB]"), -1)
bs = bytes.Replace(bs, []byte("\n"), []byte("[NEWLINE]\n"), -1)
bs = bytes.Replace(bs, []byte("\r"), []byte("[CR]"), -1)
bs = bytes.Replace(bs, []byte("\v"), []byte("[VTAB]"), -1)
bs = bytes.Replace(bs, []byte("\x00"), []byte("[NUL]"), -1)
bs = bytes.Replace(bs, []byte("\ufffd"), []byte("[U+FFFD]"), -1)
bs = bytes.ReplaceAll(bs, []byte(" "), []byte("[SPACE]"))
bs = bytes.ReplaceAll(bs, []byte("\t"), []byte("[TAB]"))
bs = bytes.ReplaceAll(bs, []byte("\n"), []byte("[NEWLINE]\n"))
bs = bytes.ReplaceAll(bs, []byte("\r"), []byte("[CR]"))
bs = bytes.ReplaceAll(bs, []byte("\v"), []byte("[VTAB]"))
bs = bytes.ReplaceAll(bs, []byte("\x00"), []byte("[NUL]"))
bs = bytes.ReplaceAll(bs, []byte("\ufffd"), []byte("[U+FFFD]"))
return bs
}
@ -573,7 +573,7 @@ func UnescapePunctuations(source []byte) []byte {
// ResolveNumericReferences resolve numeric references like '&#1234;" .
func ResolveNumericReferences(source []byte) []byte {
cob := NewCopyOnWriteBuffer(source)
buf := make([]byte, 6, 6)
buf := make([]byte, 6)
limit := len(source)
ok := false
n := 0