webui: custom image tag

ludovicm67 created

Change summary

webui/src/Content.js      |  7 ++++++-
webui/src/tag/ImageTag.js | 15 +++++++++++++++
2 files changed, 21 insertions(+), 1 deletion(-)

Detailed changes

webui/src/Content.js 🔗

@@ -2,12 +2,17 @@ import unified from 'unified';
 import parse from 'remark-parse';
 import html from 'remark-html';
 import remark2react from 'remark-react';
+import ImageTag from './tag/ImageTag';
 
 const Content = ({ markdown }) => {
   const processor = unified()
     .use(parse)
     .use(html)
-    .use(remark2react);
+    .use(remark2react, {
+      remarkReactComponents: {
+        img: ImageTag,
+      },
+    });
 
   return processor.processSync(markdown).contents;
 };

webui/src/tag/ImageTag.js 🔗

@@ -0,0 +1,15 @@
+import React from 'react';
+import { makeStyles } from '@material-ui/styles';
+
+const useStyles = makeStyles({
+  tag: {
+    maxWidth: '100%',
+  },
+});
+
+const ImageTag = (props) => {
+  const classes = useStyles();
+  return <img className={classes.tag} {...props} />
+};
+
+export default ImageTag;