Skip to content

Commit

Permalink
Merge pull request #394 from refly-ai/hotfix/to-markdown-error
Browse files Browse the repository at this point in the history
fix(editor): image src empty issues
  • Loading branch information
mrcfps authored Jan 21, 2025
2 parents 7e0119e + 5776fcc commit 80884b0
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@ import {
AIHighlight,
CharacterCount,
CodeBlockLowlight,
GlobalDragHandle,
HorizontalRule,
StarterKit,
TaskItem,
TaskList,
TiptapImage,
TiptapLink,
UpdatedImage,
Youtube,
Expand All @@ -31,7 +29,7 @@ const tiptapLink = TiptapLink.configure({
},
});

const tiptapImage = TiptapImage.extend({
const tiptapImage = UpdatedImage.extend({
addProseMirrorPlugins() {
return [
UploadImagesPlugin({
Expand Down Expand Up @@ -130,17 +128,14 @@ export const defaultExtensions = [
starterKit,
tiptapLink,
tiptapImage,
// updatedImage,
taskList,
taskItem,
horizontalRule,
aiHighlight,
// codeBlockLowlight,
youtube,
characterCount,
SpaceAICommand,
DoublePlusAICommand,
// GlobalDragHandle,
];

export { Placeholder };
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
import Image from "@tiptap/extension-image";
import Image from '@tiptap/extension-image';

const UpdatedImage = Image.extend({
name: "image",
name: 'image',
addAttributes() {
return {
...this.parent?.(),
src: {
default: '',
parseHTML: (element) => element.getAttribute('src') || '',
renderHTML: (attributes) => ({
src: attributes.src || '',
}),
},
width: {
default: null,
},
Expand Down
7 changes: 4 additions & 3 deletions packages/utils/src/editor/to_markdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,13 @@ export const defaultMarkdownSerializer = new MarkdownSerializer(
},

image(state, node) {
const src = typeof node.attrs?.src === 'string' ? node.attrs.src : String(node.attrs?.src ?? '');
state.write(
'![' +
state.esc(node.attrs.alt || '') +
state.esc(node.attrs?.alt ?? '') +
'](' +
node.attrs.src.replace(/[\(\)]/g, '\\$&') +
(node.attrs.title ? ' "' + node.attrs.title.replace(/"/g, '\\"') + '"' : '') +
src.replace(/[\(\)]/g, '\\$&') +
(node.attrs?.title ? ' "' + node.attrs.title.replace(/"/g, '\\"') + '"' : '') +
')',
);
},
Expand Down

0 comments on commit 80884b0

Please sign in to comment.