back interdiff of round #2 and #1

appview: parse reference links from markdown body #760

merged
opened by boltless.me targeting master from feat/mentions

Defined refResolver which will parse useful data from markdown body like @-mentions or issue/pr/comment mentions

Signed-off-by: Seongmin Lee git@boltless.me

ERROR
appview/db/reference.go

Failed to calculate interdiff for this file.

ERROR
appview/issues/issues.go

Failed to calculate interdiff for this file.

ERROR
appview/models/reference.go

Failed to calculate interdiff for this file.

REVERTED
appview/pages/markup/markdown_at_extension.go
··· 109 109 util.Prioritized(NewAtHTMLRenderer(), 500), 110 110 )) 111 111 } 112 + 113 + // FindUserMentions returns Set of user handles from given markup soruce. 114 + // It doesn't guarntee unique DIDs 115 + func FindUserMentions(source string) []string { 116 + var ( 117 + mentions []string 118 + mentionsSet = make(map[string]struct{}) 119 + md = NewMarkdown() 120 + sourceBytes = []byte(source) 121 + root = md.Parser().Parse(text.NewReader(sourceBytes)) 122 + ) 123 + ast.Walk(root, func(n ast.Node, entering bool) (ast.WalkStatus, error) { 124 + if entering && n.Kind() == KindAt { 125 + handle := n.(*AtNode).handle 126 + mentionsSet[handle] = struct{}{} 127 + return ast.WalkSkipChildren, nil 128 + } 129 + return ast.WalkContinue, nil 130 + }) 131 + for handle := range mentionsSet { 132 + mentions = append(mentions, handle) 133 + } 134 + return mentions 135 + }
ERROR
appview/pages/markup/reference_link.go

Failed to calculate interdiff for this file.

ERROR
appview/pulls/pulls.go

Failed to calculate interdiff for this file.

ERROR
appview/refresolver/resolver.go

Failed to calculate interdiff for this file.

ERROR
appview/state/router.go

Failed to calculate interdiff for this file.

ERROR
appview/state/state.go

Failed to calculate interdiff for this file.

NEW
appview/pages/markup/extension/atlink.go
··· 16 16 17 17 // An AtNode struct represents an AtNode 18 18 type AtNode struct { 19 - handle string 19 + Handle string 20 20 ast.BaseInline 21 21 } 22 22 ··· 59 59 block.Advance(m[1]) 60 60 node := &AtNode{} 61 61 node.AppendChild(node, ast.NewTextSegment(atSegment)) 62 - node.handle = string(atSegment.Value(block.Source())[1:]) 62 + node.Handle = string(atSegment.Value(block.Source())[1:]) 63 63 return node 64 64 } 65 65 ··· 88 88 func (r *atHtmlRenderer) renderAt(w util.BufWriter, source []byte, n ast.Node, entering bool) (ast.WalkStatus, error) { 89 89 if entering { 90 90 w.WriteString(`<a href="/@`) 91 - w.WriteString(n.(*AtNode).handle) 91 + w.WriteString(n.(*AtNode).Handle) 92 92 w.WriteString(`" class="mention">`) 93 93 } else { 94 94 w.WriteString("</a>")
NEW
appview/pages/markup/markdown.go
··· 77 77 return md 78 78 } 79 79 80 + // FindUserMentions returns Set of user handles from given markup soruce. 81 + // It doesn't guarntee unique DIDs 82 + func FindUserMentions(source string) []string { 83 + var ( 84 + mentions []string 85 + mentionsSet = make(map[string]struct{}) 86 + md = NewMarkdown() 87 + sourceBytes = []byte(source) 88 + root = md.Parser().Parse(text.NewReader(sourceBytes)) 89 + ) 90 + ast.Walk(root, func(n ast.Node, entering bool) (ast.WalkStatus, error) { 91 + if entering && n.Kind() == textension.KindAt { 92 + handle := n.(*textension.AtNode).Handle 93 + mentionsSet[handle] = struct{}{} 94 + return ast.WalkSkipChildren, nil 95 + } 96 + return ast.WalkContinue, nil 97 + }) 98 + for handle := range mentionsSet { 99 + mentions = append(mentions, handle) 100 + } 101 + return mentions 102 + } 103 + 80 104 func (rctx *RenderContext) RenderMarkdown(source string) string { 81 105 md := NewMarkdown() 82 106