Skip to content

Commit

Permalink
feat: math plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
pd4d10 committed Jun 11, 2020
1 parent ab80adb commit 9265fed
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 0 deletions.
2 changes: 2 additions & 0 deletions packages/plugin-math/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
src/*.js
src/*.d.ts
21 changes: 21 additions & 0 deletions packages/plugin-math/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "@bytemd/plugin-math",
"version": "0.0.1",
"description": "@bytemd/plugin-math",
"author": "Rongjian Zhang <pd4d10@gmail.com>",
"license": "MIT",
"main": "dist/index.js",
"module": "dist/index.mjs",
"types": "src/index.d.ts",
"files": [
"**/dist",
"src/*.{js,d.ts}"
],
"dependencies": {
"rehype-katex": "^3.0.0",
"remark-math": "^2.0.1"
},
"peerDependencies": {
"bytemd": "*"
}
}
16 changes: 16 additions & 0 deletions packages/plugin-math/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { BytemdPlugin } from 'bytemd';
import remarkMath from 'remark-math';
import rehypeKatex from 'rehype-katex';

export default function math(): BytemdPlugin {
return {
remarkTransformer: (u) => u.use(remarkMath),
rehypeTransformer: (u) => u.use(rehypeKatex),
sanitizeSchema: {
attributes: {
span: ['className', 'style'],
// TODO: svg
},
},
};
}
1 change: 1 addition & 0 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const packageConfigs = {
// external: ['bytemd', 'react'],
// },
'plugin-highlight': {},
'plugin-math': {},
};

/** @type {import('rollup').Plugin} */
Expand Down

0 comments on commit 9265fed

Please sign in to comment.