Replace MathJax with KaTeX (#497)

Signed-off-by: Tilman Vatteroth <tilman.vatteroth@tu-dortmund.de>
This commit is contained in:
mrdrogdrog 2020-08-27 15:13:35 +02:00 committed by GitHub
parent 7adb86846b
commit ef36123377
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
36 changed files with 85 additions and 109 deletions

View file

@ -48,6 +48,7 @@
- The `[name=...]`, `[time=...]` and `[color=...]` tags may now be used anywhere in the document and not just inside of blockquotes and lists. - The `[name=...]`, `[time=...]` and `[color=...]` tags may now be used anywhere in the document and not just inside of blockquotes and lists.
- The <i class="fa fa-picture-o"/> (add image) and <i class="fa fa-link"/> (add link) toolbar buttons, put selected links directly in the `()` instead of the `[]` part of the generated markdown - The <i class="fa fa-picture-o"/> (add image) and <i class="fa fa-link"/> (add link) toolbar buttons, put selected links directly in the `()` instead of the `[]` part of the generated markdown
- The help dialog has multiple tabs, and is a bit more organized. - The help dialog has multiple tabs, and is a bit more organized.
- Use KaTeX instead of MathJax. ([Why?](https://community.codimd.org/t/frequently-asked-questions/190))
--- ---

View file

@ -92,7 +92,7 @@ describe('Links Intro', () => {
.should('include', '/features#Share-Notes') .should('include', '/features#Share-Notes')
}) })
it('MathJax', () => { it('KaTeX', () => {
cy.get('i.fa-bar-chart.fa-3x') cy.get('i.fa-bar-chart.fa-3x')
.click() .click()
cy.url() cy.url()

View file

@ -3,6 +3,7 @@
"license": "AGPL-3.0", "license": "AGPL-3.0",
"version": "0.1.0", "version": "0.1.0",
"dependencies": { "dependencies": {
"@matejmazur/react-katex": "^3.1.3",
"@testing-library/jest-dom": "5.11.4", "@testing-library/jest-dom": "5.11.4",
"@testing-library/react": "10.4.9", "@testing-library/react": "10.4.9",
"@testing-library/user-event": "12.1.2", "@testing-library/user-event": "12.1.2",
@ -22,7 +23,6 @@
"@types/react-bootstrap-typeahead": "3.4.6", "@types/react-bootstrap-typeahead": "3.4.6",
"@types/react-dom": "16.9.8", "@types/react-dom": "16.9.8",
"@types/react-html-parser": "2.0.1", "@types/react-html-parser": "2.0.1",
"@types/react-mathjax": "1.0.0",
"@types/react-redux": "7.1.9", "@types/react-redux": "7.1.9",
"@types/react-router": "5.1.8", "@types/react-router": "5.1.8",
"@types/react-router-bootstrap": "0.24.5", "@types/react-router-bootstrap": "0.24.5",
@ -48,6 +48,7 @@
"i18next-browser-languagedetector": "6.0.1", "i18next-browser-languagedetector": "6.0.1",
"i18next-http-backend": "1.0.18", "i18next-http-backend": "1.0.18",
"js-yaml": "3.14.0", "js-yaml": "3.14.0",
"katex": "^0.12.0",
"markdown-it": "11.0.0", "markdown-it": "11.0.0",
"markdown-it-abbr": "1.0.4", "markdown-it-abbr": "1.0.4",
"markdown-it-anchor": "5.3.0", "markdown-it-anchor": "5.3.0",
@ -66,7 +67,6 @@
"markdown-it-sup": "1.0.0", "markdown-it-sup": "1.0.0",
"markdown-it-task-lists": "2.1.1", "markdown-it-task-lists": "2.1.1",
"markdown-it-toc-done-right": "4.1.0", "markdown-it-toc-done-right": "4.1.0",
"mathjax": "3.0.5",
"moment": "2.27.0", "moment": "2.27.0",
"node-sass": "4.14.1", "node-sass": "4.14.1",
"react": "16.13.1", "react": "16.13.1",
@ -76,7 +76,6 @@
"react-dom": "16.13.1", "react-dom": "16.13.1",
"react-html-parser": "2.0.2", "react-html-parser": "2.0.2",
"react-i18next": "11.7.1", "react-i18next": "11.7.1",
"react-mathjax": "1.0.1",
"react-redux": "7.2.1", "react-redux": "7.2.1",
"react-router": "5.2.0", "react-router": "5.2.0",
"react-router-bootstrap": "0.25.0", "react-router-bootstrap": "0.25.0",
@ -142,10 +141,10 @@
"cypress": "5.0.0", "cypress": "5.0.0",
"eslint-plugin-chai-friendly": "0.6.0", "eslint-plugin-chai-friendly": "0.6.0",
"eslint-plugin-cypress": "2.11.1", "eslint-plugin-cypress": "2.11.1",
"http-server": "0.12.3",
"redux-devtools": "3.6.1", "redux-devtools": "3.6.1",
"redux-devtools-extension": "2.13.8", "redux-devtools-extension": "2.13.8",
"ts-loader": "8.0.2", "ts-loader": "8.0.2"
"http-server": "0.12.3"
}, },
"resolutions": { "resolutions": {
"cypress": "5.0.0" "cypress": "5.0.0"

View file

@ -8,7 +8,7 @@
"exploreFeatures": "استكشف جميع الميزات", "exploreFeatures": "استكشف جميع الميزات",
"features": { "features": {
"collaboration": "تعاون آني", "collaboration": "تعاون آني",
"mathJax": "دعم المنحنيات البيانية و MathJax", "katex": "دعم المنحنيات البيانية و KaTeX",
"slides": "دعم الشرائح التقديمية" "slides": "دعم الشرائح التقديمية"
} }
}, },

View file

@ -8,7 +8,7 @@
"exploreFeatures": "Explorar totes les funcions", "exploreFeatures": "Explorar totes les funcions",
"features": { "features": {
"collaboration": "Col·laborar a través de URL", "collaboration": "Col·laborar a través de URL",
"mathJax": "Soport per a gràfics i MathJax", "katex": "Soport per a gràfics i KaTeX",
"slides": "Soport per a diapositives" "slides": "Soport per a diapositives"
} }
}, },

View file

@ -8,7 +8,7 @@
"exploreFeatures": "Prozkoumat všechny funkce", "exploreFeatures": "Prozkoumat všechny funkce",
"features": { "features": {
"collaboration": "Spolupráce v reálném čase", "collaboration": "Spolupráce v reálném čase",
"mathJax": "Funguje s grafy a MathJax", "katex": "Funguje s grafy a KaTeX",
"slides": "Podporuje režim prezentace" "slides": "Podporuje režim prezentace"
} }
}, },

View file

@ -8,7 +8,7 @@
"exploreFeatures": "Udforsk alle features", "exploreFeatures": "Udforsk alle features",
"features": { "features": {
"collaboration": "Samarbejd via URL", "collaboration": "Samarbejd via URL",
"mathJax": "Mulighed for diagrammer og MathJax", "katex": "Mulighed for diagrammer og KaTeX",
"slides": "Mulighed for præsentationer" "slides": "Mulighed for præsentationer"
} }
}, },

View file

@ -8,7 +8,7 @@
"exploreFeatures": "Alle Funktionen", "exploreFeatures": "Alle Funktionen",
"features": { "features": {
"collaboration": "Zusammenarbeiten mit URL", "collaboration": "Zusammenarbeiten mit URL",
"mathJax": "Unterstützt Charts und MathJax", "katex": "Unterstützt Charts und KaTeX",
"slides": "Unterstützt Präsentationsmodus" "slides": "Unterstützt Präsentationsmodus"
} }
}, },

View file

@ -8,7 +8,7 @@
"exploreFeatures": "Ανακαλύψτε όλες τις λειτουργίες", "exploreFeatures": "Ανακαλύψτε όλες τις λειτουργίες",
"features": { "features": {
"collaboration": "Συνεργαστείτε με URL", "collaboration": "Συνεργαστείτε με URL",
"mathJax": "Υποστηρίζει διαγράμματα και MathJax", "katex": "Υποστηρίζει διαγράμματα και KaTeX",
"slides": "Υποστηρίζει λειτουργία συρσίματος" "slides": "Υποστηρίζει λειτουργία συρσίματος"
} }
}, },

View file

@ -8,7 +8,7 @@
"exploreFeatures": "Explore all features", "exploreFeatures": "Explore all features",
"features": { "features": {
"collaboration": "Real time collaboration", "collaboration": "Real time collaboration",
"mathJax": "Works with charts and MathJax", "katex": "Works with charts and KaTeX",
"slides": "Supports slide mode" "slides": "Supports slide mode"
}, },
"screenShotAltText": "CodiMD Screenshot" "screenShotAltText": "CodiMD Screenshot"

View file

@ -8,7 +8,7 @@
"exploreFeatures": "Esploru ĉiujn eblecojn", "exploreFeatures": "Esploru ĉiujn eblecojn",
"features": { "features": {
"collaboration": "Kunlaboru per URL", "collaboration": "Kunlaboru per URL",
"mathJax": "Ebleco por skemoj kaj MathJax", "katex": "Ebleco por skemoj kaj KaTeX",
"slides": "Ebleco por bildvica modo" "slides": "Ebleco por bildvica modo"
} }
}, },

View file

@ -8,7 +8,7 @@
"exploreFeatures": "Explorar todas las funciones", "exploreFeatures": "Explorar todas las funciones",
"features": { "features": {
"collaboration": "Colaborar via URL", "collaboration": "Colaborar via URL",
"mathJax": "Soporte para gráficos y MathJax", "katex": "Soporte para gráficos y KaTeX",
"slides": "Soporte para diapositivas" "slides": "Soporte para diapositivas"
} }
}, },

View file

@ -8,7 +8,7 @@
"exploreFeatures": "Explorer toutes les fonctionnalités", "exploreFeatures": "Explorer toutes les fonctionnalités",
"features": { "features": {
"collaboration": "Collaborez avec l'URL", "collaboration": "Collaborez avec l'URL",
"mathJax": "Gère les graphiques et MathJax", "katex": "Gère les graphiques et KaTeX",
"slides": "Gère le mode présentation" "slides": "Gère le mode présentation"
} }
}, },

View file

@ -8,7 +8,7 @@
"exploreFeatures": "सभी सुविधाओं का अन्वेषण करें", "exploreFeatures": "सभी सुविधाओं का अन्वेषण करें",
"features": { "features": {
"collaboration": "यूआरएल के साथ सहयोग करें", "collaboration": "यूआरएल के साथ सहयोग करें",
"mathJax": "चार्ट और MathJax का समर्थन", "katex": "चार्ट और KaTeX का समर्थन",
"slides": "स्लाइड मोड का समर्थन" "slides": "स्लाइड मोड का समर्थन"
} }
}, },

View file

@ -8,7 +8,7 @@
"exploreFeatures": "Istraži sve značajke", "exploreFeatures": "Istraži sve značajke",
"features": { "features": {
"collaboration": "Kolaboracija sa URL-om", "collaboration": "Kolaboracija sa URL-om",
"mathJax": "Support charts and MathJax", "katex": "Support charts and KaTeX",
"slides": "Način podrške slajda" "slides": "Način podrške slajda"
} }
}, },

View file

@ -8,7 +8,7 @@
"exploreFeatures": "Jelajahi semua fitur", "exploreFeatures": "Jelajahi semua fitur",
"features": { "features": {
"collaboration": "Kolaborasi real-time", "collaboration": "Kolaborasi real-time",
"mathJax": "Mendukung charts dan MathJax", "katex": "Mendukung charts dan KaTeX",
"slides": "Mendukung mode slide" "slides": "Mendukung mode slide"
} }
}, },

View file

@ -8,7 +8,7 @@
"exploreFeatures": "Esplora tutte le funzioni", "exploreFeatures": "Esplora tutte le funzioni",
"features": { "features": {
"collaboration": "Collabora tramite URL", "collaboration": "Collabora tramite URL",
"mathJax": "Supporta grafici e MathJax", "katex": "Supporta grafici e KaTeX",
"slides": "Supporta modalità slide" "slides": "Supporta modalità slide"
} }
}, },

View file

@ -8,7 +8,7 @@
"exploreFeatures": "すべての機能をチェック", "exploreFeatures": "すべての機能をチェック",
"features": { "features": {
"collaboration": "URLで共同編集", "collaboration": "URLで共同編集",
"mathJax": "グラフとMathJaxのサポート", "katex": "グラフとKaTeXのサポート",
"slides": "スライドモードのサポート" "slides": "スライドモードのサポート"
} }
}, },

View file

@ -8,7 +8,7 @@
"exploreFeatures": "모든 기능 둘러보기", "exploreFeatures": "모든 기능 둘러보기",
"features": { "features": {
"collaboration": "URL을 통한 실시간 협업", "collaboration": "URL을 통한 실시간 협업",
"mathJax": "차트와 MathJax 지원", "katex": "차트와 KaTeX 지원",
"slides": "슬라이드 모드 지원" "slides": "슬라이드 모드 지원"
} }
}, },

View file

@ -8,7 +8,7 @@
"exploreFeatures": "Ontdek alle features", "exploreFeatures": "Ontdek alle features",
"features": { "features": {
"collaboration": "Samenwerken met URL", "collaboration": "Samenwerken met URL",
"mathJax": "Ondersteunt grafieken en MathJax", "katex": "Ondersteunt grafieken en KaTeX",
"slides": "Ondersteunt presentatiemodus" "slides": "Ondersteunt presentatiemodus"
} }
}, },

View file

@ -8,7 +8,7 @@
"exploreFeatures": "Przeglądaj wszystkie funkcje", "exploreFeatures": "Przeglądaj wszystkie funkcje",
"features": { "features": {
"collaboration": "Kolaboracja w czasie rzeczywistym", "collaboration": "Kolaboracja w czasie rzeczywistym",
"mathJax": "Kompatybilne z wykresami oraz MathJax", "katex": "Kompatybilne z wykresami oraz KaTeX",
"slides": "Obsługuje tryb slajdów" "slides": "Obsługuje tryb slajdów"
} }
}, },

View file

@ -8,7 +8,7 @@
"exploreFeatures": "Explore todas as funções", "exploreFeatures": "Explore todas as funções",
"features": { "features": {
"collaboration": "Colaborar via URL", "collaboration": "Colaborar via URL",
"mathJax": "Suporte para gráficos e MathJax", "katex": "Suporte para gráficos e KaTeX",
"slides": "Suporte para modo apresentação" "slides": "Suporte para modo apresentação"
} }
}, },

View file

@ -8,7 +8,7 @@
"exploreFeatures": "Изучите все возможности", "exploreFeatures": "Изучите все возможности",
"features": { "features": {
"collaboration": "Сотрудничество по ссылке", "collaboration": "Сотрудничество по ссылке",
"mathJax": "Поддержка графиков и MathJax", "katex": "Поддержка графиков и KaTeX",
"slides": "Поддержка режима слайдера" "slides": "Поддержка режима слайдера"
} }
}, },

View file

@ -8,7 +8,7 @@
"exploreFeatures": "Preskúmať všetky funkcie", "exploreFeatures": "Preskúmať všetky funkcie",
"features": { "features": {
"collaboration": "Spolupráca v reálnom čase", "collaboration": "Spolupráca v reálnom čase",
"mathJax": "Funguje s grafmi a MathJax", "katex": "Funguje s grafmi a KaTeX",
"slides": "Podporuje prezentačný režim" "slides": "Podporuje prezentačný režim"
} }
}, },

View file

@ -8,7 +8,7 @@
"exploreFeatures": "Истражи све могућности", "exploreFeatures": "Истражи све могућности",
"features": { "features": {
"collaboration": "Сарадња уз помоћ URL-а", "collaboration": "Сарадња уз помоћ URL-а",
"mathJax": "Подршка за графиконе и MathJax", "katex": "Подршка за графиконе и KaTeX",
"slides": "Подршка за слајдове и презентације" "slides": "Подршка за слајдове и презентације"
} }
}, },

View file

@ -8,7 +8,7 @@
"exploreFeatures": "Upptäck alla funktioner", "exploreFeatures": "Upptäck alla funktioner",
"features": { "features": {
"collaboration": "Samarbeta med URL", "collaboration": "Samarbeta med URL",
"mathJax": "Stöd för diagram och MathJax", "katex": "Stöd för diagram och KaTeX",
"slides": "Stöd för slide mode" "slides": "Stöd för slide mode"
} }
}, },

View file

@ -8,7 +8,7 @@
"exploreFeatures": "Özellikleri keşfet", "exploreFeatures": "Özellikleri keşfet",
"features": { "features": {
"collaboration": "URL ile katkıda bulun", "collaboration": "URL ile katkıda bulun",
"mathJax": "Grafikler ve MathJax'ı destekle", "katex": "Grafikler ve KaTeX'ı destekle",
"slides": "Sunum modunu destekle" "slides": "Sunum modunu destekle"
} }
}, },

View file

@ -8,7 +8,7 @@
"exploreFeatures": "Дослідити всі можливості", "exploreFeatures": "Дослідити всі можливості",
"features": { "features": {
"collaboration": "Спільна робота по URL", "collaboration": "Спільна робота по URL",
"mathJax": "Підтримка графіків і MathJax", "katex": "Підтримка графіків і KaTeX",
"slides": "Підтримка режиму слайдера" "slides": "Підтримка режиму слайдера"
} }
}, },

View file

@ -8,7 +8,7 @@
"exploreFeatures": "Khám phá tất cả tính năng", "exploreFeatures": "Khám phá tất cả tính năng",
"features": { "features": {
"collaboration": "Cộng tác thời gian thực", "collaboration": "Cộng tác thời gian thực",
"mathJax": "Làm việc với biểu đồ và MathJax", "katex": "Làm việc với biểu đồ và KaTeX",
"slides": "Hỗ trợ chế độ slide" "slides": "Hỗ trợ chế độ slide"
} }
}, },

View file

@ -8,7 +8,7 @@
"exploreFeatures": "探索所有功能", "exploreFeatures": "探索所有功能",
"features": { "features": {
"collaboration": "实时协作", "collaboration": "实时协作",
"mathJax": "支持图表与 MathJax", "katex": "支持图表与 KaTeX",
"slides": "支持幻灯模式" "slides": "支持幻灯模式"
} }
}, },

View file

@ -8,7 +8,7 @@
"exploreFeatures": "探索所有功能", "exploreFeatures": "探索所有功能",
"features": { "features": {
"collaboration": "使用網址協作", "collaboration": "使用網址協作",
"mathJax": "支援圖表與 MathJax", "katex": "支援圖表與 KaTeX",
"slides": "支援簡報模式" "slides": "支援簡報模式"
} }
}, },

View file

@ -20,7 +20,7 @@ export const FeatureLinks: React.FC = () => {
<Link to={'/n/features#MathJax'} className="text-light"> <Link to={'/n/features#MathJax'} className="text-light">
<ForkAwesomeIcon icon="bar-chart" size="3x"/> <ForkAwesomeIcon icon="bar-chart" size="3x"/>
<h5> <h5>
<Trans i18nKey="landing.intro.features.mathJax"/> <Trans i18nKey="landing.intro.features.katex"/>
</h5> </h5>
</Link> </Link>
</Col> </Col>

View file

@ -25,7 +25,6 @@ import React, { ReactElement, useCallback, useEffect, useMemo, useRef, useState
import { Alert } from 'react-bootstrap' import { Alert } from 'react-bootstrap'
import ReactHtmlParser, { convertNodeToElement, Transform } from 'react-html-parser' import ReactHtmlParser, { convertNodeToElement, Transform } from 'react-html-parser'
import { Trans } from 'react-i18next' import { Trans } from 'react-i18next'
import MathJaxReact from 'react-mathjax'
import { useSelector } from 'react-redux' import { useSelector } from 'react-redux'
import useResizeObserver from 'use-resize-observer' import useResizeObserver from 'use-resize-observer'
import { TocAst } from '../../external-types/markdown-it-toc-done-right/interface' import { TocAst } from '../../external-types/markdown-it-toc-done-right/interface'
@ -60,7 +59,7 @@ import { ComponentReplacer, SubNodeConverter } from './replace-components/Compon
import { GistReplacer } from './replace-components/gist/gist-replacer' import { GistReplacer } from './replace-components/gist/gist-replacer'
import { HighlightedCodeReplacer } from './replace-components/highlighted-fence/highlighted-fence-replacer' import { HighlightedCodeReplacer } from './replace-components/highlighted-fence/highlighted-fence-replacer'
import { ImageReplacer } from './replace-components/image/image-replacer' import { ImageReplacer } from './replace-components/image/image-replacer'
import { MathjaxReplacer } from './replace-components/mathjax/mathjax-replacer' import { KatexReplacer } from './replace-components/katex/katex-replacer'
import { PdfReplacer } from './replace-components/pdf/pdf-replacer' import { PdfReplacer } from './replace-components/pdf/pdf-replacer'
import { PossibleWiderReplacer } from './replace-components/possible-wider/possible-wider-replacer' import { PossibleWiderReplacer } from './replace-components/possible-wider/possible-wider-replacer'
import { QuoteOptionsReplacer } from './replace-components/quote-options/quote-options-replacer' import { QuoteOptionsReplacer } from './replace-components/quote-options/quote-options-replacer'
@ -244,12 +243,12 @@ export const MarkdownRenderer: React.FC<MarkdownRendererProps> = ({ content, onM
permalinkSymbol: '<i class="fa fa-link"></i>' permalinkSymbol: '<i class="fa fa-link"></i>'
}) })
md.use(mathJax({ md.use(mathJax({
beforeMath: '<codimd-mathjax>', beforeMath: '<codimd-katex>',
afterMath: '</codimd-mathjax>', afterMath: '</codimd-katex>',
beforeInlineMath: '<codimd-mathjax inline>', beforeInlineMath: '<codimd-katex inline>',
afterInlineMath: '</codimd-mathjax>', afterInlineMath: '</codimd-katex>',
beforeDisplayMath: '<codimd-mathjax>', beforeDisplayMath: '<codimd-katex>',
afterDisplayMath: '</codimd-mathjax>' afterDisplayMath: '</codimd-katex>'
})) }))
md.use(markdownItRegex, replaceLegacyYoutubeShortCode) md.use(markdownItRegex, replaceLegacyYoutubeShortCode)
md.use(markdownItRegex, replaceLegacyVimeoShortCode) md.use(markdownItRegex, replaceLegacyVimeoShortCode)
@ -312,7 +311,7 @@ export const MarkdownRenderer: React.FC<MarkdownRendererProps> = ({ content, onM
new TocReplacer(), new TocReplacer(),
new HighlightedCodeReplacer(), new HighlightedCodeReplacer(),
new QuoteOptionsReplacer(), new QuoteOptionsReplacer(),
new MathjaxReplacer() new KatexReplacer()
] ]
if (onMetaDataChange) { if (onMetaDataChange) {
// This is used if the front-matter callback is never called, because the user deleted everything regarding metadata from the document // This is used if the front-matter callback is never called, because the user deleted everything regarding metadata from the document
@ -337,9 +336,7 @@ export const MarkdownRenderer: React.FC<MarkdownRendererProps> = ({ content, onM
</Trans> </Trans>
</Alert> </Alert>
</ShowIf> </ShowIf>
<MathJaxReact.Provider> {result}
{result}
</MathJaxReact.Provider>
</div> </div>
</div> </div>
) )

View file

@ -0,0 +1,28 @@
import { DomElement } from 'domhandler'
import React from 'react'
import 'katex/dist/katex.min.css'
import TeX from '@matejmazur/react-katex'
import { ComponentReplacer } from '../ComponentReplacer'
const getNodeIfKatexBlock = (node: DomElement): (DomElement|undefined) => {
if (node.name !== 'p' || !node.children || node.children.length !== 1) {
return
}
const katexNode = node.children[0]
return (katexNode.name === 'codimd-katex' && katexNode.attribs?.inline === undefined) ? katexNode : undefined
}
const getNodeIfInlineKatex = (node: DomElement): (DomElement|undefined) => {
return (node.name === 'codimd-katex' && node.attribs?.inline !== undefined) ? node : undefined
}
export class KatexReplacer implements ComponentReplacer {
getReplacement (node: DomElement, index: number): React.ReactElement | undefined {
const katex = getNodeIfKatexBlock(node) || getNodeIfInlineKatex(node)
if (katex?.children && katex.children[0]) {
const mathJaxContent = katex.children[0]?.data as string
const isInline = (katex.attribs?.inline) !== undefined
return <TeX key={index} block={!isInline} math={mathJaxContent} errorColor={'#cc0000'}/>
}
}
}

View file

@ -1,27 +0,0 @@
import { DomElement } from 'domhandler'
import React from 'react'
import MathJax from 'react-mathjax'
import { ComponentReplacer, SubNodeConverter } from '../ComponentReplacer'
const getNodeIfMathJaxBlock = (node: DomElement): (DomElement|undefined) => {
if (node.name !== 'p' || !node.children || node.children.length !== 1) {
return
}
const mathJaxNode = node.children[0]
return (mathJaxNode.name === 'codimd-mathjax' && mathJaxNode.attribs?.inline === undefined) ? mathJaxNode : undefined
}
const getNodeIfInlineMathJax = (node: DomElement): (DomElement|undefined) => {
return (node.name === 'codimd-mathjax' && node.attribs?.inline !== undefined) ? node : undefined
}
export class MathjaxReplacer implements ComponentReplacer {
getReplacement (node: DomElement, index: number, subNodeConverter: SubNodeConverter): React.ReactElement | undefined {
const mathJax = getNodeIfMathJaxBlock(node) || getNodeIfInlineMathJax(node)
if (mathJax?.children && mathJax.children[0]) {
const mathJaxContent = mathJax.children[0]?.data as string
const isInline = (mathJax.attribs?.inline) !== undefined
return <MathJax.Node key={index} inline={isInline} formula={mathJaxContent}/>
}
}
}

View file

@ -1420,6 +1420,11 @@
"@types/yargs" "^15.0.0" "@types/yargs" "^15.0.0"
chalk "^4.0.0" chalk "^4.0.0"
"@matejmazur/react-katex@^3.1.3":
version "3.1.3"
resolved "https://registry.yarnpkg.com/@matejmazur/react-katex/-/react-katex-3.1.3.tgz#f07404c848b93bfef9ed9653a4bb080dc8bf2bf0"
integrity sha512-rBp7mJ9An7ktNoU653BWOYdO4FoR4YNwofHZi+vaytX/nWbIlmHVIF+X8VFOn6c3WYmrLT5FFBjKqCZ1sjR5uQ==
"@mrmlnc/readdir-enhanced@^2.2.1": "@mrmlnc/readdir-enhanced@^2.2.1":
version "2.2.1" version "2.2.1"
resolved "https://registry.yarnpkg.com/@mrmlnc/readdir-enhanced/-/readdir-enhanced-2.2.1.tgz#524af240d1a360527b730475ecfa1344aa540dde" resolved "https://registry.yarnpkg.com/@mrmlnc/readdir-enhanced/-/readdir-enhanced-2.2.1.tgz#524af240d1a360527b730475ecfa1344aa540dde"
@ -1901,13 +1906,6 @@
"@types/htmlparser2" "*" "@types/htmlparser2" "*"
"@types/react" "*" "@types/react" "*"
"@types/react-mathjax@1.0.0":
version "1.0.0"
resolved "https://registry.yarnpkg.com/@types/react-mathjax/-/react-mathjax-1.0.0.tgz#5e337ddc0fbee4d01513d960f81f85963a9ee482"
integrity sha512-c3beW/LhRx/7LkwYGj7mIDphatRdih80Cpe4l2u3LFdyOgBloPaXq3H9QROC6GnhbGxVql7ByHLA70s+Q6ol1Q==
dependencies:
"@types/react" "*"
"@types/react-redux@7.1.9": "@types/react-redux@7.1.9":
version "7.1.9" version "7.1.9"
resolved "https://registry.yarnpkg.com/@types/react-redux/-/react-redux-7.1.9.tgz#280c13565c9f13ceb727ec21e767abe0e9b4aec3" resolved "https://registry.yarnpkg.com/@types/react-redux/-/react-redux-7.1.9.tgz#280c13565c9f13ceb727ec21e767abe0e9b4aec3"
@ -3681,7 +3679,7 @@ combined-stream@^1.0.6, combined-stream@~1.0.6:
dependencies: dependencies:
delayed-stream "~1.0.0" delayed-stream "~1.0.0"
commander@^2.11.0, commander@^2.20.0: commander@^2.11.0, commander@^2.19.0, commander@^2.20.0:
version "2.20.3" version "2.20.3"
resolved "https://registry.yarnpkg.com/commander/-/commander-2.20.3.tgz#fd485e84c03eb4881c20722ba48035e8531aeb33" resolved "https://registry.yarnpkg.com/commander/-/commander-2.20.3.tgz#fd485e84c03eb4881c20722ba48035e8531aeb33"
integrity sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ== integrity sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==
@ -4564,16 +4562,6 @@ dom-accessibility-api@^0.5.1:
resolved "https://registry.yarnpkg.com/dom-accessibility-api/-/dom-accessibility-api-0.5.1.tgz#152f5e88583d900977119223e3e76c2d93d23830" resolved "https://registry.yarnpkg.com/dom-accessibility-api/-/dom-accessibility-api-0.5.1.tgz#152f5e88583d900977119223e3e76c2d93d23830"
integrity sha512-8DhtmKTYWXNpPiL/QOszbnkAbCGuPz9ieVwDrmWM1rNx4KRI3zqmvKANAD1PJdvvov3+eq1BPLXQkYTpqTrWng== integrity sha512-8DhtmKTYWXNpPiL/QOszbnkAbCGuPz9ieVwDrmWM1rNx4KRI3zqmvKANAD1PJdvvov3+eq1BPLXQkYTpqTrWng==
dom-accessibility-api@^0.5.1:
version "0.5.1"
resolved "https://registry.yarnpkg.com/dom-accessibility-api/-/dom-accessibility-api-0.5.1.tgz#152f5e88583d900977119223e3e76c2d93d23830"
integrity sha512-8DhtmKTYWXNpPiL/QOszbnkAbCGuPz9ieVwDrmWM1rNx4KRI3zqmvKANAD1PJdvvov3+eq1BPLXQkYTpqTrWng==
dom-accessibility-api@^0.5.1:
version "0.5.1"
resolved "https://registry.yarnpkg.com/dom-accessibility-api/-/dom-accessibility-api-0.5.1.tgz#152f5e88583d900977119223e3e76c2d93d23830"
integrity sha512-8DhtmKTYWXNpPiL/QOszbnkAbCGuPz9ieVwDrmWM1rNx4KRI3zqmvKANAD1PJdvvov3+eq1BPLXQkYTpqTrWng==
dom-converter@^0.2: dom-converter@^0.2:
version "0.2.0" version "0.2.0"
resolved "https://registry.yarnpkg.com/dom-converter/-/dom-converter-0.2.0.tgz#6721a9daee2e293682955b6afe416771627bb768" resolved "https://registry.yarnpkg.com/dom-converter/-/dom-converter-0.2.0.tgz#6721a9daee2e293682955b6afe416771627bb768"
@ -7747,6 +7735,13 @@ jsx-ast-utils@^2.2.1, jsx-ast-utils@^2.2.3, jsx-ast-utils@^2.4.1:
array-includes "^3.1.1" array-includes "^3.1.1"
object.assign "^4.1.0" object.assign "^4.1.0"
katex@^0.12.0:
version "0.12.0"
resolved "https://registry.yarnpkg.com/katex/-/katex-0.12.0.tgz#2fb1c665dbd2b043edcf8a1f5c555f46beaa0cb9"
integrity sha512-y+8btoc/CK70XqcHqjxiGWBOeIL8upbS0peTPXTvgrh21n1RiWWcIpSWM+4uXq+IAgNh9YYQWdc7LVDPDAEEAg==
dependencies:
commander "^2.19.0"
killable@^1.0.1: killable@^1.0.1:
version "1.0.1" version "1.0.1"
resolved "https://registry.yarnpkg.com/killable/-/killable-1.0.1.tgz#4c8ce441187a061c7474fb87ca08e2a638194892" resolved "https://registry.yarnpkg.com/killable/-/killable-1.0.1.tgz#4c8ce441187a061c7474fb87ca08e2a638194892"
@ -7935,11 +7930,6 @@ load-json-file@^4.0.0:
pify "^3.0.0" pify "^3.0.0"
strip-bom "^3.0.0" strip-bom "^3.0.0"
load-script@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/load-script/-/load-script-1.0.0.tgz#0491939e0bee5643ee494a7e3da3d2bac70c6ca4"
integrity sha1-BJGTngvuVkPuSUp+PaPSuscMbKQ=
loader-fs-cache@^1.0.2: loader-fs-cache@^1.0.2:
version "1.0.3" version "1.0.3"
resolved "https://registry.yarnpkg.com/loader-fs-cache/-/loader-fs-cache-1.0.3.tgz#f08657646d607078be2f0a032f8bd69dd6f277d9" resolved "https://registry.yarnpkg.com/loader-fs-cache/-/loader-fs-cache-1.0.3.tgz#f08657646d607078be2f0a032f8bd69dd6f277d9"
@ -8259,11 +8249,6 @@ markdown-it@11.0.0:
mdurl "^1.0.1" mdurl "^1.0.1"
uc.micro "^1.0.5" uc.micro "^1.0.5"
mathjax@3.0.5:
version "3.0.5"
resolved "https://registry.yarnpkg.com/mathjax/-/mathjax-3.0.5.tgz#707e703a9c1d95f0790bbd404b895566f459d514"
integrity sha512-9M7VulhltkD8sIebWutK/VfAD+m+6BIFqfpjDh9Pz/etoKUtjO6UMnOhUcDmNl6iApE8C9xrUmaMyNZkZAlrMw==
md5.js@^1.3.4: md5.js@^1.3.4:
version "1.3.5" version "1.3.5"
resolved "https://registry.yarnpkg.com/md5.js/-/md5.js-1.3.5.tgz#b5d07b8e3216e3e27cd728d72f70d1e6a342005f" resolved "https://registry.yarnpkg.com/md5.js/-/md5.js-1.3.5.tgz#b5d07b8e3216e3e27cd728d72f70d1e6a342005f"
@ -10530,13 +10515,6 @@ react-lifecycles-compat@^3.0.4:
resolved "https://registry.yarnpkg.com/react-lifecycles-compat/-/react-lifecycles-compat-3.0.4.tgz#4f1a273afdfc8f3488a8c516bfda78f872352362" resolved "https://registry.yarnpkg.com/react-lifecycles-compat/-/react-lifecycles-compat-3.0.4.tgz#4f1a273afdfc8f3488a8c516bfda78f872352362"
integrity sha512-fBASbA6LnOU9dOU2eW7aQ8xmYBSXUIWr+UmF9b1efZBazGNO+rcXT/icdKnYm2pTwcRylVUYwW7H1PHfLekVzA== integrity sha512-fBASbA6LnOU9dOU2eW7aQ8xmYBSXUIWr+UmF9b1efZBazGNO+rcXT/icdKnYm2pTwcRylVUYwW7H1PHfLekVzA==
react-mathjax@1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/react-mathjax/-/react-mathjax-1.0.1.tgz#a8c282e75d277a201632dfd07edf41edda372b4b"
integrity sha512-+mjFcciZY3GQoqiQm3aRTyDjgBKuoaXpY+SCONX00jScuPpTKwnASeFMS5+pbTIzDf5zPT2Y9ZZfQ9U/d4CKtQ==
dependencies:
load-script "^1.0.0"
react-overlays@^2.0.0: react-overlays@^2.0.0:
version "2.1.1" version "2.1.1"
resolved "https://registry.yarnpkg.com/react-overlays/-/react-overlays-2.1.1.tgz#ffe2090c4a10da6b8947a1c7b1a67d0457648a0d" resolved "https://registry.yarnpkg.com/react-overlays/-/react-overlays-2.1.1.tgz#ffe2090c4a10da6b8947a1c7b1a67d0457648a0d"