Documentation ¶
Overview ¶
Package hashtag provides support for #tag-style tags for the Goldmark Markdown parser.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var Kind = ast.NewNodeKind("Hashtag")
Kind is the kind of hashtag AST nodes.
Functions ¶
This section is empty.
Types ¶
type Extender ¶
type Extender struct { // Resolver specifies destination links for hashtags, if any. // // Defaults to no links. Resolver Resolver // Variant is the flavor of the hashtag syntax to support. // // Defaults to DefaultVariant. See the documentation of individual // variants for more information. Variant Variant }
Extender extends a goldmark Markdown object with support for parsing and rendering hashtags.
Install it on your Markdown object upon creation.
goldmark.New( goldmark.WithExtensions( // ... &hashtag.Extender{...}, ), // ... )
Provide a Resolver to render tags as links that point to a specific destination.
type Node ¶
type Node struct { ast.BaseInline // Tag is the portion of the hashtag following the '#'. Tag []byte }
Node is a hashtag node in a Goldmark Markdown document.
type Parser ¶
type Parser struct { // Variant is the flavor of the hashtag syntax to support. // // Defaults to DefaultVariant. See the documentation of individual // variants for more information. Variant Variant }
Parser is a Goldmark inline parser for parsing hashtag nodes.
Hashtags start with "#". The list of other characters allowed in the hashtag is determined by variant. See the documentation for Variant for more details.
type Renderer ¶
type Renderer struct { // Resolver specifies how where hashtag links should point, if at all. // // When a Resolver returns an empty destination for a hashtag, the // Renderer will render the hashtag as plain text rather than a link. // // Defaults to empty destinations for all hashtags. Resolver Resolver // contains filtered or unexported fields }
Renderer renders hashtag nodes into HTML, optionally linking them to specific pages.
#foo
Renders as the following by default.
<span class="hashtag">#foo</span>
Supply a Resolver that returns a non-empty destination to render it like the following.
<span class="hashtag"><a href="...">#foo</a></span>
func (*Renderer) RegisterFuncs ¶
func (r *Renderer) RegisterFuncs(reg renderer.NodeRendererFuncRegisterer)
RegisterFuncs registers rendering functions from this renderer onto the provided registerer.
type Resolver ¶
type Resolver interface { // ResolveHashtag reports the link that the provided hashtag Node // should point to, or an empty destination for hashtags that should // not link to anything. ResolveHashtag(*Node) (destination []byte, err error) }
Resolver resolves hashtags to pages they should link to.
type Variant ¶
type Variant uint
Variant represents one of the different flavours of hashtag syntax.
const ( // DefaultVariant is the default flavor of hashtag syntax supported by // this package. // // In this format, hashtags start with "#" and an alphabet, followed by // zero or more alphanumeric characters and the following symbols. // // /_- DefaultVariant Variant = iota // ObsidianVariant is a flavor of the hashtag syntax that aims to be // compatible with Obsidian (https://obsidian.md/). // // In this format, hashtags start with "#" followed by alphabets, // numbers, emoji, or any of the following symbols. // // /_- // // Hashtags cannot be entirely numeric and must contain at least one // non-numeric character. // // See also https://help.obsidian.md/How+to/Working+with+tags. ObsidianVariant )