fix: image url host missing (#623)

This commit is contained in:
boojack
2022-11-28 19:52:03 +08:00
committed by GitHub
parent fbe7b604ef
commit b04e001db1
2 changed files with 9 additions and 1 deletions

View File

@ -134,3 +134,9 @@ export const parseHTMLToRawText = (htmlStr: string): string => {
const text = tempEl.innerText; const text = tempEl.innerText;
return text; return text;
}; };
export function absolutifyLink(rel: string): string {
const anchor = document.createElement("a");
anchor.setAttribute("href", rel);
return anchor.href;
}

View File

@ -1,4 +1,5 @@
import { escape } from "lodash-es"; import { escape } from "lodash-es";
import { absolutifyLink } from "../../../helpers/utils";
export const IMAGE_REG = /!\[.*?\]\((.+?)\)/; export const IMAGE_REG = /!\[.*?\]\((.+?)\)/;
@ -8,8 +9,9 @@ const renderer = (rawStr: string): string => {
return rawStr; return rawStr;
} }
const imageUrl = absolutifyLink(escape(matchResult[1]));
// NOTE: Get image blob from backend to avoid CORS. // NOTE: Get image blob from backend to avoid CORS.
return `<img class='img' src='/o/get/image?url=${escape(matchResult[1])}' />`; return `<img class='img' src='/o/get/image?url=${imageUrl}' />`;
}; };
export default { export default {