fix: dont parse tags in the middle of a post

This commit is contained in:
Xylight committed 2024-10-19 18:35:35 -07:00
1 parent 8c6887b576
commit 8958321031
2 files changed
+31 -17

No files matched your search

+22 -14
View File
@@ -18,22 +18,27 @@
let extracted: Tag[] = []
title = title.replace(/\[(.*?)\]/g, (match, content) => {
const contents = content.split(',').map((part: string) => part.trim())
const newTitle = title.replace(
/^(\[.[^\]]+\])|(\[.[^\]]+\])$/g,
(match, content) => {
const contents = match.split(',').map((part: string) => part.trim())
contents.forEach((content: string) => {
extracted.push(
textToTag.get(content) ?? {
content: content,
}
)
})
return ''
})
contents
.map((i) => i.replaceAll(/(\[|\])/g, ''))
.forEach((content: string) => {
extracted.push(
textToTag.get(content) ?? {
content: content,
}
)
})
return ''
}
)
return {
tags: extracted,
title: title,
title: newTitle,
}
}
</script>
@@ -93,11 +98,14 @@
export let tags: Tag[] = []
let displayTitle = title
$: {
if (title && tags.length == 0) {
const result = parseTags(title)
tags = result.tags
title = result.title
console.log('changed display title')
displayTitle = result.title
}
}
@@ -293,7 +301,7 @@
data-sveltekit-preload-data="tap"
>
<Markdown
source={title}
source={displayTitle}
inline
noStyle
class={view == 'compact' ? '' : 'leading-[1.3]'}
@@ -21,7 +21,9 @@
ArrowUp,
ArrowDown,
} from 'svelte-hero-icons'
import PostMeta from '$lib/components/lemmy/post/PostMeta.svelte'
import PostMeta, {
parseTags,
} from '$lib/components/lemmy/post/PostMeta.svelte'
import { Select, removeToast, toast } from 'mono-svelte'
import type { CommentSortType } from 'lemmy-js-client'
import { profile } from '$lib/auth.js'
@@ -261,7 +263,7 @@
}}
published={publishedToDate(data.post.post_view.post.published)}
edited={data.post.post_view.post.updated}
bind:title={data.post.post_view.post.name}
title={data.post.post_view.post.name}
style="width: max-content;"
/>
<Button on:click={() => history.back()} size="square-md">
@@ -269,7 +271,11 @@
</Button>
</div>
<h1 class="font-bold text-xl font-display leading-5">
<Markdown source={data.post.post_view.post.name} inline />
<Markdown
source={parseTags(data.post.post_view.post.name).title ??
data.post.post_view.post.name}
inline
/>
</h1>
</header>
<PostMedia