Skip to content

Commit

Permalink
feat: properly handle math
Browse files Browse the repository at this point in the history
  • Loading branch information
uetchy committed Jul 2, 2020
1 parent b8df478 commit 45f2687
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
13 changes: 13 additions & 0 deletions src/plugins/math.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import is from 'hast-util-is-element';
import katex from 'rehype-katex';
import { Node } from 'unist';
import remove from 'unist-util-remove';

const removeMathML = () => (tree: Node) => {
remove(tree, (node: any) => {
const isKatexMathML = node.properties?.className?.includes('katex-mathml');
return is(node, 'span') && isKatexMathML;
});
};

export const plugin = { plugins: [katex, removeMathML] };
4 changes: 2 additions & 2 deletions src/revive-rehype.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import mathjax from 'rehype-mathjax';
import raw from 'rehype-raw';
import slug from 'rehype-slug';
import remark2rehype from 'remark-rehype';
import unified from 'unified';
import {handler as figure} from './plugins/figure';
import {handler as ruby} from './plugins/ruby';
import {inspect} from './utils/debug';
import { plugin as math } from './plugins/math';

export default [
[remark2rehype, {allowDangerousHtml: true, handlers: {ruby}}],
raw,
mathjax,
figure,
math,
slug,
inspect('hast'),
] as unified.PluggableList<unified.Settings>;

0 comments on commit 45f2687

Please sign in to comment.