Only render mxc images in markdown
authorAjay Bura <32841439+ajbura@users.noreply.github.com>
Thu, 11 Aug 2022 11:50:55 +0000 (17:20 +0530)
committerAjay Bura <32841439+ajbura@users.noreply.github.com>
Thu, 11 Aug 2022 11:50:55 +0000 (17:20 +0530)
src/util/sanitize.js

index ade47ffcbc114f7b016f4649413f684ae5c04ffb..0f88c62b3e46746da1180413391ad9f101a25822 100644 (file)
@@ -76,11 +76,22 @@ function transformATag(tagName, attribs) {
 
 function transformImgTag(tagName, attribs) {
   const { src } = attribs;
+  if (src.startsWith('mxc://') === false) {
+    return {
+      tagName: 'a',
+      attribs: {
+        href: src,
+        rel: 'noopener',
+        target: '_blank',
+      },
+      text: attribs.alt || src,
+    };
+  }
   return {
     tagName,
     attribs: {
       ...attribs,
-      src: src.startsWith('mxc://') ? mx?.mxcUrlToHttp(src) : src,
+      src: mx?.mxcUrlToHttp(src),
     },
   };
 }