images

package module
v0.0.0-...-49b26b7 Latest Latest
Warning

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

Go to latest
Published: Dec 26, 2019 License: MIT Imports: 5 Imported by: 1

README

goldmark-images

GoDoc

Goldmark image replacer extension.

imageURL := func (src string) string {
	return "test-" + src
}

source := []byte(`![alt](image.png "title")`)
gm := goldmark.New(
    images.NewReplacer(imageURL),
    goldmark.WithRendererOptions(html.WithXHTML()),
)
err = gm.Convert(source, os.Stdout)
<p><img src="test-image.png" alt="alt" title="title" /></p>

Documentation

Overview

Package images is a extension for the goldmark (http://github.com/yuin/goldmark).

This extension adds replacer render to change image urls.

Example
package main

import (
	"log"
	"os"

	images "github.com/mdigger/goldmark-images"
	"github.com/yuin/goldmark"
)

var source = []byte(`![alt](image.png "title")`)

func imageURL(src string) string {
	return "test-" + src
}

func main() {
	gm := goldmark.New(
		images.NewReplacer(imageURL),
	)
	if err := gm.Convert(source, os.Stdout); err != nil {
		log.Fatal(err)
	}
}
Output:

<p><img src="test-image.png" alt="alt" title="title"></p>

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(r ReplaceFunc, options ...html.Option) goldmark.Extender

New return initialized image render with source url replacing support.

func NewReplacer

func NewReplacer(r ReplaceFunc) goldmark.Option

NewReplacer adding src url replacing function to image html render.

Types

type ReplaceFunc

type ReplaceFunc = func(link string) string

ReplaceFunc is a function for replacing image source link.

Jump to

Keyboard shortcuts

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