├── .nojekyll ├── .gitignore ├── index.html ├── .github └── workflows │ ├── test.yml │ ├── release.yml │ └── gh-pages.yml ├── CONTRIBUTING.md ├── LICENSE ├── test.jsx ├── package.json ├── demo.jsx ├── README.md └── index.jsx /.nojekyll: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | .parcel-cache 3 | dist -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | react-mathjax-preview 4 | 5 | 6 |
7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /.github/workflows/test.yml: -------------------------------------------------------------------------------- 1 | name: run tests 2 | 3 | on: [push, pull_request] 4 | 5 | jobs: 6 | test: 7 | runs-on: ubuntu-20.04 8 | 9 | steps: 10 | - uses: actions/checkout@v2 11 | - uses: actions/setup-node@v2 12 | with: 13 | node-version: '14' 14 | - run: yarn install 15 | - run: yarn run test 16 | 17 | -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | name: release 2 | on: 3 | push: 4 | branches: 5 | - master 6 | jobs: 7 | test: 8 | runs-on: ubuntu-20.04 9 | steps: 10 | - uses: actions/checkout@v2 11 | - uses: actions/setup-node@v2 12 | with: 13 | node-version: '14' 14 | - run: yarn install 15 | - run: yarn run test 16 | release: 17 | needs: test 18 | runs-on: ubuntu-20.04 19 | steps: 20 | - uses: actions/checkout@v2 21 | - uses: actions/setup-node@v2 22 | with: 23 | node-version: '14' 24 | - run: yarn install 25 | - run: yarn build 26 | - uses: mikeal/merge-release@master 27 | env: 28 | NPM_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} 29 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} -------------------------------------------------------------------------------- /.github/workflows/gh-pages.yml: -------------------------------------------------------------------------------- 1 | name: github pages 2 | 3 | on: 4 | push: 5 | branches: 6 | - master 7 | 8 | jobs: 9 | build-deploy: 10 | name: Publish demo website 11 | runs-on: ubuntu-20.04 12 | 13 | steps: 14 | - name: Checkout 15 | uses: actions/checkout@v2 16 | 17 | - uses: actions/setup-node@v2 18 | with: 19 | node-version: '14' 20 | 21 | - run: yarn install 22 | - run: yarn run parcel build --target demo --no-optimize index.html --dist-dir dist/demo --public-url https://mehdisadeghi.github.io/react-mathjax-preview 23 | - run: touch dist/demo/.nojekyll 24 | 25 | - name: Deploy page 26 | uses: JamesIves/github-pages-deploy-action@4.1.0 27 | with: 28 | branch: gh-pages 29 | folder: dist/demo 30 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | ## Prerequisites 2 | 3 | [Node.js](http://nodejs.org/) >= v4 must be installed. 4 | 5 | ## Installation 6 | 7 | - Running `yarn install` in the components's root directory will install everything you need for development. 8 | 9 | ## Development 10 | 11 | - `yarn start` will run a development server with the component's demo app at [http://localhost:3000](http://localhost:3000) with hot module reloading. 12 | 13 | - `yarn test` runs the tests with `jest`. 14 | 15 | - `yarn build` builds the component for publishing to npm in the `dist` folder. 16 | 17 | - `yarn build:demo` builds the demo app in the `dist` folder. 18 | 19 | ## Packaging 20 | For packaging and transforms `parcel` and `bable` have been used. The `.babelrc` 21 | is there because of `jest`, otherwise the default `parcel` configs would work build 22 | the react project properly. 23 | 24 | Initially I had used nwb and later neutrinojs, however they were unnecessary for this extremely small project, which is basically one single component. So, using 25 | `parcel` and removing extra folders simplified everything a great deal. 26 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Mehdi Sadeghi 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /test.jsx: -------------------------------------------------------------------------------- 1 | import expect from "expect"; 2 | import React from "react"; 3 | import { render, unmountComponentAtNode } from "react-dom"; 4 | 5 | import ReactMathjaxPreview from "./index.jsx"; 6 | 7 | describe("ReactMathjaxPreview", () => { 8 | let node; 9 | 10 | beforeEach(() => { 11 | node = document.createElement("div"); 12 | }); 13 | 14 | afterEach(() => { 15 | unmountComponentAtNode(node); 16 | }); 17 | 18 | // TODO: test MathJax rendered output 19 | it("renders MathJax", () => { 20 | render( 21 | , 24 | node, 25 | () => { 26 | expect(node.innerHTML).toContain("react-mathjax-preview-result"); 27 | } 28 | ); 29 | }); 30 | 31 | it("renders MathJax with dynamic script", () => { 32 | render( 33 | , 37 | node, 38 | () => { 39 | expect(node.innerHTML).toContain("react-mathjax-preview-result"); 40 | } 41 | ); 42 | }); 43 | }); 44 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "react-mathjax-preview", 3 | "version": "2.2.1", 4 | "description": "The MathJax React component you were looking for.", 5 | "author": "Mehdi Sadeghi", 6 | "homepage": "https://github.com/mehdisadeghi/react-mathjax-preview", 7 | "license": "MIT", 8 | "repository": "https://github.com/mehdisadeghi/react-mathjax-preview", 9 | "keywords": [ 10 | "react", 11 | "react-component", 12 | "mathjax", 13 | "tex", 14 | "asciimath", 15 | "mathml" 16 | ], 17 | "main": "dist/index.js", 18 | "files": [ 19 | "dist/index.*" 20 | ], 21 | "peerDependencies": { 22 | "prop-types": "^15", 23 | "react": "^16 || ^17", 24 | "react-dom": "^16 || ^17" 25 | }, 26 | "scripts": { 27 | "start": "parcel serve -p 3000 index.html", 28 | "build": "parcel build --target main --no-optimize index.jsx", 29 | "build:demo": "parcel build --target demo --no-optimize index.html --dist-dir dist/demo", 30 | "test": "jest" 31 | }, 32 | "devDependencies": { 33 | "@babel/preset-env": "^7.16.11", 34 | "@babel/preset-react": "^7.16.7", 35 | "babel-jest": "^27.5.1", 36 | "jest": "^27.5.1", 37 | "parcel": "^2.3.2", 38 | "prop-types": "^15", 39 | "react": "^16 || ^17", 40 | "react-dom": "^16 || ^17" 41 | }, 42 | "dependencies": { 43 | "dompurify": "^2.0.8" 44 | }, 45 | "targets": { 46 | "main": {}, 47 | "demo": {} 48 | }, 49 | "jest": { 50 | "transform": { 51 | "\\.[jt]sx?$": "babel-jest" 52 | }, 53 | "testEnvironment": "jsdom" 54 | }, 55 | "babel": { 56 | "presets": [ 57 | "@babel/preset-react", 58 | "@babel/preset-env" 59 | ] 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /demo.jsx: -------------------------------------------------------------------------------- 1 | import React, { useState } from 'react' 2 | import ReactDOM from 'react-dom' 3 | import ReactMathjaxPreview from './index.jsx' 4 | 5 | const asciimath = '`sum_(i=1)^n i^3=((n(n+1))/2)^2`' 6 | const someMath = String.raw` 7 | 8 | 9 | x + y 10 | 11 | 12 | 13 | $$\lim_{x \to \infty} \exp(-x) = 0$$ 14 | 15 | ${asciimath} 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 1 24 | t 25 | 26 | 27 | 28 | 29 | x 30 | 31 | x 32 | 33 | 34 | 35 | 36 | 37 | x 38 | 1 39 | t 40 | 41 | 42 | 1 43 | x 44 | 45 | 46 | 47 | 48 | 49 | ` 50 | 51 | const App = () => { 52 | const [math, setMath] = useState(someMath) 53 | 54 | return ( 55 |
56 |

react-mathjax-preview

57 |

58 | Enter some TeX, asciimath or MathML in the box below, or mix them all. 59 |

60 |