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:
parent
48f54cfc9d
commit
380de23122
2 changed files with 7 additions and 6 deletions
|
@ -62,7 +62,7 @@ const buildSearchContent = (status: Pick<BaseStatus, 'poll' | 'mentions' | 'spoi
|
||||||
return unescapeHTML(fields.join('\n\n')) || '';
|
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 calculateSpoiler = (text: string, emojiMap: any) => DOMPurify.sanitize(emojify(escapeTextContentForBrowser(text), emojiMap), { USE_PROFILES: { html: true } });
|
||||||
|
|
||||||
const calculateStatus = (status: BaseStatus, oldStatus?: OldStatus): CalculatedValues => {
|
const calculateStatus = (status: BaseStatus, oldStatus?: OldStatus): CalculatedValues => {
|
||||||
|
@ -80,10 +80,10 @@ const calculateStatus = (status: BaseStatus, oldStatus?: OldStatus): CalculatedV
|
||||||
|
|
||||||
return {
|
return {
|
||||||
search_index: domParser.parseFromString(searchContent, 'text/html').documentElement.textContent || '',
|
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),
|
spoilerHtml: calculateSpoiler(status.spoiler_text, emojiMap),
|
||||||
contentMapHtml: status.content_map
|
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,
|
: undefined,
|
||||||
spoilerMapHtml: status.spoiler_text_map
|
spoilerMapHtml: status.spoiler_text_map
|
||||||
? Object.fromEntries(Object.entries(status.spoiler_text_map).map(([key, value]) => [key, calculateSpoiler(value, emojiMap)]))
|
? Object.fromEntries(Object.entries(status.spoiler_text_map).map(([key, value]) => [key, calculateSpoiler(value, emojiMap)]))
|
||||||
|
|
|
@ -7,17 +7,18 @@ const unescapeHTML = (html: string = ''): string => {
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Remove compatibility markup for features pl-fe supports. */
|
/** 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');
|
const node = document.createElement('div');
|
||||||
node.innerHTML = html;
|
node.innerHTML = html;
|
||||||
|
|
||||||
const selectors = [
|
const selectors = [
|
||||||
// Quote posting
|
|
||||||
'.quote-inline',
|
|
||||||
// Explicit mentions
|
// Explicit mentions
|
||||||
'.recipients-inline',
|
'.recipients-inline',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
// Quote posting
|
||||||
|
if (hasQuote) selectors.push('.quote-inline');
|
||||||
|
|
||||||
// Remove all instances of all selectors
|
// Remove all instances of all selectors
|
||||||
selectors.forEach(selector => {
|
selectors.forEach(selector => {
|
||||||
node.querySelectorAll(selector).forEach(elem => {
|
node.querySelectorAll(selector).forEach(elem => {
|
||||||
|
|
Loading…
Reference in a new issue