links

package
v4.3.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 4, 2022 License: Apache-2.0 Imports: 7 Imported by: 1

Documentation

Overview

Package links provides a data type for links.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type InterwikiLink struct {
	// contains filtered or unexported fields
}

InterwikiLink in Mycomarkup has this syntax:

[[prefix>target]]
[[prefix>target|display]]

For every prefix, there is a known link format. A link format is a format string, that might resemble Go's format strings, but they are actually not. This is DSL for link formats. It is inspired by DokuWiki's interwiki link format: https://www.dokuwiki.org/interwiki.

https://example.org/view/{NAME}

Supported instructions are (more will be added):

{NAME} is the document name without any encoding.

func (*InterwikiLink) Classes added in v4.3.1

func (l *InterwikiLink) Classes(_ mycocontext.Context) string

func (*InterwikiLink) DisplayedText added in v4.3.1

func (l *InterwikiLink) DisplayedText() string

func (*InterwikiLink) Err added in v4.3.1

func (l *InterwikiLink) Err() error

func (*InterwikiLink) HyphaProbe added in v4.3.1

func (l *InterwikiLink) HyphaProbe(mycocontext.Context) func(string)

func (*InterwikiLink) ImgSrc added in v4.3.1

func (l *InterwikiLink) ImgSrc(ctx mycocontext.Context) string

func (*InterwikiLink) LinkHref added in v4.3.1

func (l *InterwikiLink) LinkHref(ctx mycocontext.Context) string

func (*InterwikiLink) TryToGetError added in v4.3.1

func (l *InterwikiLink) TryToGetError(ctx mycocontext.Context) bool
type LegacyLink struct {
	// contains filtered or unexported fields
}

LegacyLink is an abstraction for universal representation of links, be they links in mycomarkup links or whatever.

ADT would help out a lot.

func From

func From(srcAddress, srcDisplay, srcHypha string) LegacyLink

From makes a link from the given source address and display text on the given hypha. The arguments are stripped of whitespace on both sides before further processing.

func (LegacyLink) Classes added in v4.3.1

func (link LegacyLink) Classes() (classes string)

Classes returns CSS class string for given link. It is not wrapped in any quotes, wrap yourself.

func (LegacyLink) CopyMarkedAsExisting added in v4.3.1

func (link LegacyLink) CopyMarkedAsExisting() LegacyLink

CopyMarkedAsExisting returns a copy of the link that is marked as existing, i/e colored in blue.

func (LegacyLink) Display added in v4.3.1

func (link LegacyLink) Display() string

Display returns the display text of the given link. It is not escaped, escape by yourself.

func (LegacyLink) Href added in v4.3.1

func (link LegacyLink) Href() string

Href returns escaped content for the href attribute for HTML link. You should always use it.

func (LegacyLink) ImgSrc added in v4.3.1

func (link LegacyLink) ImgSrc() string

ImgSrc returns escaped content for src attribute of img tag. Used with `img{}`.

func (link LegacyLink) IsBlueLink() bool

IsBlueLink is true if the link should be blue, not red. Red links are links to hyphae that do not exist, all other links are blue.

func (LegacyLink) OfKind added in v4.3.1

func (link LegacyLink) OfKind(kind LinkType) bool

OfKind is true if the given link is of the given kind, i/e the kinds are equal.

func (LegacyLink) TargetHypha added in v4.3.1

func (link LegacyLink) TargetHypha() string

TargetHypha returns the canonical name of the target hypha. Use for hypha links.

type Link interface {
	// Classes returns a string to put into the class attr in HTML.
	Classes(ctx mycocontext.Context) string

	// LinkHref returns a string to put into the href attr of <a>.
	LinkHref(ctx mycocontext.Context) string

	// ImgSrc returns a string to put into the src attr of <img>.
	ImgSrc(ctx mycocontext.Context) string

	// DisplayedText returns a string to put inside <a>.
	DisplayedText() string

	// HyphaProbe returns a function that captures the Link. Probes are checked against all existing hyphae. This is Mycorrhiza-specific. If it is nil, do not check this link for existence. TODO: make it optional.
	HyphaProbe(ctx mycocontext.Context) func(string)
}

Link is a link of some kind.

func LinkFrom added in v4.3.1

func LinkFrom(ctx mycocontext.Context, target, display string) Link

type LinkType

type LinkType int

LinkType tells what type the given link is.

const (
	// LinkLocalRoot is a link like "/list", "/user-list", etc.
	LinkLocalRoot LinkType = iota
	// LinkLocalHypha is a link like "test", "../test", etc.
	LinkLocalHypha
	// LinkExternal is an external link with specified protocol.
	LinkExternal
	// LinkInterwiki is an interwiki link
	LinkInterwiki
)
type LocalLink struct {
	// contains filtered or unexported fields
}

func (*LocalLink) Classes added in v4.3.1

func (l *LocalLink) Classes(ctx mycocontext.Context) string

func (*LocalLink) DisplayedText added in v4.3.1

func (l *LocalLink) DisplayedText() string

func (*LocalLink) Existing added in v4.3.2

func (l *LocalLink) Existing() bool

func (*LocalLink) HyphaProbe added in v4.3.1

func (l *LocalLink) HyphaProbe(ctx mycocontext.Context) func(string)

func (*LocalLink) ImgSrc added in v4.3.1

func (l *LocalLink) ImgSrc(ctx mycocontext.Context) string

func (*LocalLink) LinkHref added in v4.3.1

func (l *LocalLink) LinkHref(ctx mycocontext.Context) string

func (*LocalLink) Target added in v4.3.2

func (l *LocalLink) Target() string
type LocalRootedLink struct {
	// contains filtered or unexported fields
}

func (*LocalRootedLink) Classes added in v4.3.1

func (l *LocalRootedLink) Classes(_ mycocontext.Context) string

func (*LocalRootedLink) DisplayedText added in v4.3.1

func (l *LocalRootedLink) DisplayedText() string

func (*LocalRootedLink) HyphaProbe added in v4.3.1

func (l *LocalRootedLink) HyphaProbe(_ mycocontext.Context) func(string)

func (*LocalRootedLink) ImgSrc added in v4.3.1

func (*LocalRootedLink) LinkHref added in v4.3.1

func (l *LocalRootedLink) LinkHref(_ mycocontext.Context) string
type URLLink struct {
	// contains filtered or unexported fields
}

func (*URLLink) Classes added in v4.3.1

func (l *URLLink) Classes(_ mycocontext.Context) string

func (*URLLink) DisplayedText added in v4.3.1

func (l *URLLink) DisplayedText() string

func (*URLLink) HyphaProbe added in v4.3.1

func (l *URLLink) HyphaProbe(_ mycocontext.Context) func(string)

func (*URLLink) ImgSrc added in v4.3.1

func (l *URLLink) ImgSrc(_ mycocontext.Context) string

func (*URLLink) LinkHref added in v4.3.1

func (l *URLLink) LinkHref(_ mycocontext.Context) string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL