autolinks

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2022 License: MIT Imports: 7 Imported by: 0

README

Goldmark text autolinks extension.

code

var source = []byte(`Standup notes:
- Previous day:
  - Gave feedback on TICKET-123.
  - Outlined presentation on syntax-aware markdown transformations.
  - Finished my part of TICKET-456 and assigned to Emily.
- Today:
  - Add integration tests for TICKET-789.
  - Create slides for presentation.`)

func Example() {
	md := goldmark.New(
		goldmark.WithExtensions(
			autolinks.NewExtender(
				map[string]string{
					`TICKET-\d+`: "https://example.com/TICKET?query=$0",
                    `Emily`:"https://example.com/Emily?query=$0",
				}),
		),
	)

	if err := md.Convert(source, os.Stdout); err != nil {
		log.Fatal(err)
	}

}

view

<p>Standup notes:</p>
<ul>
    <li>
        Previous day:
        <ul>
            <li>Gave feedback on <a href="https://example.com/TICKET?query=TICKET-123">TICKET-123</a>.</li>
            <li>Outlined presentation on syntax-aware markdown transformations.</li>
            <li>
                Finished my part of <a href="https://example.com/TICKET?query=TICKET-456">TICKET-456</a> and assigned to Emily.
            </li>
        </ul>
    </li>
    <li>
        Today:
        <ul>
            <li>Add integration tests for <a href="https://example.com/TICKET?query=TICKET-789">TICKET-789</a>.</li>
            <li>Create slides for presentation.</li>
        </ul>
    </li>
</ul>

thanks

Goldmark

goldmark-markdown

Documentation

Overview

Example
package main

import (
	"log"
	"os"

	autolinks "github.com/fundipper/goldmark-autolinks"
	"github.com/yuin/goldmark"
)

var source = []byte(`Standup notes:
- Previous day:
  - Gave feedback on TICKET-123.
  - Outlined presentation on syntax-aware markdown transformations.
  - Finished my part of TICKET-456 and assigned to Emily.
- Today:
  - Add integration tests for TICKET-789.
  - Create slides for presentation.`)

func main() {
	md := goldmark.New(
		goldmark.WithExtensions(
			autolinks.NewExtender(
				map[string]string{
					`TICKET-\d+`: "https://example.com/TICKET?query=$0",
				}),
		),
	)

	if err := md.Convert(source, os.Stdout); err != nil {
		log.Fatal(err)
	}

}
Output:

<p>Standup notes:</p>
<ul>
<li>Previous day:
<ul>
<li>Gave feedback on <a href="https://example.com/TICKET?query=TICKET-123">TICKET-123</a>.</li>
<li>Outlined presentation on syntax-aware markdown transformations.</li>
<li>Finished my part of <a href="https://example.com/TICKET?query=TICKET-456">TICKET-456</a> and assigned to Emily.</li>
</ul>
</li>
<li>Today:
<ul>
<li>Add integration tests for <a href="https://example.com/TICKET?query=TICKET-789">TICKET-789</a>.</li>
<li>Create slides for presentation.</li>
</ul>
</li>
</ul>

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewExtender

func NewExtender(data map[string]string) goldmark.Extender

New return initialized image render with source url replacing support.

Types

type Extender

type Extender struct {
	Data map[string]string
}

func (*Extender) Extend

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

type Transformer

type Transformer struct {
	Pattern *regexp.Regexp
	URL     []byte
}

func NewTransformer

func NewTransformer(pattern *regexp.Regexp, url []byte) *Transformer

func (*Transformer) LinkifyText

func (t *Transformer) LinkifyText(node *ast.Text, source []byte)

LinkifyText finds all LinkPattern matches in the given Text node and replaces them with Link nodes that point to ReplUrl.

func (*Transformer) Transform

func (t *Transformer) Transform(node *ast.Document, reader text.Reader, pc parser.Context)

Transform implements goldmark.parser.ASTTransformer

Jump to

Keyboard shortcuts

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