Skip to content

Commit

Permalink
! Fix original space padding logic
Browse files Browse the repository at this point in the history
  • Loading branch information
PikachuEXE committed Mar 31, 2023
1 parent a879b08 commit 14dd653
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/renderer/helpers/api/local.js
Original file line number Diff line number Diff line change
Expand Up @@ -511,8 +511,10 @@ export function parseLocalTextRuns(runs, emojiSize = 16, options = { looseChanne
const trimmedText = text.trim()
// In comments, mention can be `@Channel Name` (not handle, but name)
if (CHANNEL_HANDLE_REGEX.test(trimmedText) || (options.looseChannelNameDetection && /^@/.test(trimmedText))) {
// Extra space at the end due to YT tend to include one space afterward into "channel run" `text` for "mentions"
parsedRuns.push(`<a href="https://www.youtube.com/channel/${endpoint.payload.browseId}">${trimmedText}</a> `)
// Note that in regex `\s` must be used since the text contain non-default space (the half-width space char when we press spacebar)
const spacesBefore = (/^\s+/.exec(text) || [''])[0]
const spacesAfter = (/\s+$/.exec(text) || [''])[0]
parsedRuns.push(`${spacesBefore}<a href="https://www.youtube.com/channel/${endpoint.payload.browseId}">${trimmedText}</a>${spacesAfter}`)
} else {
parsedRuns.push(`https://www.youtube.com${endpoint.metadata.url}`)
}
Expand Down

0 comments on commit 14dd653

Please sign in to comment.