bigbuffet-rw/app/soapbox/utils/greentext.ts
2022-11-16 08:34:55 -05:00

22 lines
750 B
TypeScript

import { processHtml } from './tiny-post-html-processor';
export const addGreentext = (html: string): string => {
// 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>`;
} else {
return string;
}
} catch (e) {
return string;
}
});
};