Add LaTeX / math input and rendering support (#345)

* Initial display support

* Use better colors for error in math parsing

* Parse math markdown

* Use proper jsx

* Better copy support

* use css var directly

* Remove console.debug call

* Lazy load math module

* Show fallback while katex is loading
This commit is contained in:
ginnyTheCat 2022-04-24 17:48:35 +02:00 committed by GitHub
parent 9a22b25564
commit b7c5902f67
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 230 additions and 18 deletions

View file

@ -2,8 +2,9 @@ import EventEmitter from 'events';
import { micromark } from 'micromark';
import { gfm, gfmHtml } from 'micromark-extension-gfm';
import encrypt from 'browser-encrypt-attachment';
import { math } from 'micromark-extension-math';
import { getShortcodeToEmoji } from '../../app/organisms/emoji-board/custom-emoji';
import { spoilerExtension, spoilerExtensionHtml } from '../../util/markdown';
import { mathExtensionHtml, spoilerExtension, spoilerExtensionHtml } from '../../util/markdown';
import cons from './cons';
import settings from './settings';
@ -85,8 +86,8 @@ function getVideoThumbnail(video, width, height, mimeType) {
function getFormattedBody(markdown) {
const result = micromark(markdown, {
extensions: [gfm(), spoilerExtension()],
htmlExtensions: [gfmHtml(), spoilerExtensionHtml],
extensions: [gfm(), spoilerExtension(), math()],
htmlExtensions: [gfmHtml(), spoilerExtensionHtml, mathExtensionHtml],
});
const bodyParts = result.match(/^(<p>)(.*)(<\/p>)$/);
if (bodyParts === null) return result;