1
0
mirror of https://github.com/osmarks/mycorrhiza.git synced 2024-12-13 05:50:27 +00:00
mycorrhiza/markup/link.go

34 lines
949 B
Go
Raw Normal View History

2020-11-04 17:42:02 +00:00
package markup
import (
"strings"
"github.com/bouncepaw/mycorrhiza/link"
2020-11-04 17:42:02 +00:00
)
// 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 := link.From(addr, display, hyphaName)
if l.Kind == link.LinkLocalHypha && !HyphaExists(l.Address) {
l.DestinationUnknown = true
2020-11-04 17:42:02 +00:00
}
return l.Href(), l.Display, l.Classes()
2020-11-04 17:42:02 +00:00
}
// Parse markup line starting with "=>" according to wikilink rules.
// See http://localhost:1737/page/wikilink
func Rocketlink(src, hyphaName string) (href, text, class string) {
2020-11-04 17:42:02 +00:00
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)
}