img64

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2023 License: MIT Imports: 13 Imported by: 2

README

goldmark-img64

An extention of goldmark to embed local images into a rendered html file as base64 encoded data.

![alt](./image.png "title")
<p><img src="data:image/png;base64,..." alt="alt" title="title"></p>

Installation

go get github.com/tenkoh/goldmark-img64

Quick usage

When your target markdown file is in the current working directory, just do as below.

package main

import (
    "io"
    "os"

    "github.com/yuin/goldmark"
    img64 "github.com/tenkoh/goldmark-img64"
)

func main() {
    f, _ := os.Open("target.md")
    defer f.Close()
    b, _ := io.ReadAll(f)
    goldmark.New(goldmark.WithExtensions(img64.Img64)).Convert(b, os.Stdout)
}

When your target markdown is not in the current working directory, add WithParentPath option.

goldmark.New(
    goldmark.WithExtensions(img64.Img64),
    goldmark.WithRendererOptions(img64.WithParentPath(dir)),
)

This package supports these image types.

  • "image/apng"
  • "image/avif"
  • "image/gif"
  • "image/jpeg"
  • "image/png"
  • "image/svg+xml"
  • "image/webp"

License

MIT

Author

tenkoh

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Img64 = &img64{}

Img64 is an implementation of goldmark.Extender

Functions

func NewImg64

func NewImg64(opts ...Img64Option) goldmark.Extender

NewImg64 initializes Img64: goldmark's extension with its options. Using default Img64 with goldmark.WithRendereOptions(opts) give the same result.

func NewImg64Renderer

func NewImg64Renderer(opts ...Img64Option) renderer.NodeRenderer

func WithParentPath

func WithParentPath(path string) interface {
	renderer.Option
	Img64Option
}

Types

type Img64Config

type Img64Config struct {
	html.Config
	ParentPath string
}

Img64Config embeds html.Config to refer to some fields like unsafe and xhtml.

func (*Img64Config) SetOption

func (c *Img64Config) SetOption(name renderer.OptionName, value any)

SetOption implements renderer.NodeRenderer.SetOption

type Img64Option

type Img64Option interface {
	renderer.Option
	SetImg64Option(*Img64Config)
}

Jump to

Keyboard shortcuts

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