images

package module
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2022 License: MIT Imports: 5 Imported by: 0

README

goldmark-images

Goldmark image replacer extension, base on mdigger/goldmark-images.

support image lazyload and more customize attribute.

code

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

func Example() {
	md := goldmark.New(
		goldmark.WithExtensions(
			images.NewExtender(
				"/loading.gif", // source
				"data-src",    // target
				map[string]string{
					"class": "lazy", // arrtibute
				}),
		),
	)
	if err := md.Convert(source, os.Stdout); err != nil {
		log.Fatal(err)
	}
}

view

<p>
<img src="/loading.gif" alt="alt" title="title" class="lazy" data-src="image.png">
</p>

thanks

Goldmark

mdigger

Documentation

Overview

Example
package main

import (
	"log"
	"os"

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

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

func main() {
	md := goldmark.New(
		goldmark.WithExtensions(
			images.NewExtender(
				"/loading.gif", // source
				"data-src",     // target
				map[string]string{
					"class": "lazy", // arrtibute
				}),
		),
	)
	if err := md.Convert(source, os.Stdout); err != nil {
		log.Fatal(err)
	}

}
Output:

<p>
<img src="/loading.gif" alt="alt" title="title" class="lazy" data-src="image.png">
</p>

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewExtender

func NewExtender(source, target string, attribute map[string]string) goldmark.Extender

New return initialized image render with source url replacing support.

func NewRenderer

func NewRenderer() renderer.NodeRenderer

NewRenderer builds a new Renderer with given options and returns it.

Types

type Extender

type Extender struct {
	Source    string
	Target    string
	Attribute map[string]string
}

func (*Extender) Extend

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

type Renderer

type Renderer struct {
	html.Config
}

Renderer struct is a renderer.NodeRenderer implementation for the extension.

func (*Renderer) RegisterFuncs

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

RegisterFuncs implements NodeRenderer.RegisterFuncs interface.

Jump to

Keyboard shortcuts

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