texlike

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

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

Go to latest
Published: Mar 11, 2022 License: MIT Imports: 8 Imported by: 0

README

goldmark-texlike

goldmark-texlike is an extension for the goldmark to provide support for TeX-like grammar, inline math uses the ${ and }$ delimiters by default, Block math uses the $${ and }$$ delimiters by default.

Note: This software does not handle TeX code, you need to use MathJax or KaTeX to render the math.

This software reference goldmark-mathjax.

Installation

go get github.com/Eumeryx/goldmark-texlike

Usage

import (
	"bytes"
	"fmt"

	texlike "github.com/Eumeryx/goldmark-texlike"
	"github.com/yuin/goldmark"
)

func main() {
	md := goldmark.New(
		goldmark.WithExtensions(texlike.NewTexlike(texlike.DefaultConfig)),
	)

	var buf bytes.Buffer
	if err := md.Convert([]byte(source), &buf); err != nil {
		fmt.Println(err)
	} else {
		fmt.Println(buf.String())
	}
}

Config

var DefaultConfig = Config{
	Block: TexBase{					// Block mathe configuration
		Delimit:       [2]string{`$${`, `}$$`},	// Set delimiters
		TagName:       `span`,			// HTML tag name
		ClassName:     []string{},		// HTML class name
		OutputDelimit: [2]string{},		// Replaces the delimiters in the output HTML
	},
	Inline: TexBase{				// Inline math configuration, see Block math
		Delimit:       [2]string{`${`, `}$`},
		TagName:       `span`,
		ClassName:     []string{},
		OutputDelimit: [2]string{},
	},
	RemoveOutputDelimit: false,			// Remove the delimiters from the output HTML
}

Why is the delimiters ${, }$ and $${, }$$

See this talk.

You can customize math delimiters, but I can't vouch for the correctness of custom delimiters.

License

MIT

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultConfig = Config{
	Block: TexBase{
		Delimit:       [2]string{`$${`, `}$$`},
		TagName:       `span`,
		ClassName:     []string{},
		OutputDelimit: [2]string{},
	},
	Inline: TexBase{
		Delimit:       [2]string{`${`, `}$`},
		TagName:       `span`,
		ClassName:     []string{},
		OutputDelimit: [2]string{},
	},
	RemoveOutputDelimit: false,
}
View Source
var KindTexBlock = ast.NewNodeKind("TexBlock")
View Source
var KindTexInline = ast.NewNodeKind("TexInline")

Functions

func NewTexBlockParser

func NewTexBlockParser(delimit [2]string) parser.BlockParser

func NewTexBlockRenderer

func NewTexBlockRenderer(htmlTag [2]string) renderer.NodeRenderer

func NewTexInlineParser

func NewTexInlineParser(delimit [2]string) parser.InlineParser

func NewTexInlineRenderer

func NewTexInlineRenderer(htmlTag [2]string) renderer.NodeRenderer

Types

type Config

type Config struct {
	Block               TexBase
	Inline              TexBase
	RemoveOutputDelimit bool
}

type TexBase

type TexBase struct {
	Delimit       [2]string
	TagName       string
	ClassName     []string
	OutputDelimit [2]string
}

type TexBlockNode

type TexBlockNode struct {
	ast.BaseBlock
}

AST

func NewTexBlockNode

func NewTexBlockNode() *TexBlockNode

func (*TexBlockNode) Dump

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

func (*TexBlockNode) IsRaw

func (n *TexBlockNode) IsRaw() bool

func (*TexBlockNode) Kind

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

type TexBlockParser

type TexBlockParser struct {
	// contains filtered or unexported fields
}

Parser

func (*TexBlockParser) CanAcceptIndentedLine

func (b *TexBlockParser) CanAcceptIndentedLine() bool

func (*TexBlockParser) CanInterruptParagraph

func (b *TexBlockParser) CanInterruptParagraph() bool

func (*TexBlockParser) Close

func (b *TexBlockParser) Close(node ast.Node, reader text.Reader, pc parser.Context)

func (*TexBlockParser) Continue

func (b *TexBlockParser) Continue(node ast.Node, reader text.Reader, pc parser.Context) parser.State

func (*TexBlockParser) Open

func (b *TexBlockParser) Open(parent ast.Node, reader text.Reader, pc parser.Context) (ast.Node, parser.State)

func (*TexBlockParser) Trigger

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

type TexBlockRenderer

type TexBlockRenderer struct {
	// contains filtered or unexported fields
}

Renderer

func (*TexBlockRenderer) RegisterFuncs

type TexInlineNode

type TexInlineNode struct {
	ast.BaseInline
}

AST

func NewTexInlineNode

func NewTexInlineNode() *TexInlineNode

func (*TexInlineNode) Dump

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

func (*TexInlineNode) Kind

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

type TexInlineParser

type TexInlineParser struct {
	// contains filtered or unexported fields
}

Parser

func (*TexInlineParser) Parse

func (s *TexInlineParser) Parse(parent ast.Node, block text.Reader, pc parser.Context) ast.Node

func (*TexInlineParser) Trigger

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

type TexInlineRenderer

type TexInlineRenderer struct {
	// contains filtered or unexported fields
}

Renderer

func (*TexInlineRenderer) RegisterFuncs

type Texlike

type Texlike struct {
	// contains filtered or unexported fields
}

func NewTexlike

func NewTexlike(r Config) *Texlike

func (*Texlike) Extend

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

Jump to

Keyboard shortcuts

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