hashtag

package module
v0.0.0-...-837b29d Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2020 License: MIT Imports: 8 Imported by: 0

README

goldmark-hashtag

goldmark-hashtag is an extension for the goldmark library to handle #example hashtags providing a Hashtag AST type.

Demo

This markdown:

# Hello goldmark-hashtag

#example

With the default configuration, becomes this HTML:

<h1>Hello goldmark-hashtag</h1>
<p><a href="/tags/example">#example</a></p>
Installation
go get github.com/13rac1/goldmark-hashtag

Usage

  markdown := goldmark.New(
    goldmark.WithExtensions(
      hashtag.Extension,
    ),
  )
  var buf bytes.Buffer
  if err := markdown.Convert([]byte(source), &buf); err != nil {
    panic(err)
  }
  fmt.Print(buf)
}

License

MIT

Author

Brad Erickson

Documentation

Index

Constants

This section is empty.

Variables

View Source
var KindHashtag = ast.NewNodeKind("Hashtag")

KindHashtag is a NodeKind of the Hashtag node.

Functions

func New

func New(opts ...Option) goldmark.Extender

New returns a new Hashtag extension.

func NewHTMLRenderer

func NewHTMLRenderer() renderer.NodeRenderer

NewHTMLRenderer builds a new HTMLRenderer with given options and returns it.

Types

type HTMLRenderer

type HTMLRenderer struct{}

HTMLRenderer struct is a renderer.NodeRenderer implementation for the extension.

func (*HTMLRenderer) RegisterFuncs

func (r *HTMLRenderer) RegisterFuncs(reg renderer.NodeRendererFuncRegisterer)

RegisterFuncs implements NodeRenderer.RegisterFuncs.

type Hashtag

type Hashtag struct {
	ast.Link
}

Hashtag struct represents a Hashtag of the Markdown text.

func NewHashtag

func NewHashtag(title, destination []byte) *Hashtag

NewHashtag returns a new Hashtag node.

func (*Hashtag) Kind

func (n *Hashtag) Kind() ast.NodeKind

Kind implements Node.Kind.

type Linker

type Linker interface {
	Link(text string) string
}

Linker describes the method to convert hashtags into URLs.

type Option

type Option func(*htExtension)

Option is a functional option type for this extension.

type Parser

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

Parser implements the goldmark parser.Parser interface

func NewParser

func NewParser() *Parser

NewParser gives you back a parser that you can use to process hashtags.

func (*Parser) Parse

func (p *Parser) Parse(parent ast.Node, block text.Reader, pc parser.Context) ast.Node

Parse implements the parser.Parser interface for Hashtags in markdown

func (*Parser) Trigger

func (p *Parser) Trigger() []byte

Trigger looks for the # beginning of a hashtag

func (*Parser) WithNormalizer

func (p *Parser) WithNormalizer(fn Linker) *Parser

WithNormalizer is the fluent interface for replacing the default normalizer plugin.

Jump to

Keyboard shortcuts

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