fix: dont parse tags in the middle of a post
This commit is contained in:
1 parent
8c6887b576
commit
8958321031
2 files changed
+31
-17
No files matched your search
@@ -18,22 +18,27 @@
|
|||||||
|
|
||||||
let extracted: Tag[] = []
|
let extracted: Tag[] = []
|
||||||
|
|
||||||
title = title.replace(/\[(.*?)\]/g, (match, content) => {
|
const newTitle = title.replace(
|
||||||
const contents = content.split(',').map((part: string) => part.trim())
|
/^(\[.[^\]]+\])|(\[.[^\]]+\])$/g,
|
||||||
|
(match, content) => {
|
||||||
|
const contents = match.split(',').map((part: string) => part.trim())
|
||||||
|
|
||||||
contents.forEach((content: string) => {
|
contents
|
||||||
extracted.push(
|
.map((i) => i.replaceAll(/(\[|\])/g, ''))
|
||||||
textToTag.get(content) ?? {
|
.forEach((content: string) => {
|
||||||
content: content,
|
extracted.push(
|
||||||
}
|
textToTag.get(content) ?? {
|
||||||
)
|
content: content,
|
||||||
})
|
}
|
||||||
return ''
|
)
|
||||||
})
|
})
|
||||||
|
return ''
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
tags: extracted,
|
tags: extracted,
|
||||||
title: title,
|
title: newTitle,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
@@ -93,11 +98,14 @@
|
|||||||
|
|
||||||
export let tags: Tag[] = []
|
export let tags: Tag[] = []
|
||||||
|
|
||||||
|
let displayTitle = title
|
||||||
|
|
||||||
$: {
|
$: {
|
||||||
if (title && tags.length == 0) {
|
if (title && tags.length == 0) {
|
||||||
const result = parseTags(title)
|
const result = parseTags(title)
|
||||||
tags = result.tags
|
tags = result.tags
|
||||||
title = result.title
|
console.log('changed display title')
|
||||||
|
displayTitle = result.title
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -293,7 +301,7 @@
|
|||||||
data-sveltekit-preload-data="tap"
|
data-sveltekit-preload-data="tap"
|
||||||
>
|
>
|
||||||
<Markdown
|
<Markdown
|
||||||
source={title}
|
source={displayTitle}
|
||||||
inline
|
inline
|
||||||
noStyle
|
noStyle
|
||||||
class={view == 'compact' ? '' : 'leading-[1.3]'}
|
class={view == 'compact' ? '' : 'leading-[1.3]'}
|
||||||
|
|||||||
@@ -21,7 +21,9 @@
|
|||||||
ArrowUp,
|
ArrowUp,
|
||||||
ArrowDown,
|
ArrowDown,
|
||||||
} from 'svelte-hero-icons'
|
} 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 { Select, removeToast, toast } from 'mono-svelte'
|
||||||
import type { CommentSortType } from 'lemmy-js-client'
|
import type { CommentSortType } from 'lemmy-js-client'
|
||||||
import { profile } from '$lib/auth.js'
|
import { profile } from '$lib/auth.js'
|
||||||
@@ -261,7 +263,7 @@
|
|||||||
}}
|
}}
|
||||||
published={publishedToDate(data.post.post_view.post.published)}
|
published={publishedToDate(data.post.post_view.post.published)}
|
||||||
edited={data.post.post_view.post.updated}
|
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;"
|
style="width: max-content;"
|
||||||
/>
|
/>
|
||||||
<Button on:click={() => history.back()} size="square-md">
|
<Button on:click={() => history.back()} size="square-md">
|
||||||
@@ -269,7 +271,11 @@
|
|||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
<h1 class="font-bold text-xl font-display leading-5">
|
<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>
|
</h1>
|
||||||
</header>
|
</header>
|
||||||
<PostMedia
|
<PostMedia
|
||||||
|
|||||||
Reference in new issue
Block a user