Skip to content

Commit 42e3d97

Browse files
committed
Fix wikipedia images and equations in markdown
1 parent e5c1409 commit 42e3d97

File tree

1 file changed

+13
-8
lines changed
  • src/frontend/core/renderers/MarkdownRenderer

1 file changed

+13
-8
lines changed

src/frontend/core/renderers/MarkdownRenderer/index.jsx

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,20 @@ class MarkdownRenderer extends Renderer {
4545
};
4646

4747
const image = ({ src, ...rest }) => {
48-
let newSrc;
49-
const codecogs = 'https://latex.codecogs.com/svg.latex?';
50-
if (src.startsWith(codecogs)) {
51-
const latex = src.substring(codecogs.length);
52-
newSrc = `${codecogs}\\color{White}${latex}`;
53-
} else {
54-
newSrc = src;
48+
let newSrc = src;
49+
let style = { maxWidth: '100%' };
50+
const CODECOGS = 'https://latex.codecogs.com/svg.latex?';
51+
const WIKIMEDIA_IMAGE = 'https://upload.wikimedia.org/wikipedia/';
52+
const WIKIMEDIA_MATH = 'https://wikimedia.org/api/rest_v1/media/math/render/svg/';
53+
if (src.startsWith(CODECOGS)) {
54+
const latex = src.substring(CODECOGS.length);
55+
newSrc = `${CODECOGS}\\color{White}${latex}`;
56+
} else if (src.startsWith(WIKIMEDIA_IMAGE)) {
57+
style.backgroundColor = 'white';
58+
} else if (src.startsWith(WIKIMEDIA_MATH)) {
59+
style.filter = 'invert(100%)';
5560
}
56-
return <img src={newSrc} style={{ maxWidth: '100%' }} {...rest} />;
61+
return <img src={newSrc} style={style} {...rest} />;
5762
};
5863

5964
return (

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy