katex

package module
v2.1.0 Latest Latest
Warning

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

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

README

Goldmark Katex

Goldmark Katex is a Goldmark extension providing math and equation support through KaTeX.

Usage

github.com/kingreatwill/goldmark-katex/v2

goldmark.New(goldmark.WithExtensions(katex.KaTeX)).Convert(src, dst)

Wrap inline math with a pair of single $:

$A$

Wrap block math with a pair of double $:

$$
A = \pi \times r^2
$$

Example

Given the radius $r$ of a circle, the area $A$ is:

$$
A = \pi \times r^2
$$

And the circumference $C$ is:

$$
C = 2 \pi r
$$

<!DOCTYPE html>
<!-- KaTeX requires the use of the HTML5 doctype. Without it, KaTeX may not render properly -->
<html>
  <head>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.16.11/dist/katex.min.css" integrity="sha384-nB0miv6/jRmo5UMMR1wu3Gz6NLsoTkbqJghGIsx//Rlm+ZU03BU6SQNC66uf4l5+" crossorigin="anonymous">

    <!-- The loading of KaTeX is deferred to speed up page rendering -->
    <script defer src="https://cdn.jsdelivr.net/npm/katex@0.16.11/dist/katex.min.js" integrity="sha384-7zkQWkzuo3B5mTepMUcHkMB5jZaolc2xDwL6VFqjFALcbeS9Ggm/Yr2r3Dy4lfFg" crossorigin="anonymous"></script>

    <!-- To automatically render math in text elements, include the auto-render extension: -->
    <script defer src="https://cdn.jsdelivr.net/npm/katex@0.16.11/dist/contrib/auto-render.min.js" integrity="sha384-43gviWU0YVjaDtb/GhzOouOXtZMP/7XUzwPTstBeZFe/+rCMvRwr4yROQP43s0Xk" crossorigin="anonymous"
        onload="renderMathInElement(document.body);"></script>
  </head>
  ...
</html>

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
var KaTeX = &Extender{}
View Source
var KindBlock = ast.NewNodeKind("Block")
View Source
var KindInline = ast.NewNodeKind("Inline")

Functions

func Render

func Render(w io.Writer, src []byte, display bool) error
Example
b := bytes.Buffer{}
Render(&b, []byte(`Y = A \dot X^2 + B \dot X + C`), false)
fmt.Println(b.String())
Output:

Types

type Block

type Block struct {
	ast.BaseInline

	Equation []byte
}

func (*Block) Dump

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

func (*Block) IsBlank

func (n *Block) IsBlank(source []byte) bool

func (*Block) Kind

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

type Extender

type Extender struct {
}

func (*Extender) Extend

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

type HTMLRenderer

type HTMLRenderer struct {
	html.Config
}

func (*HTMLRenderer) RegisterFuncs

func (r *HTMLRenderer) RegisterFuncs(reg renderer.NodeRendererFuncRegisterer)

type Inline

type Inline struct {
	ast.BaseInline

	Equation []byte
}

func (*Inline) Dump

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

func (*Inline) Inline

func (n *Inline) Inline()

func (*Inline) IsBlank

func (n *Inline) IsBlank(source []byte) bool

func (*Inline) Kind

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

type Parser

type Parser struct {
}

func (*Parser) Parse

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

func (*Parser) Trigger

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

Jump to

Keyboard shortcuts

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