headingid

package module
v0.0.0-...-8b6c16c Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2020 License: MIT Imports: 5 Imported by: 0

README

goldmark-headingid

goldmark-headingid is an extension for the goldmark that enhances the automatic heading ID generation.

This extension overcomes the restrictions of the goldmark's default heading ID logic, including:

  • goldmark takes into account ASCII alphanumeric (one-byte) only while generating auto heading IDs, simply discarding extended latin characters (2 bytes) and other international characters (3 bytes).
  • goldmark considers only a small set of punctuations during the auto heading ID generation. As a result, the IDs for headings with other punctuations become less readable or identifiable.

With this extension,

  • All unicode letter and number code points are preserved, and converted to lowercase as necessary.
  • All punctuations are taken into account and converted to hyphen as appropriate.

Installation

go get github.com/jkboxomine/goldmark-headingid

Usage

import (
	"bytes"
	"fmt"

	"github.com/jkboxomine/goldmark-headingid"
	"github.com/yuin/goldmark"
	"github.com/yuin/goldmark/parser"
)

func main() {
	var html bytes.Buffer
	ctx := parser.NewContext(parser.WithIDs(headingid.NewIDs()))
	md := goldmark.New(
		goldmark.WithParserOptions(
			parser.WithAutoHeadingID(),
		),
	)
	mdContent := []byte(`<Markdown content>`)

	if err := md.Convert(mdContent, &html, parser.WithContext(ctx)); err != nil {
		panic(err)
	}
	fmt.Println(html.String())
}

License

MIT

Documentation

Overview

package headingid is an extension for the goldmark (http://github.com/yuin/goldmark).

This extension enhances the automatic heading ID generation.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type IDs

type IDs interface {
	// Generate generates a new element id.
	Generate(value []byte, kind ast.NodeKind) []byte

	// Put puts a given element id to the used ids table.
	Put(value []byte)
}

An IDs interface is a collection of the element ids.

func NewIDs

func NewIDs() IDs

Jump to

Keyboard shortcuts

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