ruby

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2024 License: MIT Imports: 9 Imported by: 0

README

goldmark-ruby

Go Reference

goldmark-ruby is an extension for the goldmark that parses DenDenMarkdown style rubys (like {漢字|かんじ}).

This extension has nothing to do with the original authors of DenDenMarkdown.

Installation

go get github.com/mi759/goldmark-ruby

Usage

import (
	"bytes"
	"fmt"

	ruby "github.com/mi759/goldmark-ruby"
	"github.com/yuin/goldmark"
)

func main() {
	markdown := goldmark.New(
		goldmark.WithExtensions(
			ruby.Ruby,
		),
	)
	source := `ああ、{素晴|すば}らしき{新世界|しん|せ|かい}!`
	var buf bytes.Buffer
	err := markdown.Convert([]byte(source), &buf)
	if err != nil {
		panic(err)
	}
	fmt.Print(buf.String())
}

License

MIT

Documentation

Index

Constants

This section is empty.

Variables

View Source
var KindRubyChild = gast.NewNodeKind("RubyChild")
View Source
var KindRubyParent = gast.NewNodeKind("RubyParent")
View Source
var Ruby = &RubyExtender{}

Ruby is an extension that allow you to use various ruby expressions.

Functions

This section is empty.

Types

type RubyChild

type RubyChild struct {
	gast.BaseInline
	BaseText []byte // BaseText is the text to be annotated.
	RubyText []byte // RubyText is the annotation.
}

RubyChild node has the actual information of the ruby.

func NewRubyChild

func NewRubyChild(baseText []byte, rubyText []byte) *RubyChild

NewRubyChild returns a new RubyChild node.

func (*RubyChild) Dump

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

Dump dumps the RubyChild node to stdout for debugging.

func (*RubyChild) Kind

func (n *RubyChild) Kind() gast.NodeKind

Kind implements Node.Kind.

type RubyExtender

type RubyExtender struct {
}

func (*RubyExtender) Extend

func (e *RubyExtender) Extend(m goldmark.Markdown)

Extend implements goldmark.Extender.

type RubyHTMLRenderer

type RubyHTMLRenderer struct{}

func (*RubyHTMLRenderer) RegisterFuncs

RegisterFuncs implements renderer.NodeRenderer.RegisterFuncs. It tells goldmark which render function to call when it encounters ruby nodes in the AST.

func (*RubyHTMLRenderer) RenderRubyChild

func (r *RubyHTMLRenderer) RenderRubyChild(w util.BufWriter, source []byte, node gast.Node, entering bool) (gast.WalkStatus, error)

RenderRubyParent renders the provided RubyChild node.

func (*RubyHTMLRenderer) RenderRubyParent

func (r *RubyHTMLRenderer) RenderRubyParent(w util.BufWriter, source []byte, node gast.Node, entering bool) (gast.WalkStatus, error)

RenderRubyParent renders the provided RubyParent node.

type RubyParent

type RubyParent struct {
	gast.BaseInline
}

RubyParent node holds RubyChild node(s). It itself has no special field.

func NewRubyParent

func NewRubyParent() *RubyParent

NewRubyParent returns a new RubyParent node.

func (*RubyParent) Dump

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

Dump dumps the RubyParent node to stdout for debugging.

func (*RubyParent) Kind

func (n *RubyParent) Kind() gast.NodeKind

Kind implements Node.Kind.

type RubyParser

type RubyParser struct {
}

func (*RubyParser) Parse

func (p *RubyParser) Parse(_ ast.Node, block text.Reader, _ parser.Context) ast.Node

Parse parses a markdown ruby.

func (*RubyParser) Trigger

func (s *RubyParser) Trigger() []byte

Jump to

Keyboard shortcuts

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