bigbuffet-rw/app/soapbox/utils/greentext.ts

23 lines
750 B
TypeScript
Raw Normal View History

2022-11-15 12:46:23 -08:00
import { processHtml } from './tiny-post-html-processor';
2021-07-01 18:41:03 -07:00
2022-04-24 12:28:07 -07:00
export const addGreentext = (html: string): string => {
2021-07-01 18:41:03 -07:00
// Copied from Pleroma FE
// https://git.pleroma.social/pleroma/pleroma-fe/-/blob/19475ba356c3fd6c54ca0306d3ae392358c212d1/src/components/status_content/status_content.js#L132
return processHtml(html, (string) => {
try {
if (string.includes('>') &&
string
.replace(/<[^>]+?>/gi, '') // remove all tags
.replace(/@\w+/gi, '') // remove mentions (even failed ones)
.trim()
.startsWith('&gt;')) {
return `<span class='text-greentext'>${string}</span>`;
2021-07-01 18:41:03 -07:00
} else {
return string;
}
} catch (e) {
2021-07-01 18:41:03 -07:00
return string;
}
});
};