media

package module
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2022 License: MIT Imports: 11 Imported by: 0

README

goldmark-media-tags

Go Reference

A media tags extension for GoldMark.

Inspired by flexmark-java <flexmark-ext-media-tags> (java)

Supports

<media>, <audio>, <picture>, <iframe> and <embed>.

!v[This is a video](https://example.org/test.webm)
!a[And this is an audio](https://example.org/test.mp3)
!p[And this a picture](https://example.org/test.png)
!i[And this an iframe](https://example.org/frame.html)
!e[And this an embed](https://example.org/embed.svg)

Renders to:


<p>
    <video controls>
        <source src="https://example.org/test.webm">
    </video>
    <audio controls>
        <source src="https://example.org/test.mp3">
    </audio>
    <picture>
        <img alt="And this a picture" src="https://example.org/test.png">
    </picture>
    <iframe src="https://example.org/frame.html"></iframe>
    <embed src="https://example.org/embed.svg"></embed>
</p>

Usage

check extension_test.go

Documentation

Index

Constants

View Source
const (
	TypePicture  Type = 'p'
	TypeVideo    Type = 'v'
	TypeAudio    Type = 'a'
	TypeIFrame   Type = 'i'
	TypeEmbed    Type = 'e'
	AttrControls      = "controls"
	AttrAutoplay      = "autoplay"
	AttrLoop          = "loop"
	AttrMuted         = "muted"
	AttrPreload       = "preload"
)

Variables

View Source
var KindImg = ast.NewNodeKind("MediaSourceImage")
View Source
var KindMedia = ast.NewNodeKind("MediaParent")
View Source
var KindSource = ast.NewNodeKind("MediaSourceSource")

Functions

func MatchAndAdvance added in v0.3.2

func MatchAndAdvance(reader text.Reader, reg *regexp.Regexp) []string

Types

type Extension

type Extension struct {
	Options
}

func WithDefaults

func WithDefaults() Extension

func WithOptions

func WithOptions(options Options) Extension

func (Extension) Extend

func (e Extension) Extend(md goldmark.Markdown)

type HasSrc added in v0.3.1

type HasSrc interface {
	GetSrc() string
	SetSrc(src string)
}

type Media

type Media struct {
	ast.BaseInline
	MediaType Type
	Alt       string
	Link      string
}

Media represents an inline <video>, <audio> or <picture> node

func (*Media) Dump

func (n *Media) Dump(source []byte, level int)

Dump implements Node.Dump

func (*Media) Kind

func (n *Media) Kind() ast.NodeKind

Kind implements Node.Kind

func (*Media) Text added in v0.3.0

func (n *Media) Text(source []byte) []byte

type Options

type Options struct {
	// MediaControls default is true, affects <audio> and <video>
	MediaControls bool
	// MediaAutoplay default is false, affects <audio> and <video>
	MediaAutoplay bool
	// MediaLoop default is false, affects <audio> and <video>
	MediaLoop bool
	// MediaMuted default is false, affects <audio> and <video>
	MediaMuted bool
	// MediaPreload default is empty string(""). Affects <audio> and <video>
	MediaPreload string
}

type TagSourceImg added in v0.3.0

type TagSourceImg struct {
	ast.BaseInline

	Src string
	Alt string
	// contains filtered or unexported fields
}

func (TagSourceImg) Dump added in v0.3.0

func (t TagSourceImg) Dump(source []byte, level int)

Dump implements ast.Node.Dump

func (TagSourceImg) GetSrc added in v0.3.1

func (t TagSourceImg) GetSrc() string

func (TagSourceImg) Kind added in v0.3.0

func (t TagSourceImg) Kind() ast.NodeKind

Kind implements ast.Node.Kind

func (*TagSourceImg) SetSrc added in v0.3.1

func (t *TagSourceImg) SetSrc(src string)

type TagSourceSource added in v0.3.0

type TagSourceSource struct {
	ast.BaseInline

	Src string
	// SrcSet is only used in <picture>s
	SrcSet string
	// contains filtered or unexported fields
}

func (TagSourceSource) Dump added in v0.3.0

func (t TagSourceSource) Dump(source []byte, level int)

Dump implements ast.Node.Dump

func (TagSourceSource) GetSrc added in v0.3.1

func (t TagSourceSource) GetSrc() string

func (TagSourceSource) Kind added in v0.3.0

func (t TagSourceSource) Kind() ast.NodeKind

Kind implements ast.Node.Kind

func (*TagSourceSource) SetSrc added in v0.3.1

func (t *TagSourceSource) SetSrc(src string)

type Type added in v0.2.0

type Type byte

Jump to

Keyboard shortcuts

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