tags

package
v0.0.0-...-eca56f0 Latest Latest
Warning

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

Go to latest
Published: May 7, 2021 License: MIT Imports: 6 Imported by: 0

README

goldmark-tags

goldmark-tag is an extension for the goldmark that allows you to extract tags from a markdown document

Disclaimer

This package will eventually be moved to its ows repository.

Usage

Installation
go get github.com/leonhfr/goldmark-tags
Markdown syntax

Tags are alphanumeric strings preceded by a # character, without any spaces.

Example:

This is an inline #tag.

Tag list:

#tag1 #tag2 #tag3

Code blocks are not parsed for tags:

`This is not a #tag.`

Access the tags

The code

import (
  "bytes"
  "fmt"

  "github.com/leonhfr/goldmark-tags"
  "github.com/yuin/goldmark"
  "github.com/yuin/goldmark/extension"
  "github.com/yuin/goldmark/parser"
)

var source = `
This is an inline #tag.

Tag list:

#tag1 #tag2 #tag3

Code blocks are not parsed for tags:

\`This is not a #tag.\`
`

func main() {
  markdown := goldmark.New(
    goldmark.WithExtensions(tags.Tags),
  )
  var buf bytes.Buffer
  ctx := parser.NewContext()
  if err := markdown.Convert([]byte(source), &buf, parser.WithContext(ctx)); if err != nil {
    panic(err)
  }

  tagList := tags.Get(ctx)
  fmt.Println(tagList)
}

will output

[tag1 tag2 tag3 notag]

The package does not modify the goldmark AST in any way, nor renders the tags.

License

MIT

Author

leonhfr

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Tags = &tags{}

Tags is an extension for the goldmark

Functions

func Get

func Get(pc parser.Context) []string

Get returns the tag list

func NewParser

func NewParser() parser.InlineParser

Types

This section is empty.

Jump to

Keyboard shortcuts

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