fix: use preprocessMarkdown for parsing hashtags and item mentions

The @tiptap/markdown extension doesn't automatically parse custom
markdown syntax like [@Label](/item/id). We need to preprocess the
markdown before loading it into the editor to convert these patterns
to HTML spans that the extensions' parseHTML handlers can recognize.

- RichTextEditor: preprocess defaultValue before loading
- TextView: preprocess innerText before loading

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Anton Tranelis 2026-01-14 17:34:11 +01:00
parent 90eb66bc80
commit 3a8477f863

View File

@ -10,6 +10,7 @@ import { useItems } from '#components/Map/hooks/useItems'
import { useTags } from '#components/Map/hooks/useTags'
import { Hashtag, ItemMention, VideoEmbed } from '#components/TipTap/extensions'
import {
preprocessMarkdown,
removeMarkdownSyntax,
truncateMarkdown,
} from '#components/TipTap/utils/preprocessMarkdown'
@ -79,8 +80,8 @@ export const TextView = ({
}),
VideoEmbed,
],
content: innerText,
contentType: 'markdown',
// Preprocess markdown to convert hashtags and item mentions to HTML
content: preprocessMarkdown(innerText),
editable: false,
editorProps: {
attributes: {
@ -93,7 +94,7 @@ export const TextView = ({
// Update content when text changes
useEffect(() => {
editor.commands.setContent(innerText, { contentType: 'markdown' })
editor.commands.setContent(preprocessMarkdown(innerText))
}, [editor, innerText])
// Handle link clicks for internal navigation