@@ -3,6 +3,7 @@ import { computed } from 'vue'
33import { ListKeymap , TaskItem , TaskList } from ' @tiptap/extension-list'
44import type { DirectoryTreeNode , EditorSuggestionItems , EditorToolbarItems , EditorViewMode , TreeNode , TreeNodeType } from ' ~/types/editoro'
55import { useEditoroMainContentMedia } from ' ~/composables/editor/useEditoroMainContentMedia'
6+ import { transformMarkdownLinks } from ' ~/utils/editoro-vault-links'
67
78const { t } = useI18n ()
89
@@ -52,10 +53,29 @@ const {
5253 onFileInputChange
5354} = useEditoroMainContentMedia ({
5455 canUploadImage : () => props .canUploadImage ,
56+ getCurrentFilePath : () => props .selectedPath ,
5557 uploadImage: props .uploadImage ,
56- uploadFile: props .uploadFile
58+ uploadFile: props .uploadFile ,
59+ openMarkdownPath : (path : string ) => emit (' selectPath' , path )
5760})
5861
62+ const richEditorContent = computed (() => {
63+ if (! props .selectedPath ) {
64+ return props .editorContent
65+ }
66+
67+ return transformMarkdownLinks (props .editorContent , props .selectedPath , ' to-rich' )
68+ })
69+
70+ function onRichEditorContentChange(value : string ) {
71+ if (! props .selectedPath ) {
72+ emit (' updateEditorContent' , value )
73+ return
74+ }
75+
76+ emit (' updateEditorContent' , transformMarkdownLinks (value , props .selectedPath , ' to-raw' ))
77+ }
78+
5979const richEditorHandlers = computed (() => ({
6080 ... editorHandlers ,
6181 // Disable prompt-based link handler; link editing is handled by custom popover UI.
@@ -192,13 +212,13 @@ const editorExtensions = [TaskList, TaskItem, ListKeymap]
192212
193213 <UEditor
194214 v-else
195- :model-value =" props.editorContent "
215+ :model-value =" richEditorContent "
196216 class =" editoro-editor"
197217 content-type =" markdown"
198218 :extensions =" editorExtensions"
199219 :handlers =" richEditorHandlers"
200220 :placeholder =" t('main.editorPlaceholder')"
201- @update:model-value =" emit('updateEditorContent', String($event || ''))"
221+ @update:model-value =" onRichEditorContentChange( String($event || ''))"
202222 >
203223 <template #default =" { editor } " >
204224 <span
@@ -368,12 +388,16 @@ const editorExtensions = [TaskList, TaskItem, ListKeymap]
368388 line-height : 1.5 ;
369389}
370390
371- .editoro-editor :deep(.tiptap a [href *= ' /api/files/file?path=' ]) {
391+ .editoro-editor :deep(.tiptap a [href ^= ' /' ]:not ([href ^= ' //' ])),
392+ .editoro-editor :deep(.tiptap a [href ^= ' ./' ]),
393+ .editoro-editor :deep(.tiptap a [href ^= ' ../' ]) {
372394 position : relative ;
373395 padding-left : 1.1rem ;
374396}
375397
376- .editoro-editor :deep(.tiptap a [href *= ' /api/files/file?path=' ]::before ) {
398+ .editoro-editor :deep(.tiptap a [href ^= ' /' ]:not ([href ^= ' //' ])::before ),
399+ .editoro-editor :deep(.tiptap a [href ^= ' ./' ]::before ),
400+ .editoro-editor :deep(.tiptap a [href ^= ' ../' ]::before ) {
377401 content : ' ' ;
378402 position : absolute ;
379403 left : 0 ;
@@ -388,6 +412,32 @@ const editorExtensions = [TaskList, TaskItem, ListKeymap]
388412 pointer-events : none ;
389413}
390414
415+ .editoro-editor :deep(.tiptap a [href ^= ' http://' ]),
416+ .editoro-editor :deep(.tiptap a [href ^= ' https://' ]),
417+ .editoro-editor :deep(.tiptap a [href ^= ' mailto:' ]),
418+ .editoro-editor :deep(.tiptap a [href ^= ' tel:' ]) {
419+ position : relative ;
420+ padding-left : 1.1rem ;
421+ }
422+
423+ .editoro-editor :deep(.tiptap a [href ^= ' http://' ]::before ),
424+ .editoro-editor :deep(.tiptap a [href ^= ' https://' ]::before ),
425+ .editoro-editor :deep(.tiptap a [href ^= ' mailto:' ]::before ),
426+ .editoro-editor :deep(.tiptap a [href ^= ' tel:' ]::before ) {
427+ content : ' ' ;
428+ position : absolute ;
429+ left : 0 ;
430+ top : 50% ;
431+ width : 14px ;
432+ height : 14px ;
433+ transform : translateY (-50% );
434+ background-image : url (" data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M15 3h6v6'/%3E%3Cpath d='M10 14 21 3'/%3E%3Cpath d='M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6'/%3E%3C/svg%3E" );
435+ background-repeat : no-repeat ;
436+ background-position : center ;
437+ background-size : 14px 14px ;
438+ pointer-events : none ;
439+ }
440+
391441.editoro-editor :deep(.editoro-link-modifier a [href ]) {
392442 cursor : pointer ;
393443}
0 commit comments