it has come to my attention i might need to escape markdown characters whoops

This commit is contained in:
Melanie Kat 2025-12-21 17:13:31 -08:00
parent e42f3b9f85
commit 08c149e478

View file

@ -9,16 +9,22 @@ export function markdownLinkRegex(url) {
)
}
export function markdownCharEscape(text) {
return text.replaceAll('-', '\\-')
}
export async function getRSSItemTitle(feedUrl) {
const res = await fetch(feedUrl)
const data = await res.text()
const dom = new JSDOM(data)
const item = dom.window.document.querySelector('item')
const title = item.querySelector('title').textContent
return sanitizeHtml(title, {
allowedTags: [],
allowedAttributes: {},
})?.trim()
return markdownCharEscape(
sanitizeHtml(title, {
allowedTags: [],
allowedAttributes: {},
})?.trim(),
)
}
export async function getJsonFeedItemTitle(feedUrl) {
@ -26,7 +32,8 @@ export async function getJsonFeedItemTitle(feedUrl) {
const data = await res.json()
const post = data.items[0]
const { title, image } = post
return image ? `${title} ![${title}](${image})` : title
const cleanTitle = markdownCharEscape(title)
return image ? `${cleanTitle} ![${cleanTitle}](${image})` : cleanTitle
}
export async function getJsonFeedItemContent(feedUrl) {
@ -38,7 +45,8 @@ export async function getJsonFeedItemContent(feedUrl) {
allowedTags: [],
allowedAttributes: {},
})?.trim()
return image ? `${title} ![${title}](${image})` : title
const cleanTitle = markdownCharEscape(title)
return image ? `${cleanTitle} ![${cleanTitle}](${image})` : cleanTitle
}
export async function getMalojaScrobble(malojaUrl) {
@ -49,7 +57,9 @@ export async function getMalojaScrobble(malojaUrl) {
title,
album: { artists },
} = scrobble.track
return `${title}<br />by ${artists.join(', ')}`
const cleanTitle = markdownCharEscape(title)
const cleanArtists = markdownCharEscape(artists.join(', '))
return markdownCharEscape(`${cleanTitle}<br />by ${cleanArtists}`)
}
export async function getLetterboxdActivity(username) {
@ -58,8 +68,9 @@ export async function getLetterboxdActivity(username) {
const dom = new JSDOM(data)
const item = dom.window.document.querySelector('item')
const title = item.querySelector('title').textContent
const cleanTitle = markdownCharEscape(title)
const image = item.querySelector('description > img').src
return `${title} ![${title}](${image})`
return `${cleanTitle} ![${cleanTitle}](${image})`
}
export async function getTraktEpisode(username, id) {
@ -70,5 +81,6 @@ export async function getTraktEpisode(username, id) {
const dom = new JSDOM(data)
const entry = dom.window.document.querySelector('entry')
const title = entry.querySelector('title').textContent
return `${title} ![${title}](https://widgets.trakt.tv/users/${id}/watched/thumb@2x.jpg?type=episode&image_only=1)`
const cleanTitle = markdownCharEscape(title)
return `${cleanTitle} ![${cleanTitle}](https://widgets.trakt.tv/users/${id}/watched/thumb@2x.jpg?type=episode&image_only=1)`
}