0.4.14 • Published 5 months ago

fastrender v0.4.14

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

fastrender

Real-time Markdown and LaTeX rendering library using WebAssembly.

Features

  • Fast Markdown rendering using WebAssembly
  • LaTeX support via KaTeX
  • Mixed content support (Markdown with inline and display LaTeX)
  • Caching for improved performance
  • TypeScript support

Installation

npm install fastrender
# or
yarn add fastrender
# or
bun add fastrender

Usage

import fastrender from 'fastrender';

// Create an instance
const fastrender = new fastrender({
  debug: false,
  katexOptions: {
    throwOnError: false
  }
});

// Render Markdown
const markdown = await fastrender.renderMarkdown(`
# Hello World
This is **bold** text.
`);

// Render LaTeX
const latex = fastrender.renderLatex('\\frac{1}{2}');

// Render mixed content
const mixed = await fastrender.renderMixed(`
# Math Example
Here's an inline equation: $E = mc^2$

And a display equation:
$$
\\frac{-b \\pm \\sqrt{b^2-4ac}}{2a}
$$
`);

API

new fastrender(options?)

Creates a new fastrender instance.

Options:

  • debug?: boolean - Enable debug mode
  • katexOptions?: KatexOptions - KaTeX rendering options

renderMarkdown(content: string): Promise<string>

Renders Markdown content to HTML.

renderLatex(content: string, displayMode?: boolean): string

Renders LaTeX content to HTML.

renderMixed(content: string): Promise<string>

Renders mixed Markdown and LaTeX content to HTML.

clearCache(): void

Clears the internal render cache.

Examples

Pure Markdown

const markdown = await fastrender.renderMarkdown(`
# Hello World
This is a **bold** statement.
`);

Pure LaTeX

const latex = fastrender.renderLatex('\\frac{-b \\pm \\sqrt{b^2-4ac}}{2a}', true);

Mixed Content

const mixed = await fastrender.renderMixed(`
# Math and Text Combined

Here's the quadratic formula: $ax^2 + bx + c = 0$

The solution is:

$$x = \\frac{-b \\pm \\sqrt{b^2-4ac}}{2a}$$

And here's Einstein's famous equation: $E = mc^2$
`);

Development

# Install dependencies
bun install

# Run development server
bun run dev

# Run tests
bun run test

# Run benchmarks
bun run benchmark

License

MIT

0.4.9

5 months ago

0.4.8

5 months ago

0.3.9

5 months ago

0.4.10

5 months ago

0.4.13

5 months ago

0.4.14

5 months ago

0.4.11

5 months ago

0.4.12

5 months ago

0.3.0

5 months ago

0.2.1

5 months ago

0.4.5

5 months ago

0.3.6

5 months ago

0.2.7

5 months ago

0.1.8

5 months ago

0.4.4

5 months ago

0.3.5

5 months ago

0.2.6

5 months ago

0.1.7

5 months ago

0.4.7

5 months ago

0.3.8

5 months ago

0.2.9

5 months ago

0.4.6

5 months ago

0.3.7

5 months ago

0.2.8

5 months ago

0.1.9

5 months ago

0.4.1

5 months ago

0.3.2

5 months ago

0.2.3

5 months ago

0.1.4

5 months ago

0.3.1

5 months ago

0.2.2

5 months ago

0.4.3

5 months ago

0.3.4

5 months ago

0.2.5

5 months ago

0.1.6

5 months ago

0.4.2

5 months ago

0.3.3

5 months ago

0.2.4

5 months ago

0.1.5

5 months ago

0.1.3

5 months ago

0.1.2

5 months ago

0.1.1

5 months ago

0.1.0

5 months ago