Chats: strip HTML when copying message text to clipboard
This commit is contained in:
parent
7722ce5e68
commit
40b8bab7ab
|
@ -16,6 +16,7 @@ import { MediaGallery } from 'soapbox/features/ui/util/async-components';
|
|||
import { useAppSelector, useAppDispatch, useOwnAccount } from 'soapbox/hooks';
|
||||
import { chatKeys, IChat, IChatMessage, useChatActions, useChatMessages } from 'soapbox/queries/chats';
|
||||
import { queryClient } from 'soapbox/queries/client';
|
||||
import { stripHTML } from 'soapbox/utils/html';
|
||||
import { onlyEmoji } from 'soapbox/utils/rich_content';
|
||||
|
||||
import ChatMessageListIntro from './chat-message-list-intro';
|
||||
|
@ -219,7 +220,8 @@ const ChatMessageList: React.FC<IChatMessageList> = ({ chat, autosize }) => {
|
|||
|
||||
const handleCopyText = (chatMessage: IChatMessage) => {
|
||||
if (navigator.clipboard) {
|
||||
navigator.clipboard.writeText(chatMessage.content);
|
||||
const text = stripHTML(chatMessage.content);
|
||||
navigator.clipboard.writeText(text);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -27,3 +27,11 @@ export const stripCompatibilityFeatures = (html: string): string => {
|
|||
|
||||
return node.innerHTML;
|
||||
};
|
||||
|
||||
/** Convert HTML to plaintext. */
|
||||
// https://stackoverflow.com/a/822486
|
||||
export const stripHTML = (html: string) => {
|
||||
const div = document.createElement('div');
|
||||
div.innerHTML = html;
|
||||
return div.textContent || div.innerText || '';
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue