Skip to content

A Q&A platform software for teams at any scales. Whether it's a community forum, help center, or knowledge management platform, you can always count on Apache Answer.

fix: editor fixes the issue where some line breaks are missing when the pasted content contains images

shuaibe1d5fb44566
diff --git a/ui/src/components/Editor/ToolBars/image.tsx b/ui/src/components/Editor/ToolBars/image.tsx
index 95737db6..1bc429a0 100644
--- a/ui/src/components/Editor/ToolBars/image.tsx
+++ b/ui/src/components/Editor/ToolBars/image.tsx
@@ -167,17 +167,29 @@ const Image = ({ editorInstance }) => {
}
event.preventDefault();
- const newHtml = new DOMParser()
+ let innerText = '';
+ const allPTag = new DOMParser()
.parseFromString(
htmlStr.replace(
/<img([\s\S]*?) src\s*=\s*(['"])([\s\S]*?)\2([^>]*)>/gi,
- `<p>\n![${t('image.text')}]($3)\n</p>`,
+ `<p>![${t('image.text')}]($3)\n\n</p>`,
),
'text/html',
)
- .querySelector('body')?.innerText as string;
+ .querySelectorAll('body p');
+
+ allPTag.forEach((p, index) => {
+ const text = p.textContent || '';
+ if (text !== '') {
+ if (index === allPTag.length - 1) {
+ innerText += `${p.textContent}`;
+ } else {
+ innerText += `${p.textContent}${text.endsWith('\n') ? '' : '\n\n'}`;
+ }
+ }
+ });
- editor.replaceSelection(newHtml);
+ editor.replaceSelection(innerText);
};
const handleClick = () => {
if (!link.value) {
diff --git a/ui/src/i18n/init.ts b/ui/src/i18n/init.ts
index 66d9576e..03f775cb 100644
--- a/ui/src/i18n/init.ts
+++ b/ui/src/i18n/init.ts
@@ -21,7 +21,7 @@ import { initReactI18next } from 'react-i18next';
import i18next from 'i18next';
import en_US from '@i18n/en_US.yaml';
-// import zh_CN from '@i18n/zh_CN.yaml';
+import zh_CN from '@i18n/zh_CN.yaml';
import { DEFAULT_LANG, LANG_RESOURCE_STORAGE_KEY } from '@/common/constants';
import Storage from '@/utils/storage';
@@ -34,9 +34,9 @@ const initResources = {
en_US: {
translation: en_US.ui,
},
- // zh_CN: {
- // translation: zh_CN.ui,
- // },
+ zh_CN: {
+ translation: zh_CN.ui,
+ },
};
const storageLang = Storage.get(LANG_RESOURCE_STORAGE_KEY);
diff --git a/ui/src/pages/Review/components/EditPostModal/index.tsx b/ui/src/pages/Review/components/EditPostModal/index.tsx
index e35a82ca..4190240c 100644
--- a/ui/src/pages/Review/components/EditPostModal/index.tsx
+++ b/ui/src/pages/Review/components/EditPostModal/index.tsx
@@ -76,6 +76,7 @@ const Index: FC<Props> = ({
if (bol) {
callback?.();
}
+ setFormData(initFormData);
handleClose();
setLoaded(false);
};