bsky-app/src/lib/strings/rich-text-helpers.ts
Samuel Newman 125ef1c756 Revert "run linter"
This reverts commit 1512b5cf68.
2024-03-13 01:55:14 +00:00

29 lines
690 B
TypeScript

import {AppBskyRichtextFacet, RichText} from '@atproto/api'
import {linkRequiresWarning} from './url-helpers'
export function richTextToString(rt: RichText, loose: boolean): string {
const {text, facets} = rt
if (!facets?.length) {
return text
}
let result = ''
for (const segment of rt.segments()) {
const link = segment.link
if (link && AppBskyRichtextFacet.validateLink(link).success) {
const href = link.uri
const text = segment.text
const requiresWarning = linkRequiresWarning(href, text)
result += !requiresWarning ? href : loose ? `[${text}](${href})` : text
} else {
result += segment.text
}
}
return result
}