goldmark-emoji – github.com/yuin/goldmark-emoji Index | Files | Directories

package emoji

import "github.com/yuin/goldmark-emoji"

package emoji is a extension for the goldmark(http://github.com/yuin/goldmark).

Index

Constants

const DefaultTwemojiTemplate = "" /* 136 byte string literal not displayed */

DefaultTwemojiTemplate is a default value for RendererConfig.TwemojiTemplate.

Variables

var Emoji = &emoji{
	options: []Option{},
}

Emoji is a goldmark.Extender implementation.

Functions

func New

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

New returns a new extension with given options.

func NewHTMLRenderer

func NewHTMLRenderer(opts ...RendererOption) renderer.NodeRenderer

NewHTMLRenderer returns a new HTMLRenderer.

func NewParser

func NewParser(opts ...ParserOption) parser.InlineParser

NewParser returns a new parser.InlineParser that can parse emoji expressions.

Types

type Option

type Option interface {
	// contains filtered or unexported methods
}

Option interface sets options for this extension.

func WithEmojis

func WithEmojis(value definition.Emojis) Option

WithMaping is a functional option that defines links names to unicode emojis.

func WithRendererFunc

func WithRendererFunc(f RendererFunc) Option

WithRendererFunc is a functional option that changes a renderer func.

func WithRenderingMethod

func WithRenderingMethod(a RenderingMethod) Option

WithRenderingMethod is a functional option that indicates how emojis are rendered.

func WithTwemojiTemplate

func WithTwemojiTemplate(s string) Option

WithTwemojiTemplate is a functional option that changes a twemoji img tag.

type ParserConfig

type ParserConfig struct {
	Emojis definition.Emojis
}

ParserConfig struct is a data structure that holds configuration of the Emoji extension.

func (*ParserConfig) SetOption

func (c *ParserConfig) SetOption(name parser.OptionName, value interface{})

SetOption implements parser.SetOptioner

type ParserOption

type ParserOption interface {
	Option
	parser.Option

	SetEmojiOption(*ParserConfig)
}

A ParserOption interface sets options for the emoji parser.

type RendererConfig

type RendererConfig struct {
	html.Config

	// Method indicates how emojis are rendered.
	Method RenderingMethod

	// TwemojiTemplate is a printf template for twemoji. This value is valid only when Method is set to Twemoji.
	// `printf` arguments are:
	//
	//     1: name (e.g. "face with tears of joy")
	//     2: file name without an extension (e.g. 1f646-2642)
	//     3: '/' if XHTML, otherwise ''
	//
	TwemojiTemplate string

	// RendererFunc is a RendererFunc that renders emojis. This value is valid only when Method is set to Func.
	RendererFunc RendererFunc
}

RendererConfig struct holds options for the emoji renderer.

func (*RendererConfig) SetOption

func (c *RendererConfig) SetOption(name renderer.OptionName, value interface{})

SetOption implements renderer.SetOptioner.

type RendererFunc

type RendererFunc func(w util.BufWriter, source []byte, n *east.Emoji, config *RendererConfig)

RendererFunc will be used for rendering emojis.

type RendererOption

type RendererOption interface {
	Option
	renderer.Option

	SetEmojiOption(*RendererConfig)
}

A RendererOption interface sets options for the emoji renderer.

type RenderingMethod

type RenderingMethod int

RenderingMethod indicates how emojis are rendered.

const (
	// Entity renders an emoji as an html entity.
	Entity RenderingMethod = iota

	// Unicode renders an emoji as unicode character.
	Unicode

	// Twemoji renders an emoji as an img tag with [twemoji](https://github.com/twitter/twemoji).
	Twemoji

	// Func renders an emoji using RendererFunc.
	Func
)

Source Files

emoji.go

Directories

PathSynopsis
astPackage ast defines AST nodes that represetns emoji extension's elements.
definitionCode generated by _tools; DO NOT EDIT.
_tools
Version
v1.0.6 (latest)
Published
Apr 19, 2025
Platform
js/wasm
Imports
11 packages
Last checked
now

Tools for package owners.