fix: memo formater

This commit is contained in:
boojack 2022-01-27 12:12:43 +08:00
parent 076c42d9c4
commit 374721fa48
2 changed files with 7 additions and 5 deletions

View File

@ -146,6 +146,11 @@ export function formatMemoContent(content: string) {
content = content.replace(IMAGE_URL_REG, ""); content = content.replace(IMAGE_URL_REG, "");
} }
content = content
.replace(TAG_REG, "<span class='tag-span'>#$1</span>")
.replace(LINK_REG, "<a class='link' target='_blank' rel='noreferrer' href='$1'>$1</a>")
.replace(MEMO_LINK_REG, "<span class='memo-link-text' data-value='$2'>$1</span>");
// 中英文之间加空格 // 中英文之间加空格
if (shouldSplitMemoWord) { if (shouldSplitMemoWord) {
content = content content = content
@ -153,11 +158,6 @@ export function formatMemoContent(content: string) {
.replace(/([A-Za-z0-9?.,;[\]]+)([\u4e00-\u9fa5])/g, "$1 $2"); .replace(/([A-Za-z0-9?.,;[\]]+)([\u4e00-\u9fa5])/g, "$1 $2");
} }
content = content
.replace(TAG_REG, "<span class='tag-span'>#$1</span>")
.replace(LINK_REG, "<a class='link' target='_blank' rel='noreferrer' href='$1'>$1</a>")
.replace(MEMO_LINK_REG, "<span class='memo-link-text' data-value='$2'>$1</span>");
const tempDivContainer = document.createElement("div"); const tempDivContainer = document.createElement("div");
tempDivContainer.innerHTML = content; tempDivContainer.innerHTML = content;
for (let i = 0; i < tempDivContainer.children.length; i++) { for (let i = 0; i < tempDivContainer.children.length; i++) {

View File

@ -116,6 +116,8 @@ const MemoEditor: React.FC<Props> = () => {
return () => { return () => {
editorRef.current?.element.removeEventListener("paste", handlePasteEvent); editorRef.current?.element.removeEventListener("paste", handlePasteEvent);
editorRef.current?.element.removeEventListener("drop", handleDropEvent); editorRef.current?.element.removeEventListener("drop", handleDropEvent);
editorRef.current?.element.removeEventListener("click", handleClickEvent);
editorRef.current?.element.removeEventListener("keydown", handleKeyDownEvent);
}; };
}, []); }, []);