pl-fe: don't strip quote-inline when quote is not included

Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
This commit is contained in:
marcin mikołajczak 2024-08-31 19:43:15 +02:00
parent 48f54cfc9d
commit 380de23122
2 changed files with 7 additions and 6 deletions

View file

@ -62,7 +62,7 @@ const buildSearchContent = (status: Pick<BaseStatus, 'poll' | 'mentions' | 'spoi
return unescapeHTML(fields.join('\n\n')) || '';
};
const calculateContent = (text: string, emojiMap: any) => DOMPurify.sanitize(stripCompatibilityFeatures(emojify(text, emojiMap)), { USE_PROFILES: { html: true } });
const calculateContent = (text: string, emojiMap: any, hasQuote?: boolean) => DOMPurify.sanitize(stripCompatibilityFeatures(emojify(text, emojiMap), hasQuote), { USE_PROFILES: { html: true } });
const calculateSpoiler = (text: string, emojiMap: any) => DOMPurify.sanitize(emojify(escapeTextContentForBrowser(text), emojiMap), { USE_PROFILES: { html: true } });
const calculateStatus = (status: BaseStatus, oldStatus?: OldStatus): CalculatedValues => {
@ -80,10 +80,10 @@ const calculateStatus = (status: BaseStatus, oldStatus?: OldStatus): CalculatedV
return {
search_index: domParser.parseFromString(searchContent, 'text/html').documentElement.textContent || '',
contentHtml: calculateContent(status.content, emojiMap),
contentHtml: calculateContent(status.content, emojiMap, !!status.quote),
spoilerHtml: calculateSpoiler(status.spoiler_text, emojiMap),
contentMapHtml: status.content_map
? Object.fromEntries(Object.entries(status.content_map)?.map(([key, value]) => [key, calculateContent(value, emojiMap)]))
? Object.fromEntries(Object.entries(status.content_map)?.map(([key, value]) => [key, calculateContent(value, emojiMap, !!status.quote)]))
: undefined,
spoilerMapHtml: status.spoiler_text_map
? Object.fromEntries(Object.entries(status.spoiler_text_map).map(([key, value]) => [key, calculateSpoiler(value, emojiMap)]))

View file

@ -7,17 +7,18 @@ const unescapeHTML = (html: string = ''): string => {
};
/** Remove compatibility markup for features pl-fe supports. */
const stripCompatibilityFeatures = (html: string): string => {
const stripCompatibilityFeatures = (html: string, hasQuote = true): string => {
const node = document.createElement('div');
node.innerHTML = html;
const selectors = [
// Quote posting
'.quote-inline',
// Explicit mentions
'.recipients-inline',
];
// Quote posting
if (hasQuote) selectors.push('.quote-inline');
// Remove all instances of all selectors
selectors.forEach(selector => {
node.querySelectorAll(selector).forEach(elem => {