mirror of
https://github.com/yuin/goldmark
synced 2025-03-04 23:04:52 +00:00
Simplify code
This commit is contained in:
parent
fa6bebc584
commit
adf4a91f02
9 changed files with 22 additions and 22 deletions
|
|
@ -91,7 +91,7 @@ func (n *Text) SetSoftLineBreak(v bool) {
|
||||||
if v {
|
if v {
|
||||||
n.flags |= textSoftLineBreak
|
n.flags |= textSoftLineBreak
|
||||||
} else {
|
} else {
|
||||||
n.flags = n.flags &^ textSoftLineBreak
|
n.flags &^= textSoftLineBreak
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -106,7 +106,7 @@ func (n *Text) SetRaw(v bool) {
|
||||||
if v {
|
if v {
|
||||||
n.flags |= textRaw
|
n.flags |= textRaw
|
||||||
} else {
|
} else {
|
||||||
n.flags = n.flags &^ textRaw
|
n.flags &^= textRaw
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -121,7 +121,7 @@ func (n *Text) SetHardLineBreak(v bool) {
|
||||||
if v {
|
if v {
|
||||||
n.flags |= textHardLineBreak
|
n.flags |= textHardLineBreak
|
||||||
} else {
|
} else {
|
||||||
n.flags = n.flags &^ textHardLineBreak
|
n.flags &^= textHardLineBreak
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -237,7 +237,7 @@ func (n *String) SetRaw(v bool) {
|
||||||
if v {
|
if v {
|
||||||
n.flags |= textRaw
|
n.flags |= textRaw
|
||||||
} else {
|
} else {
|
||||||
n.flags = n.flags &^ textRaw
|
n.flags &^= textRaw
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -252,7 +252,7 @@ func (n *String) SetCode(v bool) {
|
||||||
if v {
|
if v {
|
||||||
n.flags |= textCode
|
n.flags |= textCode
|
||||||
} else {
|
} else {
|
||||||
n.flags = n.flags &^ textCode
|
n.flags &^= textCode
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -229,7 +229,7 @@ func (a *footnoteASTTransformer) Transform(node *gast.Document, reader text.Read
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for footnote := list.FirstChild(); footnote != nil; {
|
for footnote := list.FirstChild(); footnote != nil; {
|
||||||
var container gast.Node = footnote
|
var container = footnote
|
||||||
next := footnote.NextSibling()
|
next := footnote.NextSibling()
|
||||||
if fc := container.LastChild(); fc != nil && gast.IsParagraph(fc) {
|
if fc := container.LastChild(); fc != nil && gast.IsParagraph(fc) {
|
||||||
container = fc
|
container = fc
|
||||||
|
|
@ -649,8 +649,8 @@ func applyFootnoteTemplate(b []byte, index, refCount int) []byte {
|
||||||
}
|
}
|
||||||
is := []byte(strconv.Itoa(index))
|
is := []byte(strconv.Itoa(index))
|
||||||
rs := []byte(strconv.Itoa(refCount))
|
rs := []byte(strconv.Itoa(refCount))
|
||||||
ret := bytes.Replace(b, []byte("^^"), is, -1)
|
ret := bytes.ReplaceAll(b, []byte("^^"), is)
|
||||||
return bytes.Replace(ret, []byte("%%"), rs, -1)
|
return bytes.ReplaceAll(ret, []byte("%%"), rs)
|
||||||
}
|
}
|
||||||
|
|
||||||
type footnote struct {
|
type footnote struct {
|
||||||
|
|
|
||||||
|
|
@ -182,7 +182,7 @@ func (s *linkifyParser) Parse(parent ast.Node, block text.Reader, pc parser.Cont
|
||||||
|
|
||||||
var m []int
|
var m []int
|
||||||
var protocol []byte
|
var protocol []byte
|
||||||
var typ ast.AutoLinkType = ast.AutoLinkURL
|
var typ = ast.AutoLinkURL
|
||||||
if s.LinkifyConfig.AllowedProtocols == nil {
|
if s.LinkifyConfig.AllowedProtocols == nil {
|
||||||
if bytes.HasPrefix(line, protoHTTP) || bytes.HasPrefix(line, protoHTTPS) || bytes.HasPrefix(line, protoFTP) {
|
if bytes.HasPrefix(line, protoHTTP) || bytes.HasPrefix(line, protoHTTPS) || bytes.HasPrefix(line, protoFTP) {
|
||||||
m = s.LinkifyConfig.URLRegexp.FindSubmatchIndex(line)
|
m = s.LinkifyConfig.URLRegexp.FindSubmatchIndex(line)
|
||||||
|
|
|
||||||
|
|
@ -175,7 +175,7 @@ func (b *tableParagraphTransformer) Transform(node *gast.Paragraph, reader text.
|
||||||
node.Parent().RemoveChild(node.Parent(), node)
|
node.Parent().RemoveChild(node.Parent(), node)
|
||||||
} else {
|
} else {
|
||||||
last := node.Lines().At(i - 2)
|
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)
|
node.Lines().Set(i-2, last)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ func (s *autoLinkParser) Trigger() []byte {
|
||||||
func (s *autoLinkParser) Parse(parent ast.Node, block text.Reader, pc Context) ast.Node {
|
func (s *autoLinkParser) Parse(parent ast.Node, block text.Reader, pc Context) ast.Node {
|
||||||
line, segment := block.PeekLine()
|
line, segment := block.PeekLine()
|
||||||
stop := util.FindEmailIndex(line[1:])
|
stop := util.FindEmailIndex(line[1:])
|
||||||
typ := ast.AutoLinkType(ast.AutoLinkEmail)
|
typ := ast.AutoLinkEmail
|
||||||
if stop < 0 {
|
if stop < 0 {
|
||||||
stop = util.FindURLIndex(line[1:])
|
stop = util.FindURLIndex(line[1:])
|
||||||
typ = ast.AutoLinkURL
|
typ = ast.AutoLinkURL
|
||||||
|
|
|
||||||
|
|
@ -159,7 +159,7 @@ func (r *renderer) Render(w io.Writer, source []byte, n ast.Node) error {
|
||||||
writer = bufio.NewWriter(w)
|
writer = bufio.NewWriter(w)
|
||||||
}
|
}
|
||||||
err := ast.Walk(n, func(n ast.Node, entering bool) (ast.WalkStatus, error) {
|
err := ast.Walk(n, func(n ast.Node, entering bool) (ast.WalkStatus, error) {
|
||||||
s := ast.WalkStatus(ast.WalkContinue)
|
s := ast.WalkContinue
|
||||||
var err error
|
var err error
|
||||||
f := r.nodeRendererFuncs[n.Kind()]
|
f := r.nodeRendererFuncs[n.Kind()]
|
||||||
if f != nil {
|
if f != nil {
|
||||||
|
|
|
||||||
|
|
@ -156,7 +156,7 @@ func DoTestCaseFile(m goldmark.Markdown, filename string, t TestingT, no ...int)
|
||||||
}
|
}
|
||||||
c.Expected = strings.Join(buf, "\n")
|
c.Expected = strings.Join(buf, "\n")
|
||||||
if len(c.Expected) != 0 {
|
if len(c.Expected) != 0 {
|
||||||
c.Expected = c.Expected + "\n"
|
c.Expected += "\n"
|
||||||
}
|
}
|
||||||
shouldAdd := len(no) == 0
|
shouldAdd := len(no) == 0
|
||||||
if !shouldAdd {
|
if !shouldAdd {
|
||||||
|
|
|
||||||
16
util/util.go
16
util/util.go
|
|
@ -126,13 +126,13 @@ func IsBlank(bs []byte) bool {
|
||||||
|
|
||||||
// VisualizeSpaces visualize invisible space characters.
|
// VisualizeSpaces visualize invisible space characters.
|
||||||
func VisualizeSpaces(bs []byte) []byte {
|
func VisualizeSpaces(bs []byte) []byte {
|
||||||
bs = bytes.Replace(bs, []byte(" "), []byte("[SPACE]"), -1)
|
bs = bytes.ReplaceAll(bs, []byte(" "), []byte("[SPACE]"))
|
||||||
bs = bytes.Replace(bs, []byte("\t"), []byte("[TAB]"), -1)
|
bs = bytes.ReplaceAll(bs, []byte("\t"), []byte("[TAB]"))
|
||||||
bs = bytes.Replace(bs, []byte("\n"), []byte("[NEWLINE]\n"), -1)
|
bs = bytes.ReplaceAll(bs, []byte("\n"), []byte("[NEWLINE]\n"))
|
||||||
bs = bytes.Replace(bs, []byte("\r"), []byte("[CR]"), -1)
|
bs = bytes.ReplaceAll(bs, []byte("\r"), []byte("[CR]"))
|
||||||
bs = bytes.Replace(bs, []byte("\v"), []byte("[VTAB]"), -1)
|
bs = bytes.ReplaceAll(bs, []byte("\v"), []byte("[VTAB]"))
|
||||||
bs = bytes.Replace(bs, []byte("\x00"), []byte("[NUL]"), -1)
|
bs = bytes.ReplaceAll(bs, []byte("\x00"), []byte("[NUL]"))
|
||||||
bs = bytes.Replace(bs, []byte("\ufffd"), []byte("[U+FFFD]"), -1)
|
bs = bytes.ReplaceAll(bs, []byte("\ufffd"), []byte("[U+FFFD]"))
|
||||||
return bs
|
return bs
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -573,7 +573,7 @@ func UnescapePunctuations(source []byte) []byte {
|
||||||
// ResolveNumericReferences resolve numeric references like 'Ӓ" .
|
// ResolveNumericReferences resolve numeric references like 'Ӓ" .
|
||||||
func ResolveNumericReferences(source []byte) []byte {
|
func ResolveNumericReferences(source []byte) []byte {
|
||||||
cob := NewCopyOnWriteBuffer(source)
|
cob := NewCopyOnWriteBuffer(source)
|
||||||
buf := make([]byte, 6, 6)
|
buf := make([]byte, 6)
|
||||||
limit := len(source)
|
limit := len(source)
|
||||||
ok := false
|
ok := false
|
||||||
n := 0
|
n := 0
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue