embed

package module
v0.0.0-...-e6806f2 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2020 License: MIT Imports: 8 Imported by: 7 modules, 5 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

goldmark-embed

goldmark-embed is an extension for the goldmark library that extends the Markdown ![]() image embed syntax to support additional media formats.

YouTube only at first.

Demo

This markdown:

# Hello goldmark-embed

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

Becomes this HTML:

<h1>Hello goldmark-embed</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>
Installation
go get github.com/13rac1/goldmark-embed

Usage

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

TODO

  • Embed Options
  • Additional Data Sources

License

MIT

Author

Brad Erickson

Documentation

Index

Constants

This section is empty.

Variables

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 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, v string) *YouTube

NewYouTube returns a new YouTube node.

func (*YouTube) Kind

func (n *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
⌂ 换网址