wikilink

package module
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2020 License: MIT Imports: 9 Imported by: 1

README

goldmark-wikilink is an extension for the goldmark library that extends Markdown to support [[title]] Wikilink style links with a new AST type and HTML Renderer.

Demo

This markdown:

# Hello goldmark-wikilink

[[Example Link]]

Becomes this HTML, with the default Normalizer:

<h1>Hello goldmark-wikilink</h1>
<p><a href="Example%20Link.html">Example Link</a></p>
Installation
go get github.com/13rac1/goldmark-wikilink

Usage

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

TODO

  • Support Piped Links in the form [target|displayed text].
  • Support Section linking in the forms:
    • External link: [[Page name#Section name|displayed text]]
    • Internal link: [[#Section name|displayed text]]

License

MIT

Author

Brad Erickson & Kevin Dangoor

Fork of dangoor/goldmark-wikilinks. Adds a Wikilink AST type to ease extending and removes the WikilinkTracker which can implemented in a separate AST walker.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var KindWikilink = ast.NewNodeKind("Wikilink")

KindWikilink is a NodeKind of the Wikilink node.

Functions

func New added in v1.3.0

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

New returns a new Wikilink extension.

func NewHTMLRenderer

func NewHTMLRenderer() renderer.NodeRenderer

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

Types

type FilenameNormalizer

type FilenameNormalizer interface {
	Normalize(linkText string) string
}

FilenameNormalizer is a plugin which takes link text and converts the text given to a filename which can be linked to in the final format of your file.

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 Option added in v1.3.0

type Option func(*wlExtension)

Option is a functional option type for this extension.

type Parser added in v1.3.0

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

Parser keeps track of the plugins used for processing wikilinks.

func NewParser

func NewParser() *Parser

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

func (*Parser) Parse added in v1.3.0

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

Parse implements the parser.Parser interface for Wikilinks in markdown

func (*Parser) Trigger added in v1.3.0

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

Trigger looks for the [[ beginning of wikilinks.

func (*Parser) WithNormalizer added in v1.3.0

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

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

type Wikilink struct {
	ast.Link
}

Wikilink struct represents a Wikilink of the Markdown text.

func NewWikilink(l *ast.Link) *Wikilink

NewWikilink returns a new Wikilink node.

func (*Wikilink) Kind

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

Kind implements Node.Kind.

Jump to

Keyboard shortcuts

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