1
0
mirror of https://github.com/osmarks/mycorrhiza.git synced 2025-04-03 01:07:04 +00:00
mycorrhiza/markup/link.go
2021-05-11 14:35:46 +05:00

34 lines
956 B
Go

package markup
import (
"strings"
"github.com/bouncepaw/mycomarkup/links"
)
// LinkParts determines what href, text and class should resulting <a> have based on mycomarkup's addr, display and hypha name.
//
// => addr display
// [[addr|display]]
// TODO: deprecate
func LinkParts(addr, display, hyphaName string) (href, text, class string) {
l := links.From(addr, display, hyphaName)
if l.OfKind(links.LinkLocalHypha) && !HyphaExists(l.Address()) {
l.DestinationUnknown = true
}
return l.Href(), l.Display(), l.Classes()
}
// Parse markup line starting with "=>" according to wikilink rules.
// See http://localhost:1737/page/wikilink
func Rocketlink(src, hyphaName string) (href, text, class string) {
src = strings.TrimSpace(src[2:]) // Drop =>
if src == "" {
return
}
// Href is text after => till first whitespace
addr := strings.Fields(src)[0]
display := strings.TrimPrefix(src, addr)
return LinkParts(addr, display, hyphaName)
}