diff --git a/web/package.json b/web/package.json index 69e9992b..49806761 100644 --- a/web/package.json +++ b/web/package.json @@ -8,11 +8,13 @@ "lint": "eslint --ext .js,.ts,.tsx, src" }, "dependencies": { + "lodash-es": "^4.17.21", "react": "^17.0.2", "react-dom": "^17.0.2", "tiny-undo": "^0.0.8" }, "devDependencies": { + "@types/lodash-es": "^4.17.5", "@types/react": "^17.0.2", "@types/react-dom": "^17.0.2", "@typescript-eslint/eslint-plugin": "^5.6.0", diff --git a/web/src/components/Editor/Editor.tsx b/web/src/components/Editor/Editor.tsx index 3e1165e3..fd084b7a 100644 --- a/web/src/components/Editor/Editor.tsx +++ b/web/src/components/Editor/Editor.tsx @@ -180,7 +180,7 @@ const Editor = forwardRef((props: EditorProps, ref: React.ForwardedRef - diff --git a/web/src/components/Memo.tsx b/web/src/components/Memo.tsx index 5067e03b..e980a387 100644 --- a/web/src/components/Memo.tsx +++ b/web/src/components/Memo.tsx @@ -1,6 +1,7 @@ import { memo } from "react"; +import { escape } from "lodash-es"; import { IMAGE_URL_REG, LINK_REG, MEMO_LINK_REG, TAG_REG } from "../helpers/consts"; -import { encodeHtml, parseMarkedToHtml, parseRawTextToHtml } from "../helpers/marked"; +import { parseMarkedToHtml, parseRawTextToHtml } from "../helpers/marked"; import utils from "../helpers/utils"; import useToggle from "../hooks/useToggle"; import { globalStateService, memoService } from "../services"; @@ -128,7 +129,7 @@ const Memo: React.FC = (props: Props) => { }; export function formatMemoContent(content: string) { - content = encodeHtml(content); + content = escape(content); content = parseRawTextToHtml(content) .split("
") .map((t) => { diff --git a/web/src/components/MemoEditor.tsx b/web/src/components/MemoEditor.tsx index 3c1d23a8..3f576f67 100644 --- a/web/src/components/MemoEditor.tsx +++ b/web/src/components/MemoEditor.tsx @@ -175,11 +175,6 @@ const MemoEditor: React.FC = () => { }, []); const handleContentChange = useCallback((content: string) => { - const tempDiv = document.createElement("div"); - tempDiv.innerHTML = content; - if (tempDiv.innerText.trim() === "") { - content = ""; - } setEditorContentCache(content); if (editorRef.current) { diff --git a/web/src/helpers/marked.ts b/web/src/helpers/marked.ts index ec8a2ed5..aef09e6f 100644 --- a/web/src/helpers/marked.ts +++ b/web/src/helpers/marked.ts @@ -39,10 +39,4 @@ const parseRawTextToHtml = (rawTextStr: string): string => { return htmlText; }; -const encodeHtml = (htmlStr: string): string => { - const t = document.createElement("div"); - t.textContent = htmlStr; - return t.innerHTML; -}; - -export { encodeHtml, parseMarkedToHtml, parseHtmlToRawText, parseRawTextToHtml }; +export { parseMarkedToHtml, parseHtmlToRawText, parseRawTextToHtml }; diff --git a/web/src/pages/Signin.tsx b/web/src/pages/Signin.tsx index d14e372c..47ccf198 100644 --- a/web/src/pages/Signin.tsx +++ b/web/src/pages/Signin.tsx @@ -121,7 +121,7 @@ const Signin: React.FC = () => {

- Login to Memos ✍️ + ✍️ Memos

{showAutoSigninAsGuest ? ( diff --git a/web/vite.config.ts b/web/vite.config.ts index cdd88af4..c46bf54c 100644 --- a/web/vite.config.ts +++ b/web/vite.config.ts @@ -13,7 +13,8 @@ export default defineConfig({ changeOrigin: true, }, "/h/": { - target: "https://memos.justsven.top/", + target: "http://localhost:8080/", + // target: "https://memos.justsven.top/", changeOrigin: true, }, }, diff --git a/web/yarn.lock b/web/yarn.lock index ac98984e..e3247e4e 100644 --- a/web/yarn.lock +++ b/web/yarn.lock @@ -336,6 +336,18 @@ resolved "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.9.tgz" integrity sha512-qcUXuemtEu+E5wZSJHNxUXeCZhAfXKQ41D+duX+VYPde7xyEVZci+/oXKJL13tnRs9lR2pr4fod59GT6/X1/yQ== +"@types/lodash-es@^4.17.5": + version "4.17.5" + resolved "https://registry.yarnpkg.com/@types/lodash-es/-/lodash-es-4.17.5.tgz#1c3fdd16849d84aea43890b1c60da379fb501353" + integrity sha512-SHBoI8/0aoMQWAgUHMQ599VM6ZiSKg8sh/0cFqqlQQMyY9uEplc0ULU5yQNzcvdR4ZKa0ey8+vFmahuRbOCT1A== + dependencies: + "@types/lodash" "*" + +"@types/lodash@*": + version "4.14.178" + resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.14.178.tgz#341f6d2247db528d4a13ddbb374bcdc80406f4f8" + integrity sha512-0d5Wd09ItQWH1qFbEyQ7oTQ3GZrMfth5JkbN3EvTKLXcHLRDSXeLnlvlOn0wvxVIwK5o2M8JzP/OWz7T3NRsbw== + "@types/parse-json@^4.0.0": version "4.0.0" resolved "https://registry.yarnpkg.com/@types/parse-json/-/parse-json-4.0.0.tgz#2f8bb441434d163b35fb8ffdccd7138927ffb8c0" @@ -1645,6 +1657,11 @@ lines-and-columns@^1.1.6: resolved "https://registry.yarnpkg.com/lines-and-columns/-/lines-and-columns-1.2.4.tgz#eca284f75d2965079309dc0ad9255abb2ebc1632" integrity sha512-7ylylesZQ/PV29jhEDl3Ufjo6ZX7gCqJr5F7PKrqc93v7fzSymt1BpwEU8nAUXs8qzzvqhbjhK5QZg6Mt/HkBg== +lodash-es@^4.17.21: + version "4.17.21" + resolved "https://registry.yarnpkg.com/lodash-es/-/lodash-es-4.17.21.tgz#43e626c46e6591b7750beb2b50117390c609e3ee" + integrity sha512-mKnC+QJ9pWVzv+C4/U3rRsHapFfHvQFoFB92e52xeyGMcX6/OlIl78je1u8vePzYZSkkogMPJ2yjxxsb89cxyw== + lodash.merge@^4.6.2: version "4.6.2" resolved "https://registry.npm.taobao.org/lodash.merge/download/lodash.merge-4.6.2.tgz"