qjskatex

package module
Version: v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2020 License: MIT Imports: 9 Imported by: 1

README

goldmark-qjs-katex

This is an extension for Goldmark that adds TeX rendering using KaTeX. It embeds QuickJS and QuickJS-compiled KaTeX bytecode.

The parser follows pandoc's rules for TeX in markdown. Right now, $ and $$ are the only supported delimiters. Also, only KaTeX's default configuration is supported.

Performance
goos: windows
goarch: amd64
pkg: github.com/graemephi/goldmark-qjs-katex
BenchmarkSequencesAndSeries/NoKaTeX-4              12210            981796 ns/op          381171 B/op       1497 allocs/op
BenchmarkSequencesAndSeries/NoCache-4                 10        1069105530 ns/op         4900488 B/op       1563 allocs/op
BenchmarkSequencesAndSeries/Cache-4                 5041           2329294 ns/op         4443003 B/op       1545 allocs/op

Usage

import (
	"github.com/graemephi/goldmark-qjs-katex"
	
	"github.com/yuin/goldmark"
)
markdown := goldmark.New(
	goldmark.WithExtensions(&qjskatex.Extension{}),
)

Also, godoc.

Building

If you just want to build, gcc must be installed, and all you need to do is

go build

However, if you modify ./katex/katex.js, then you must recompile the JS source to bytecode with qjsc. qjsc can be compiled from source in ./katex/quickjs/. In addition, if these modifications change the way TeX is rendered then you need to regenerate the test cases. This requires pandoc to be installed. Run

make

to do all that, or look in the Makefile to see how to do it.

Dependencies

Goldmark, KaTeX, QuickJS.

Licenses

Goldmark
MIT License

Copyright (c) 2019 Yusuke Inuzuka
KaTeX
The MIT License (MIT)

Copyright (c) 2013-2018 Khan Academy
QuickJS
QuickJS is released under the MIT license.

Unless otherwise specified, the QuickJS sources are copyright Fabrice
Bellard and Charlie Gordon.

Documentation

Overview

Package qjskatex is an extension for goldmark (github.com/yuin/goldmark) to perform server-side KaTeX rendering.

Note: the extension holds a sync.Map to cache rendered TeX for performance; it grows without bound.

markdown := goldmark.New(
	goldmark.WithExtensions(&qjskatex.Extension{}),
)

Index

Constants

This section is empty.

Variables

View Source
var KindTex = gma.NewNodeKind("TeX")

KindTex indicates that a node is of kind qjskatex.Node.

Functions

func ReportKatexNodes added in v0.3.0

func ReportKatexNodes(pc gmp.Context) int

ReportKatexNodes reports the number of KaTeX nodes seen by parsers using the Goldmark parser Context pc.

Types

type Extension

type Extension struct {
	// EnableWarnings allows KaTeX to print warnings to standard out.
	EnableWarnings bool

	// DisableCache disables the internal cache.
	DisableCache bool
	// contains filtered or unexported fields
}

Extension extends Goldmark with KaTeX, implementing goldmark.Extender. The configuration cannot be changed after calling Extend, i.e., after passing it into goldmark.New.

func (*Extension) Extend

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

Extend extends m.

type Node added in v0.3.0

type Node struct {
	gma.BaseInline
	// contains filtered or unexported fields
}

Node represents a KaTeX node in the Goldmark AST tree.

func (*Node) Dump added in v0.3.0

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

Dump dumps a textual representation this node.

func (*Node) Kind added in v0.3.0

func (n *Node) Kind() gma.NodeKind

Kind returns the kind of this node.

Source Files

Directories

Path Synopsis
Package katex exposes a simplified API to KaTeX, run on QuickJS.
Package katex exposes a simplified API to KaTeX, run on QuickJS.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL