Status: strip compatibility features from markup when importing
This commit is contained in:
parent
35ab65efcf
commit
462df83989
|
@ -1,5 +1,7 @@
|
||||||
import escapeTextContentForBrowser from 'escape-html';
|
import escapeTextContentForBrowser from 'escape-html';
|
||||||
|
|
||||||
|
import { stripCompatibilityFeatures } from 'soapbox/utils/html';
|
||||||
|
|
||||||
import emojify from '../../features/emoji/emoji';
|
import emojify from '../../features/emoji/emoji';
|
||||||
import { unescapeHTML } from '../../utils/html';
|
import { unescapeHTML } from '../../utils/html';
|
||||||
|
|
||||||
|
@ -79,7 +81,7 @@ export function normalizeStatus(status, normalOldStatus, expandSpoilers) {
|
||||||
const emojiMap = makeEmojiMap(normalStatus);
|
const emojiMap = makeEmojiMap(normalStatus);
|
||||||
|
|
||||||
normalStatus.search_index = domParser.parseFromString(searchContent, 'text/html').documentElement.textContent;
|
normalStatus.search_index = domParser.parseFromString(searchContent, 'text/html').documentElement.textContent;
|
||||||
normalStatus.contentHtml = emojify(normalStatus.content, emojiMap);
|
normalStatus.contentHtml = stripCompatibilityFeatures(emojify(normalStatus.content, emojiMap));
|
||||||
normalStatus.spoilerHtml = emojify(escapeTextContentForBrowser(spoilerText), emojiMap);
|
normalStatus.spoilerHtml = emojify(escapeTextContentForBrowser(spoilerText), emojiMap);
|
||||||
normalStatus.hidden = expandSpoilers ? false : spoilerText.length > 0 || normalStatus.sensitive;
|
normalStatus.hidden = expandSpoilers ? false : spoilerText.length > 0 || normalStatus.sensitive;
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,17 +75,6 @@ class StatusContent extends React.PureComponent {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
stripCompatibilityFeatures() {
|
|
||||||
const node = this.node;
|
|
||||||
if (!node) return;
|
|
||||||
|
|
||||||
const inlineQuote = node.querySelector('.quote-inline');
|
|
||||||
const inlineRecipients = node.querySelector('.recipients-inline');
|
|
||||||
|
|
||||||
if (inlineQuote) inlineQuote.remove();
|
|
||||||
if (inlineRecipients) inlineRecipients.remove();
|
|
||||||
}
|
|
||||||
|
|
||||||
setCollapse() {
|
setCollapse() {
|
||||||
const node = this.node;
|
const node = this.node;
|
||||||
|
|
||||||
|
@ -117,7 +106,6 @@ class StatusContent extends React.PureComponent {
|
||||||
refresh = () => {
|
refresh = () => {
|
||||||
this.setCollapse();
|
this.setCollapse();
|
||||||
this._updateStatusLinks();
|
this._updateStatusLinks();
|
||||||
this.stripCompatibilityFeatures();
|
|
||||||
this.setOnlyEmoji();
|
this.setOnlyEmoji();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,3 +4,23 @@ export const unescapeHTML = (html) => {
|
||||||
wrapper.innerHTML = html.replace(/<br\s*\/?>/g, '\n').replace(/<\/p><p>/g, '\n\n').replace(/<[^>]*>/g, '');
|
wrapper.innerHTML = html.replace(/<br\s*\/?>/g, '\n').replace(/<\/p><p>/g, '\n\n').replace(/<[^>]*>/g, '');
|
||||||
return wrapper.textContent;
|
return wrapper.textContent;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const stripCompatibilityFeatures = html => {
|
||||||
|
const node = document.createElement('div');
|
||||||
|
node.innerHTML = html;
|
||||||
|
|
||||||
|
const selectors = [
|
||||||
|
'.quote-inline',
|
||||||
|
'.recipients-inline',
|
||||||
|
];
|
||||||
|
|
||||||
|
selectors.forEach(selector => {
|
||||||
|
const elem = node.querySelector(selector);
|
||||||
|
|
||||||
|
if (elem) {
|
||||||
|
elem.remove();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return node.innerHTML;
|
||||||
|
};
|
||||||
|
|
|
@ -821,12 +821,3 @@ a.status-card.compact:hover {
|
||||||
margin-top: 5px !important;
|
margin-top: 5px !important;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Fedibird quote post compatibility */
|
|
||||||
.status__content,
|
|
||||||
.quoted-status__content {
|
|
||||||
.quote-inline,
|
|
||||||
.recipients-inline {
|
|
||||||
display: none;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue