highlight

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2021 License: MIT Imports: 7 Imported by: 0

README

Goldmark-Highlight

An extension to the Goldmark Markdown Parser which adds parsing / rendering capabilities for rendering highlighted text.

Highlighted text is denoted by an opening and closing pair of equals signs e.g. ==this text is highlighted== source text renders into <p><mark>this text is highlighted</mark></p>.

See example_test.go in this package for a minimal example how to integrate this module into your Goldmark parser/renderer.

Documentation

Overview

Package highlight provides an extension to the Goldmark Markdown Parser which adds parsing / rendering capabilities for rendering highlighted text.

Highlighted text is denoted by an opening and closing pair of equals signs e.g. `==this text is highlighted==` source text renders into `<p><mark>this text is highlighted</mark></p>`.

See example_test.go in this package for a minimal example how to integrate this module into your Goldmark parser/renderer.

Example
package main

import (
	"bytes"
	"fmt"

	"github.com/yuin/goldmark"
	highlight "github.com/zuern/goldmark-highlight"
)

func main() {
	// Create a combined parser / renderer which understands highlight syntax.
	md := goldmark.New(
		goldmark.WithExtensions(
			&highlight.Extender{},
		),
	)

	markdown := []byte("==this is some highlighted text==")

	var buffer bytes.Buffer
	_ = md.Convert(markdown, &buffer)

	fmt.Println(buffer.String())
}
Output:

<p><mark>this is some highlighted text</mark></p>

Index

Examples

Constants

This section is empty.

Variables

View Source
var Kind = ast.NewNodeKind("Highlight")

Kind is the ast.NodeKind for *Highlight AST nodes.

Functions

This section is empty.

Types

type Extender

type Extender struct{}

Extender implements the goldmark Extender interface and extends goldmark.Markdown to understand highlighting syntax.

func (*Extender) Extend

func (e *Extender) Extend(md goldmark.Markdown)

Extend extends md to understand highlighting syntax.

type Highlight

type Highlight struct {
	ast.BaseInline
	Level int
}

A Highlight ast.Node whose contents is highlighted.

func (*Highlight) Dump

func (n *Highlight) Dump(src []byte, level int)

Dump prints the node to stdout for debugging purposes.

func (*Highlight) Kind

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

Kind of the node.

type Parser

type Parser struct{}

Parser for parsing highlight markdown into a *Highlight ast.Node.

func (*Parser) Parse

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

Parse parse the given block into an inline node.

func (*Parser) Trigger

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

Trigger returns a list of characters that triggers Parse method of this parser.

type Renderer

type Renderer struct{}

Renderer renders a *Highlight ast.Node into HTML.

func (*Renderer) RegisterFuncs

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

RendererFuncs registers NodeRendererFuncs to given NodeRendererFuncRegisterer.

func (*Renderer) Render

func (r *Renderer) Render(w util.BufWriter, source []byte, n ast.Node, entering bool) (ast.WalkStatus, error)

Render the AST node to the given writer.

Jump to

Keyboard shortcuts

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