Skip to content

Commit

Permalink
Merge pull request #6 from Daiji256/1.0.0
Browse files Browse the repository at this point in the history
1.0.0 stable
  • Loading branch information
Daiji256 authored Nov 15, 2024
2 parents 6813f48 + b2f0eda commit 9cd35ed
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 432 deletions.
13 changes: 9 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# @daiji256/rehype-mathml

**[rehype][]** plugin to render math with MathML.
This plugin converts LaTeX math to MathML using [temml][].
**[rehype][]** plugin to render math with MathML by
converting LaTeX math to MathML using temml.
The reason for using [temml][] is that it is a lightweight library
with a wide coverage of LaTeX functions.

## Contents

Expand All @@ -26,12 +28,14 @@ with [`remark-math`][remark-math] for a `$C$` syntax extension.

## When should I use this?

This project is useful as it renders math with MathML at compile time, which
means that there is no client side JavaScript needed.
This project is useful as it renders math with MathML at compile time,
which means that no client-side JavaScript or images are needed.

This plugin is the MathML version of other plugins like
[`rehype-mathjax`][rehype-mathjax] (renders with MathJax) and
[`rehype-katex`][rehype-katex] (renders with KaTeX).
With MathML, the HTML becomes simpler and lighter.
Additionally, it supports the use of math fonts like [Noto Math][note-math].

## Install

Expand Down Expand Up @@ -151,5 +155,6 @@ It exports the additional type [`Options`](#options).
[rehype-katex]: https://github.com/remarkjs/remark-math/tree/main/packages/rehype-katex
[npm]: https://docs.npmjs.com/cli/install
[typescript]: https://www.typescriptlang.org
[note-math]: https://github.com/notofonts/math
[license]: LICENSE
[author]: https://github.com/Daiji256
7 changes: 2 additions & 5 deletions lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import type { Plugin } from 'unified';
import temml from 'temml';
import { SKIP, visitParents } from 'unist-util-visit-parents';
import { toText } from 'hast-util-to-text';
import { unified } from 'unified';
import rehypeParse from 'rehype-parse';
import { fromHtmlIsomorphic } from 'hast-util-from-html-isomorphic';

type Options = Partial<temml.Options>;

Expand Down Expand Up @@ -45,9 +44,7 @@ const rehypeMathML: Plugin<[Options?], Root> = (options) => {
latex,
Object.assign({}, options || {}, { displayMode: displayMode }),
);
result = unified()
.use(rehypeParse, { fragment: true })
.parse(mathml).children;
result = fromHtmlIsomorphic(mathml, { fragment: true }).children;
} catch (error) {
result = [
{
Expand Down
Loading

0 comments on commit 9cd35ed

Please sign in to comment.