Monorepo for Tangled tangled.org

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

Labels

None yet.

assignee

None yet.

Participants 1
AT URI
at://did:plc:xasnlahkri4ewmbuzly2rlc5/sh.tangled.repo.pull/3m4vklvknsc22
+3 -51
Interdiff #4 #5
appview/db/reference.go

This file has not been changed.

appview/issues/issues.go

This file has not been changed.

appview/models/reference.go

This file has not been changed.

+3 -3
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>")
-48
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 - 104 80 func (rctx *RenderContext) RenderMarkdown(source string) string { 105 81 md := NewMarkdown() 106 82 ··· 326 302 return path.Join(rctx.CurrentDir, dst) 327 303 } 328 304 329 - // FindUserMentions returns Set of user handles from given markup soruce. 330 - // It doesn't guarntee unique DIDs 331 - func FindUserMentions(source string) []string { 332 - var ( 333 - mentions []string 334 - mentionsSet = make(map[string]struct{}) 335 - md = NewMarkdown() 336 - sourceBytes = []byte(source) 337 - root = md.Parser().Parse(text.NewReader(sourceBytes)) 338 - ) 339 - ast.Walk(root, func(n ast.Node, entering bool) (ast.WalkStatus, error) { 340 - if entering && n.Kind() == textension.KindAt { 341 - handle := n.(*textension.AtNode).Handle 342 - mentionsSet[handle] = struct{}{} 343 - return ast.WalkSkipChildren, nil 344 - } 345 - return ast.WalkContinue, nil 346 - }) 347 - for handle := range mentionsSet { 348 - mentions = append(mentions, handle) 349 - } 350 - return mentions 351 - } 352 - 353 305 func isAbsoluteUrl(link string) bool { 354 306 parsed, err := url.Parse(link) 355 307 if err != nil {
appview/pages/markup/reference_link.go

This file has not been changed.

appview/pulls/pulls.go

This file has not been changed.

appview/refresolver/resolver.go

This file has not been changed.

appview/state/router.go

This file has not been changed.

appview/state/state.go

This file has not been changed.

History

13 rounds 0 comments
sign up or login to add to the discussion
1 commit
expand
appview: parse reference links from markdown body
2/3 failed, 1/3 running
expand
expand 0 comments
pull request successfully merged
1 commit
expand
appview: parse reference links from markdown body
2/3 failed, 1/3 running
expand
expand 0 comments
1 commit
expand
appview: parse reference links from markdown body
3/3 success
expand
expand 0 comments
1 commit
expand
appview: parse reference links from markdown body
3/3 success
expand
expand 0 comments
1 commit
expand
appview: parse reference links from markdown body
3/3 success
expand
expand 0 comments
1 commit
expand
appview: parse reference links from markdown body
3/3 success
expand
expand 0 comments
1 commit
expand
appview: parse reference links from markdown body
3/3 success
expand
expand 0 comments
1 commit
expand
appview: parse reference links from markdown body
3/3 success
expand
expand 0 comments
1 commit
expand
appview: parse reference links from markdown body
3/3 success
expand
expand 0 comments
1 commit
expand
appview: parse reference links from markdown body
1/3 failed, 2/3 running
expand
expand 0 comments
1 commit
expand
appview: parse reference links from markdown body
1/3 failed, 2/3 timeout
expand
expand 0 comments
1 commit
expand
appview: parse reference links from markdown body
3/3 success
expand
expand 0 comments
1 commit
expand
appview: parse reference links from markdown body
3/3 success
expand
expand 0 comments