embed

package module
v0.0.0-...-3e5148e Latest Latest
Warning

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

Go to latest
Published: May 4, 2022 License: MIT Imports: 8 Imported by: 0

README

goldmark-embed

goldmark-embed is based on 13rac1's extension for the goldmark library that extends the Markdown ![]() image embed syntax to support additional media formats.

Supports YouTube and Vimeo links.

Demo

This markdown:

# Hello goldmark-embed for YouTube

![](https://www.youtube.com/watch?v=dQw4w9WgXcQ)

# Hello goldmark-embed for Vimeo

![](https://vimeo.com/148751763)

Becomes this HTML:

<h1>Hello goldmark-embed for Youtube</h1>
<p><iframe width="560" height="315" src="https://www.youtube.com/embed/dQw4w9WgXcQ" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe></p>
<h1>Hello goldmark-embed for Vimeo</h1>
<p><iframe src="https://player.vimeo.com/video/148751763?&amp;badge=0&amp;autopause=0&amp;player_id=0&amp;app_id=58479" width="724" height="404" frameborder="0" allow="autoplay; fullscreen; picture-in-picture" allowfullscreen></iframe></p>
Installation
go get github.com/PaperPrototype/goldmark-embed

Usage

  markdown := goldmark.New(
    goldmark.WithExtensions(
      embed.New(),
    ),
  )
  var buf bytes.Buffer
  if err := markdown.Convert([]byte(source), &buf); err != nil {
    panic(err)
  }
  
  // output html
  fmt.Print(buf)
}

TODO

  • Embed Options
  • Additional Data Sources

License

MIT

Authors

Brad Erickson Abdiel Lopez

Documentation

Index

Constants

This section is empty.

Variables

View Source
var KindVimeo = ast.NewNodeKind("Vimeo")

KindVimeo is a NodeKind of the Vimeo node.

View Source
var KindYouTube = ast.NewNodeKind("YouTube")

KindYouTube is a NodeKind of the YouTube node.

Functions

func New

func New(opts ...Option) goldmark.Extender

New returns a new Embed extension.

func NewHTMLRenderer

func NewHTMLRenderer() renderer.NodeRenderer

NewHTMLRenderer builds a new HTMLRenderer with given options and returns it.

Types

type HTMLRenderer

type HTMLRenderer struct{}

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

func (*HTMLRenderer) RegisterFuncs

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

RegisterFuncs implements NodeRenderer.RegisterFuncs.

type Option

type Option func(*embedExtension)

Option is a functional option type for this extension.

type Vimeo

type Vimeo struct {
	ast.Image
	Video string
}

Vimeo struct represents a Vimeo Video embed of the markdown text.

func NewVimeo

func NewVimeo(img *ast.Image, video string) *Vimeo

New Vimeo returns a new Vimeo node.

func (*Vimeo) Kind

func (node *Vimeo) Kind() ast.NodeKind

implements Node.Kind.

type YouTube

type YouTube struct {
	ast.Image
	Video string
}

YouTube struct represents a YouTube Video embed of the Markdown text.

func NewYouTube

func NewYouTube(img *ast.Image, video string) *YouTube

NewYouTube returns a new YouTube node.

func (*YouTube) Kind

func (node *YouTube) Kind() ast.NodeKind

Kind implements Node.Kind.

Jump to

Keyboard shortcuts

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