[WIKI-343] [WIKI-312] Fix: html characters (#7049)

* fix: handle symbols and space

* chore: refactor
This commit is contained in:
Vipin Chaudhary 2025-05-30 18:17:03 +05:30 committed by GitHub
parent 4a97d7c28c
commit b16a585102
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 6 additions and 4 deletions

View file

@ -81,6 +81,7 @@ export const useEditor = (props: CustomEditorProps) => {
immediatelyRender: false, immediatelyRender: false,
shouldRerenderOnTransaction: false, shouldRerenderOnTransaction: false,
autofocus, autofocus,
parseOptions: { preserveWhitespace: true },
editorProps: { editorProps: {
...CoreEditorProps({ ...CoreEditorProps({
editorClassName, editorClassName,
@ -119,7 +120,7 @@ export const useEditor = (props: CustomEditorProps) => {
const isUploadInProgress = getExtensionStorage(editor, CORE_EXTENSIONS.UTILITY)?.uploadInProgress; const isUploadInProgress = getExtensionStorage(editor, CORE_EXTENSIONS.UTILITY)?.uploadInProgress;
if (!editor.isDestroyed && !isUploadInProgress) { if (!editor.isDestroyed && !isUploadInProgress) {
try { try {
editor.commands.setContent(value, false, { preserveWhitespace: "full" }); editor.commands.setContent(value, false, { preserveWhitespace: true });
if (editor.state.selection) { if (editor.state.selection) {
const docLength = editor.state.doc.content.size; const docLength = editor.state.doc.content.size;
const relativePosition = Math.min(editor.state.selection.from, docLength - 1); const relativePosition = Math.min(editor.state.selection.from, docLength - 1);
@ -153,7 +154,7 @@ export const useEditor = (props: CustomEditorProps) => {
editor?.chain().setMeta(CORE_EDITOR_META.SKIP_FILE_DELETION, true).clearContent(emitUpdate).run(); editor?.chain().setMeta(CORE_EDITOR_META.SKIP_FILE_DELETION, true).clearContent(emitUpdate).run();
}, },
setEditorValue: (content: string, emitUpdate = false) => { setEditorValue: (content: string, emitUpdate = false) => {
editor?.commands.setContent(content, emitUpdate, { preserveWhitespace: "full" }); editor?.commands.setContent(content, emitUpdate, { preserveWhitespace: true });
}, },
setEditorValueAtCursorPosition: (content: string) => { setEditorValueAtCursorPosition: (content: string) => {
if (editor?.state.selection) { if (editor?.state.selection) {

View file

@ -46,6 +46,7 @@ export const useReadOnlyEditor = (props: CustomReadOnlyEditorProps) => {
immediatelyRender: true, immediatelyRender: true,
shouldRerenderOnTransaction: false, shouldRerenderOnTransaction: false,
content: typeof initialValue === "string" && initialValue.trim() !== "" ? initialValue : "<p></p>", content: typeof initialValue === "string" && initialValue.trim() !== "" ? initialValue : "<p></p>",
parseOptions: { preserveWhitespace: true },
editorProps: { editorProps: {
...CoreReadOnlyEditorProps({ ...CoreReadOnlyEditorProps({
editorClassName, editorClassName,
@ -71,7 +72,7 @@ export const useReadOnlyEditor = (props: CustomReadOnlyEditorProps) => {
// for syncing swr data on tab refocus etc // for syncing swr data on tab refocus etc
useEffect(() => { useEffect(() => {
if (initialValue === null || initialValue === undefined) return; if (initialValue === null || initialValue === undefined) return;
if (editor && !editor.isDestroyed) editor?.commands.setContent(initialValue, false, { preserveWhitespace: "full" }); if (editor && !editor.isDestroyed) editor?.commands.setContent(initialValue, false, { preserveWhitespace: true });
}, [editor, initialValue]); }, [editor, initialValue]);
useImperativeHandle(forwardedRef, () => ({ useImperativeHandle(forwardedRef, () => ({
@ -79,7 +80,7 @@ export const useReadOnlyEditor = (props: CustomReadOnlyEditorProps) => {
editor?.chain().setMeta(CORE_EDITOR_META.SKIP_FILE_DELETION, true).clearContent(emitUpdate).run(); editor?.chain().setMeta(CORE_EDITOR_META.SKIP_FILE_DELETION, true).clearContent(emitUpdate).run();
}, },
setEditorValue: (content: string, emitUpdate = false) => { setEditorValue: (content: string, emitUpdate = false) => {
editor?.commands.setContent(content, emitUpdate, { preserveWhitespace: "full" }); editor?.commands.setContent(content, emitUpdate, { preserveWhitespace: true });
}, },
getMarkDown: (): string => { getMarkDown: (): string => {
const markdownOutput = editor?.storage.markdown.getMarkdown(); const markdownOutput = editor?.storage.markdown.getMarkdown();